Wont make a difference to your problem, but, you are using old-style
classes:
class UiSample() :
change to:
class UiSample( object ) :
Its a pet peeve =)
I also assume the loading of the window, whether it works or not,
inside the class you want to use for callback functions, during
initialization, to be a bad idea.
If you want to do that, you could make a classmethod and/or
staticmethod to call the window from the class:
def someclass(object):
@staticmethod
def makeWindow():
mainWindow = cmds.loadUI( uiFile=uiPath, verbose=True )
cmds.showWindow( mainWindow )
But I think some re-thinking the answer to the the five whys is in
order here.
It is obvious that the loadUI knows nothing about the class, so has no
frame of reference to handle anything for the instance i.e. self.*.
On Mar 16, 8:26 am, Narann <[email protected]> wrote:
> Hi all and thanks in advance! ;)
>
> I have a class:
>
> class UiSample() :
>
> def __init__( self ) :
>
> uiPath = "/rd/dfevrier/hg/code-snippets/qtDesignerUiSample/
> qtDesignerUiSample.ui"
>
> mainWindow = cmds.loadUI( uiFile=uiPath, verbose=True )
> cmds.showWindow( mainWindow )
>
> def dump( self, args ) :
> print "something"
>
> I have a simple .ui file with a button and a dynamic attribut on it:
>
> "+command" and a value: "self.dump".
>
> The prob is that when I load the ui I have this:
>
> # Executing: import maya.cmds as cmds;cmds.button('Form1|
> horizontalLayout|verticalLayout_2|
> dumpButton',e=True,command=self.dump) #
> # Error: name 'self' is not defined
> # Traceback (most recent call last):
> # File "<maya console>", line 1, in <module>
> # NameError: name 'self' is not defined #
>
> I suppose que class is not pass to the loadUI function during the
> creation and it is not able to get "self".
>
> Is there a way to handle loadUI in a OO method? Like PyQT or something
> like that.
>
> What is the good way to script UIs with maya's loadUI in Python?
>
> Thanks for help! :)
--
http://groups.google.com/group/python_inside_maya