1. Those parts aren't necessary. Only convenient if you want access to
the QApplication instance within your code, or you have multiple
scripts doing qt guis. Since maya's python interpreter is basically a
persistent single environment throughout the application, you are just
making sure to share a global reference to the qApp.

2. That is one way, which should work fine. Try first and ask for
forgiveness later :-)

You can also include
import sip
...
def getMayaWindow():
    ptr = mui.MQtUtil.mainWindow()
    return sip.wrapinstance(long(ptr), QObject)

myWindow = Window(getMayaWindow())

If you want your dialog to be parented to the maya window and pop up
centered and whatnot.



On Sep 8, 10:21 pm, oglop <[email protected]> wrote:
> hi all, i'm a new python user . i got confused by various tutorials on
> the internet, i'm using 2008 and 2011
> i've got 2 questions.
>
> 1. is this part necessary ?
>     global app
>     app=QtGui.qApp
>     app.connect(app, QtCore.SIGNAL("lastWindowClosed()"),
>                         app, QtCore.SLOT("quit()"))
>
> i deleted this part, my script still works . what does it do ? it
> looks fine both in 2008 and 2011. maya doesn't freeze.i'm under linux
>
> 2. is this the right way to make sure only one window exists ? i don't
> think so but i don't know what is the recommended way of doing it.
>
>     try:
>         myWindow.close()
>     except:
>         pass
>
> thanks !
>
> #!/usr/bin/env python2
> import os
> import maya.cmds as cmds
> import maya.OpenMayaUI as mui
> import maya.mel as mel
>
> from PyQt4 import QtGui, QtCore, uic
> from functools import partial
>
> #Get the absolute path to my ui file
> uiFile = os.path.join(cmds.internalVar(userAppDir=True),
> 'scripts','ui', 'myExample.ui')
> print 'Loading ui file:', os.path.normpath(uiFile)
>
> #Load the ui file, and create my class
> form_class, base_class = uic.loadUiType(uiFile)
>
> class Window(base_class, form_class):
>     # def __init__(self, parent=getMayaWindow()):
>     def __init__(self, parent=None):
>         '''A custom window with a demo set of ui widgets'''
>         #init our ui using the MayaWindow as parent
>         super(base_class, self).__init__(parent)
>         #uic adds a function to our class called setupUi, calling this
> creates all the widgets from the .ui file
>         self.setupUi(self)
>
> def main():
>     mayaVer = mel.eval("getApplicationVersionAsFloat()")
>
>     if mayaVer<2011:
>         import  pumpThread as pt
>         pt.initializePumpThread()
>
>     try:
>         myWindow.close()
>     except:
>         pass
>
>     global app
>     app=QtGui.qApp
>     app.connect(app, QtCore.SIGNAL("lastWindowClosed()"),
>                         app, QtCore.SLOT("quit()"))
>
>     global myWindow
>     myWindow = Window()
>     myWindow.show()

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to