David - thank you for the clarification. I think you're right, re-reading pumpThread I realized it's initializing QApplication in it. Your solution to call it before starting the instance should work.
Thank you very much :) best regard, Panupat C. On Wed, Jan 25, 2012 at 5:26 PM, David Moulder <da...@thirstydevil.co.uk>wrote: > I think you miss understood my reply. I'll try to clarify a little more. > > In your code example you did... > > app = QApplication.instance() > pumpThread.initializePumpThread() > app.setStyleSheet(setQtCSS()) > > *app* is in your *current *namespace. So if pumpThread hasn't been run > once *app *will be None (hence your error) > The pumpThread module may or may not be creating your main QApplication > (you'll have to check). I can't remember it off hand. But if it does, > then you need to initializePumpThread before you declare app. > > Like this... > > pumpThread.initializePumpThread() > *app *= QApplication.instance() # now app will not be None as pumpThread > will have started qApp > *app*.setStyleSheet(setQtCSS()) > > If pumpThread isn't making the qApp instance the code I linked to shows > how to do that. > > see... > app = None > > def get_app(): > global app > return app > > def set_app(i_app): > global app > testAppInstance = QtCore.QCoreApplication.instance() > if testAppInstance: > app = testAppInstance > else: > app = i_app > > set_app(QtGui.QApplication(sys.argv)) > > > > On Tue, Jan 24, 2012 at 9:14 PM, Judah Baron <judah.ba...@gmail.com>wrote: > >> Yeah, it looks like it's a timing thing. That block of code you have is a >> set of instructions that maya runs through pretty quickly, but you are >> getting into some quasi-asynchronous behavior with the atApp. Also, it's >> been a while since we have used pumpThread (we monitor QEvents instead >> because we weren't crazy about pumpThread - so yes, there is an >> alternative), but that line to initialize pumpThread - does it actually >> pump the thread at that point? Either way, I think you need a little time >> for the qtApp to start up. >> >> -Judah >> >> >> On Tue, Jan 24, 2012 at 8:49 AM, Panupat Chongstitwattana < >> panup...@gmail.com> wrote: >> >>> it's a pumpthread thing? Interesting . . . I suppose there's no real way >>> around it for 2010? >>> >>> About the database, I just ran into another issue. On Maya 2012, I can't >>> create QSqlDatabase object. I can import the module, get lists of drivers >>> and print it out. >>> >>> from PyQt4 import QtSql >>> >>> drivers = QtSql.QSqlDatabase.drivers() >>> >>> But as soon as I do this Maya immediately closes itself. >>> >>> myconnection = QtSql.QSqlDatabase() >>> >>> >>> >>> >>> On Tue, Jan 24, 2012 at 10:25 PM, David Moulder < >>> da...@thirstydevil.co.uk> wrote: >>> >>>> If your in 2010 then the qApp may not exist yet hence the NoneType >>>> Error. >>>> >>>> see >>>> http://www.mail-archive.com/python_inside_maya@googlegroups.com/msg01852.html >>>> >>>> >>>> Not used Qt's database drivers as we have our own dll that handles our >>>> server and file db connections. >>>> >>>> -Dave >>>> >>>> On Tue, Jan 24, 2012 at 11:09 AM, Panupat Chongstitwattana < >>>> panup...@gmail.com> wrote: >>>> >>>>> Hi everyone. I currently run into 2 problems when trying to start my >>>>> PyQt inside Maya 2010. >>>>> >>>>> 1. When I run the script, I sometimes get the error >>>>> >>>>> 'NoneType' object has no attribute 'setStyleSheet' >>>>> >>>>> When I re-run the same script again, the error goes away and the UI >>>>> shows up with the stylesheet applied . . .? >>>>> >>>>> app = QApplication.instance() >>>>> pumpThread.initializePumpThread() >>>>> app.setStyleSheet(setQtCSS()) >>>>> >>>>> >>>>> 2. I can't get QSql database connection to work. My script can connect >>>>> just fine when I run them alone outside Maya 2010. But whenever I try to >>>>> run it inside Maya, the lastError() always return me "Driver not loaded" >>>>> >>>>> >>>>> -- >>>>> view archives: http://groups.google.com/group/python_inside_maya >>>>> change your subscription settings: >>>>> http://groups.google.com/group/python_inside_maya/subscribe >>>>> >>>> >>>> >>>> >>>> -- >>>> David Moulder >>>> http://www.google.com/profiles/squish3d >>>> >>>> -- >>>> view archives: http://groups.google.com/group/python_inside_maya >>>> change your subscription settings: >>>> http://groups.google.com/group/python_inside_maya/subscribe >>>> >>> >>> -- >>> view archives: http://groups.google.com/group/python_inside_maya >>> change your subscription settings: >>> http://groups.google.com/group/python_inside_maya/subscribe >>> >> >> -- >> view archives: http://groups.google.com/group/python_inside_maya >> change your subscription settings: >> http://groups.google.com/group/python_inside_maya/subscribe >> > > > > -- > David Moulder > http://www.google.com/profiles/squish3d > > -- > view archives: http://groups.google.com/group/python_inside_maya > change your subscription settings: > http://groups.google.com/group/python_inside_maya/subscribe > -- view archives: http://groups.google.com/group/python_inside_maya change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe