Also, you can’t have more than one qt.QApplication(sys.argv) running at once.
In your second example, you are using pumpThread which works around defining the app in a bad way, but then you re-define it the way that doesn't make maya happy. Perhaps just comment out the app= line in the second example. They can all call pumpThread, since this is protected from starting more than once. On Tue, Jun 16, 2009 at 4:10 PM, John Creson <[email protected]> wrote: > I think this may be Python cleaning up :) > > Once your GUIs start getting more complex, you have to use the global > application > > instantiation and global windows variables. > > If you don't use both the global application instantiation and global > windows variables, > > then the resultant GUI will appear and disappear very quickly as Python > cleans up its > > local variables. > > > > import sys > > import PyQt4 as qt > > app=None > > win=None > def windo(): > > global app > global win > app = qt.QApplication(sys.argv) > win = qt.QLabel("Hello world!",None) > win.show() > > windo() > > > On Tue, Jun 16, 2009 at 3:52 PM, Pierre A <[email protected] > > wrote: > >> >> Hi, >> >> I'm experiencing a strange behavior with modal dialogs. >> Let's see the following code snippet: (Im in a method's class context) >> >> def launchDialog(self): >> diag = QtGui.QDialog(self) >> ret = diag.exec_() >> print ret >> >> I can see the dialog during a few miliseconds, then it disapears. The >> return value is always 0 >> >> Now, another piece of code: >> def launchDialog(self): >> self.diag = QtGui.QDialog(self) >> ret = self.diag.exec_() >> print ret >> >> I'm just adding the dialog as a member of the class. The dialog >> becomes modal, but exec_() returns immediately. >> >> I have the same problems with the convenience methods of >> QtGui.QMessageBox and QtGui.QInputDialog, they are closed immediately >> too... >> >> >> I'm in a particular state in maya. I have two different GUI launched. >> They both use pumpthread: >> ## LAUNCH APP >> window = None >> app = None >> def LaunchApp(): >> global app >> global window >> pt.initializePumpThread() >> app = QtGui.QApplication(sys.argv) >> window = MyWindowClass() >> window.show() >> >> If only one GUI is launched, diag.exec_() doesn't disappear. :'( But I >> really need to have multiple windows >> I'm stuck! I don't know how to solve this. Perhaps I could instanciate >> the QtApp in another module which would act as a singleton and share >> the QApplication with the different GUI? >> >> Thanks! >> >> Pierre >> >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/python_inside_maya -~----------~----~----~----~------~----~------~--~---
