I have a class(ButtonWin) for all my ui related code, then I have another class(CreateStuff) with the actual creation methods. CreateStuff is a subclass of ButtonWin. See the code below:
import maya.cmds as mc
class ButtonWin(object):
WINDOW_NAME = "MYCOOLBUTTONWIN"
def __init__(self):
self.deleteLayout()
self.win = mc.window(self.WINDOW_NAME, title='My Cool Button Window')
self.columnLayoutA = mc.columnLayout(parent=self.win)
#
self.buttonA = mc.button('BUTTON_A', label="Click Here", parent=self.columnLayoutA)
mc.showWindow()
def deleteLayout(self):
if mc.window(self.WINDOW_NAME, exists=True):
mc.deleteUI(self.WINDOW_NAME, window=True)
class CreateStuff(ButtonWin):
def __init__(self):
ButtonWin.__init__(self)
#>>> Add command to the buttonA <<<#
mc.button(self.buttonA, edit=True, command=self.doIt)
def doIt(self, *args):
mc.warning('Doing it!')
tmpInst = CreateStuff()
In order to run the doIt() method, I’m editing buttonA’s command in the init method of the subclass. I’m not sure that’s the most elegant way of doing this. Anybody have any thoughts on this type of issue?
I’ve seen some people doing something like this on buttonA’s creation:
self.buttonA = mc.button('BUTTON_A', label="Click Here", command='tmpInst.doIt()', parent=self.columnLayoutA)
It works too, but it doesn’t look really clean to me. :no:
Bonus question: My mel background made me write the deleteLayout() method to check if the window exists. Is there a more pythonic way? Or this is ok?
Thanks in advance! :D: