PDA

View Full Version : what am I doing wrong while creating a window


DEVILSAN
10-30-2012, 08:01 AM
filename is mywindow.py

class GUI(object):
def __init__(self):

self.widgets={}
self.winName="mywindow"
self.dock=""

self.v=mel.eval('getApplicationVersionAsFloat')
if self.v>= 2011: self.dock=True
else: self.dock=False

self.createUI(self.winName,self.dock)

def createUI(self,winName,dock):
"""
Creates dockable GUI if maya version above 2011
else creates flying window
"""
if self.dock:
if cmds.dockControl(self.winName,exists=True):
cmds.deleteUI(self.winName)
else:
if cmds.window(self.winName, exists=True):
cmds.deleteUI(self.winName)
print "WindowName: ", self.winName
print "state of dock: ", dock
# then I add some controls here
#Show the window
if self.dock:
cmds.dockControl(self.winName, area="left",allowedArea="left", content=self.widgets["window"])
else:
cmds.showWindow(self.widgets["window"])

I launch the above window using
import mywindow
reload( mywindow)
obj=mywindow.GUI()




this works fine on first run, but if i close it and try to reopen it i get error saying "mywindow is not unique"...

i guess i am doing something wrong while showing the window

Pascaru
11-02-2012, 05:02 PM
Before you launch it, you need to check if the window "self.winName" exists, if it does, delete it. Then execute the code to launch it.

DEVILSAN
11-02-2012, 05:25 PM
well I already had it fixed, figured out the reason why but not what you mentioned , while showing I had to show either for dock or non-docked window but the non-docked window was getting created explicitly as second docked window ...its fixed now and I have saved a working code as template rather then writing agian...

djx
11-03-2012, 04:35 AM
well I already had it fixed, figured out the reason why
I notice this, or something similar, is often your response after people already spent some time trying to help you.

I think it would be great, and helpful for others, if you actually posted your solutions when you discover them. Maybe you can post the corrected code here as an example for others to learn from.

David

DEVILSAN
11-03-2012, 07:21 AM
This is the skeleton code to begin with for making User Interface, I usually declare 3 classes one contains the code that needs to executes at initial(I call it BaseInitializer) just like __init__ has some variables declared to the same class method, but I can use this class to be inherited by the other two classes to use common attributes etc, the second class that contains the GUI, of which you see the code below, and the third is Actions class that contains the all the methods of logical operations... action also inherits the first class BaseInitializer .
class GUI(BaseInitializer):
def __init__(self):
BaseInitializer.__init__(self)
self.widgets={}
self.winName="minime"
self.dock=""

self.v=mel.eval('getApplicationVersionAsFloat')
if self.v>= 2011: self.dock=True
else: self.dock=False

self.createUI(self.winName,self.dock)

def createUI(self,winName,dock):
"""
Creates dockable GUI if maya version above 2011
else creates flying window
"""
if dock:
if cmds.dockControl(self.winName+"_dock",exists=True):
cmds.deleteUI(winName+"_dock")
else:
if cmds.window(self.winName, exists=True):
cmds.deleteUI(self.winName)
newObj=Actions()

self.widgets["window"] = cmds.window(self.winName, title = "replace this with your app name",
width = 300, height = 350)

#######################################################
All controls go here
#######################################################
#Show the window
if self.dock:
cmds.dockControl(self.winName+"_dock", l="replace this with your app name", area="left",
allowedArea="left",content=self.widgets["window"])
else:
cmds.showWindow(self.widgets["window"])

CGTalk Moderation
11-03-2012, 07:21 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.