[QUOTE=jjburton;17073]Thanks again for the help guys. I spent yesterday lookin at this again and not getting very far so I’m gonna let it stew in my brain a while and come back and look to implementing it later.
I did glean a lot from the resources and info you provided and as think I have better understanding of what is I’m lookin for which isn’t a singleton after all.
Regardless, I appreciate your time.
Cheers,
-Josh[/QUOTE]
This sounds a lot simpler than what I was thinking
Try something like wrapping the GUI itself in a class, and poke the active instance into a class field. Then you only need to check to see if that field is not null.
class UnitDialog( object ):
def __init__( self ):
self.Unit = None # instance variable goes here
def _create( self, window ):
self._Window = window # note that this is an instance variable too, you could get the window handle
# from the class instance if you wanted to, although that's unwise
# which is why it's a "polite private" name with an _
form = cmds.formLayout()
rbs = cmds.columnLayout() #@UndefinedVariable
cmds.formLayout( form, e=True, attachForm=( rbs, 'top', 10 ) ) #@UndefinedVariable
cmds.formLayout( form, e=True, attachForm=( rbs, 'left', 10 ) ) #@UndefinedVariable
cmds.formLayout( form, e=True, attachForm=( rbs, 'bottom', 10 ) ) #@UndefinedVariable
cmds.formLayout( form, e=True, attachForm=( rbs, 'right', 10 ) ) #@UndefinedVariable
cmds.formLayout( form, e=True, width=320 )
cmds.text( label="Set this file to:" )
cmds.text( " " )
cmds.rowColumnLayout( nc=2, cw=[( 1, 120 ), ( 2, 120 )], cal=[( 1, "both" ), ( 2, "both" ) ], cs=[( 1, 15 ), ( 2, 15 )] )
cmds.button( "meters", c=self._meters )
cmds.button( "centimeters", c=self._centimeters )
cmds.setParent( rbs )
cmds.text( " " )
cmds.text( "Scene data will be scaled to the same real-world size.", align="left", ww=True, width=320 )
def _meters( self, *args ):
cmds.currentUnit ( l="m" );
cmds.warning( "units set to meters" )
cmds.deleteUI( self._Window )
self.Unit = 'm'
def _centimeters( self, *args ):
cmds.currentUnit ( l="cm" );
cmds.warning( "units set to centimeters" )
cmds.deleteUI( self._Window )
self.Unit = 'cm'
def open( self ):
window = cmds.window( title="Fix unit settings", widthHeight=( 320, 144 ) )
self._create( window )
cmds.showWindow( window )
test_dlg = UnitDialog()
test_dlg.open()
# from other code you could check the instance variable. Not this example is not modal,
# so you might get None since the user has not yet made a choice.
# It's just the shortest bit of relevant code I had lying around.
if test_dlg.Unit == 'm': print 'unit is set to meters'
In this example, obviously, you could always check the instance variable from inside the class’s method by checking self.Unit – so the ‘create if needed’ idiom would be a method in the class like
def annoy_puppet(self, *args):
if not self.Puppet: # ie, it's None
self.Puppet = Puppet()
self.Puppet.State = "annoyed"
… and of course this also means all you can pass the class methods to button commands and bypass the global namespace and it’s annoyances.