[PySide] determine if pyside is run as standalone or inside of host app

Frank Rueter | OHUfx frank at ohufx.com
Sun Jul 13 15:19:53 CEST 2014


Hi,

I have a QWidget that uses
self.setWindowFlags(QtCore.Qt.Popup)

This causes the widget to not quit the QApplication when it closes even 
though it's the main widget.
I can put something like QtGui.QApplication.instance().quit() into the 
appropriate event to ensure the application closes properly, but most of 
the time this widget will be run from inside a host application, not as 
a standalone app, so closing the application instance would have fatal 
consequences for the user.

What would be the best way to determine whether the widget is run as a 
standalone, and I can quite the application safely, or if it's run from 
inside a host app?
In my current scenario I could check 
QtGui.QApplication.applicationFilePath() for the host applications that 
this is mostly going to be run from, but if somebody else imports my 
code into an app I didn't cater for, my QWidget will quit that when the 
widget closes, until I include the particular host in my code logic.

Here is a simple example that always manually quits the application 
(when I need ti be clever and not quit if it's run from inside a host):
http://pastebin.com/48y7nqc2

What's the best way to go about this?

Cheers,
frank




More information about the PySide mailing list