Okey, so this is another design that I am testing. This time I took a
functor aproach (or at least that is what I think I did).
So I came up with this. What do you think, am I overthinking it?
Cheers,
R
from PySide2 import QtWidgets, QtCore
class WidgetFunctor(object):
def __call__(self, widget, **kwargs):
self.widget = widget
for key in kwargs:
self.setTitle(kwargs[key]) if key == "title" else None
self.setObjectName(kwargs[key]) if key == "objectName" else None
self.setSize(kwargs[key][0], kwargs[key][1]) if key == "size"
else None
return self.widget
def setTitle(self, title):
self.widget.setText(title)
print "setting widget title success!"
def setObjectName(self, objectName):
self.widget.setObjectName(objectName)
print "setting objectName success!"
def setSize(self, width, height):
self.widget.resize(width, height)
print "setting parent success!"
# And so on with more methods...
# Using the functor
widgetFunctor = WidgetFunctor()
buttonA = widgetFunctor(QtWidgets.QPushButton(), title="foo", objectName=
"buttonA_btn", size=(60, 20))
buttonB = widgetFunctor(QtWidgets.QPushButton(), title="luu", objectName=
"buttonB_btn"))
comboBoxA = widgetFunctor(QtWidgets.QComboBox(), objectName="comboA_btn",
size=(40, 50))
# Equivalent without functor (this is what I want to avoid)
buttonA = QtWidgets.QPushButton()
buttonA.setText("foo")
buttonA.setObjectName("buttonA_btn")
buttonA.resize(60, 20)
buttonB = QtWidgets.QPushButton()
buttonB.setText("luu")
buttonB.setObjectName("buttonB_btn")
comboBoxA = QtWidgets.QComboBox()
comboBoxA.setObjectName("comboA_btn")
comboBoxA.resize(40, 50)
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/898d0237-0aed-4d2c-adcf-c4783ac5fe24%40googlegroups.com.