Hi guys, I found this trick for Maya. When you create a window class,
I can use the partial function to build my commands sent to my
buttons.
The problem is I can only manage to make this work with one arguments,
when I send 2 or more arguments i get errors.
Here is the code:
from functools import partial
import maya.cmds as cmds
class ButtonWin(object):
def __init__(self):
window='testWin'
if (cmds.window(window, exists=True)):
cmds.deleteUI(window, window=True)
self.win = cmds.window(window)
self.layout = cmds.columnLayout(parent=self.win)
for x in range(10):
partialFunc =
partial(self.report,buttonIndex=x,value=x*2)
print 'function:', partialFunc.func
print 'args:', partialFunc.args
print 'keywords:', partialFunc.keywords
cmds.button(label="Click Here %d"%x, parent=self.layout,
command=partialFunc)
cmds.showWindow()
def report(self,buttonIndex=0,value=0):
print "button %d got %s"%(buttonIndex,value)
f = ButtonWin()
I have tried using keywords arguments but I still get an error:
from functools import partial
import maya.cmds as cmds
class ButtonWin(object):
def __init__(self):
window='testWin'
if (cmds.window(window, exists=True)):
cmds.deleteUI(window, window=True)
self.win = cmds.window(window)
self.layout = cmds.columnLayout(parent=self.win)
for x in range(10):
partialFunc = partial(self.report,x,x*2)
print 'function:', partialFunc.func
print 'args:', partialFunc.args
print 'keywords:', partialFunc.keywords
cmds.button(label="Click Here %d"%x, parent=self.layout,
command=partialFunc)
cmds.showWindow()
def report(self,buttonIndex,value):
print "button %d got %s"%(buttonIndex,value)
f = ButtonWin()
Anyone have experience using this partial function?
Thanks
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---