[Pythonmac-SIG] py2app + pyqt: Differences between command-line and double-click

Berg, Stuart bergs at janelia.hhmi.org
Tue Aug 13 02:13:20 CEST 2013


Hi Ronald,

It took me a while to follow up on this thread I started a few months ago because I wanted to find a minimal test case that illustrates my problem.  Now I've got one.  Apparently the PyQt spashscreen doesn't behave correctly when I use the py2app "argv_emulation" option.  

To save you from digging through your email for the previous posts, I'll summarize my issue again:

- I use py2app to bundle my app, which is implemented with PyQt4 (qt-4.8.3, pyqt-4.9.5). 
- I want to show a QSplashScreen when my app starts up, and hide it when the main window is shown.
- When I double-click my app bundle:
 -- There is a brief delay
 -- The splash screen appears
 -- The main window does not appear.
 -- At this point, I can summon the main window into existence by using command-tab to switch away from the app and then back again.
- I get correct splash screen behavior if I launch the app from the command line via MyBundle.app/Contents/MacOS/myapp

I noticed that the odd behavior happens when I use the "argv_emulation" option.  Here's a minimal example that shows the incorrect behavior on my machine.  To see correct behavior, comment out the 'argv_emulation' option in setup.py.

If necessary, I can probably use a workaround to avoid argv_emulation, but if there is a quick fix for this, I'd love to know about it.

Thanks,
Stuart

# bash commands to run:
$ python setup.py py2app
$ open dist/splashtest.app # incorrect splash screen behavior
$ open dist/splashtest.app/Contents/MacOS/splashtest # Correct behavior

##############
### splashtest.py
import sys, time
from PyQt4.QtGui import QPixmap, QSplashScreen, QApplication, QMainWindow

app = QApplication([])

# Show a (blank) splash screen
splash = QSplashScreen( QPixmap(300, 200) )
splash.show()
app.processEvents()

time.sleep(1)

# Create & show the main window
window = QMainWindow()
window.show()
window.raise_()

# Close the splash screen
splash.finish(window)

sys.exit( app.exec_() )

##############
# setup.py
from setuptools import setup, find_packages
setup(
    app=['splashtest.py'],
    options={ 'py2app': { 'argv_emulation': True,
                          'includes':['PyQt4.QtCore','PyQt4.QtGui' ] } },
    setup_requires=['py2app']
)




More information about the Pythonmac-SIG mailing list