win_name = "Import chan"
...
...
class CustomNodeTranslator(OpenMayaMPx.MPxFileTranslator):
def reader(self, fileObject, optionString, accessMode):
if cmds.window(win_name, exists = True):
cmds.deleteUI(win_name)
print "The application is already opened!"
else:
print "no existence window"
self.initialWindow()
...
...
def initialWindow(self, *args):
self.window = cmds.window(title="Import chan", menuBar=True, iconName='.chanFileImport', widthHeight=(335, 221), sizeable=False)
...
...
This code example looks like if the window exists, you delete it and then don't initialize a new one.
Also I would recommend not using a constant for the window name, and instead saving the last window name returned from cmds.window as an instance attribute. That way you can always be sure you are deleting the last window you actually created, even if there was a name clash producing a different name, or Maya decided to rename it. I haven't tested your code, but are you sure Maya isnt replacing that illegal space character in the window name? This would be an ideal reason to save the returned window name, and reuse that on subsequent calls
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8274b1fe-3962-496e-ad9f-33548d835861%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def initialWindow(self, *args):
self.window = cmds.window(win_name, menuBar=True, iconName='.chanFileImport', widthHeight=(335, 221), sizeable=False)
On 17/09/2014 10:44 PM, "likage" <dissid...@gmail.com> wrote:
>
> Do you mean to say, I should wrote it like this perhaps:
>
> def initialWindow(self, *args):
> self.window = cmds.window(win_name, menuBar=True, iconName='.chanFileImport', widthHeight=(335, 221), sizeable=False)
>
Well you would have an initial self.window set in you constructor and always use that as the argument to cmds.window. Then it will give you back the name it actually used. But I am guessing the real problem was the space in the original name and then it giving you back a modified name. So you would never be able to delete it again since you lost the name.
> And how do I initialize a new one? Cause in my case, the UI will only be prompted if something is imported in followed by the ui prompt
>
Not sure what this means. All I know is that your small snippet suggested you only create a window if it didn't already exist. And you don't create a window if it did and you had to delete it.
> --
> You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7497217a-956c-463e-836b-d5a0167a792a%40googlegroups.com.
import maya.cmds as cmds
win_name = "TEST"
win = cmds.window(win_name, title = "CHAN Importer", menuBar=True, iconName='.chanFileImport', widthHeight=(335, 221), sizeable=False)
cmds.showWindow(win)
if cmds.window( win_name, exists = True):
cmds.deleteUI(win_name)
print "The application is already opened!"
else:
cmds.window(win_name)
cmds.showWindow(win_name)
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0a7d7056-f4e0-489b-8f77-1524461fbd09%40googlegroups.com.