Hello,
I am refactoring my rigging API code, and I am trying to make my code a bit
more clean.
from PySide2 import QtWidgets, QtCore
from abc import ABCMeta, abstractmethod
class Widget():
__metaclass__ = ABCMeta
@abstractmethod
def __call__(self, **kwargs):
for key in kwargs:
if key == "t":
self.title()
if key == "n":
self.widgetName()
if key == "c":
self.color()
if key == "tt":
self.toolTip()
if key == "p":
self.parent()
def title(self):
print "this will give the widget a title"
def widgetName(self):
print "this will give the widget a name"
def color(self):
print "this will give the widget color"
def toolTip(self):
print "this will pop up a tooltip"
def parent(self):
print "this will give a parent to the widget"
class PushButton(Widget):
def __call__(self, **kwargs):
super(PushButton, self).__call__(**kwargs)
class ComboBox(Widget):
def __call__(self, **kwargs):
super(ComboBox, self).__call__(**kwargs)
# Run
pushBtn = PushButton()
pushBtn(t="push me", n="pushBtnA")
pushBtn(t="push me too", n="pushBtB", c=("rgb(100, 25, 75)"), p=None, tt="I
am here to help")
cmbBox = ComboBox()
cmbBox(n="comboBoxA")
Basically I have created an abstract class thas is inherited by diferent
type of widgets.What do you think about that design. I like the fact is
that in one line I can set an entire widget, and that it works with
multiple types of widgets.
But According to "clean code" by Robert C.Martin (uncle bob) I might be
breaking 2 rules here:
. the __call__ in the base class is too long and have multiple if
statements.
. methods should maximum 3 arguments, with that design I can add as many as
I want.
what do you think? Does this code make any sense?
Thanks,
R
--
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/e44bf7ee-783f-4080-bde6-3a286a1f65f5%40googlegroups.com.