wow, thanks everyone.  This is really helpful!

On Wed, Jun 10, 2009 at 8:52 PM, Chris G <[email protected]> wrote:

> That is the correct way to do it.  Maya is passing a positional argument to
> the callback, which is why you need a spot for it in the method def.
>
> -Chris
>
> On Wed, Jun 10, 2009 at 5:38 PM, Sylvain Berger 
> <[email protected]>wrote:
>
>> yeah I know, I would like to be able to do it without pymel if possible.
>> I want to keep my options open so that I don't always have to rely on a
>> 3rd party module to do things.
>>
>> I kinda found a stupid workaround...basically I need to add one dummy
>> argument to the function I call with partial... not elegent but it works
>>
>>
>> On Wed, Jun 10, 2009 at 5:23 PM, Ofer Koren <[email protected]> wrote:
>>
>>>
>>> pymel has Callback object class that works well for this purpose.
>>> It works like partial except that it'll ignore any incoming args/kwargs
>>> that
>>> are passed when the callback is invoked:
>>>
>>>
>>> cb = pm.Callback(myFunc, arg1=1)
>>> cb("args", dont='matter')
>>>
>>>
>>> import pymel as pm
>>> pm.button(l="Test button", c=pm.Callback(myFunc, 1, 2, arg1="a",
>>> arg2="b"))
>>>
>>>
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: [email protected]
>>> [mailto:[email protected]] On Behalf Of sberger
>>> Sent: Wednesday, June 10, 2009 1:25 PM
>>> To: python_inside_maya
>>> Subject: [Maya-Python] Re: using partial in window classes
>>>
>>>
>>> please note that the example I sent are reversed... the first one is
>>> the keywords example, and the second one the non keywords example
>>>
>>>
>>>
>>> On Jun 10, 4:10 pm, sberger <[email protected]> wrote:
>>> > 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
>>>
>>>
>>>
>>>
>>
>>
>> --
>> They say, "Evil prevails when good men fail to act." What they ought to
>> say is, "Evil prevails."
>> Nicolas Cage as Yuri Orlov in Lord of War.
>>
>>
>>
>
> >
>


-- 
They say, "Evil prevails when good men fail to act." What they ought to say
is, "Evil prevails."
Nicolas Cage as Yuri Orlov in Lord of War.

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to