Tk window fails to display when argv_emulation option is True

Issue #155 new
Christopher Wilson
created an issue

The default setup.py script generated by py2applet includes the following options by default:

OPTIONS = {'argv_emulation': True}

When argv_emulation is set to True, the Tk window in my app is not displayed until I click the app icon in the dock. After clicking the app icon, the Tk window is displayed correctly. Using command+tab to select app focus does not cause the Tk window to appear, and it doesn't appear to be hiding behind any other windows on my system.

However, if I change argv_emulation to False, the Tk window appears correctly.

Please see this screencast for a video of this behavior http://www.screencast.com/t/ja2AMP4oq

Is this expected behavior? Today is my first attempt at using py2app, so I may be missing something in the config.

I found this post by Kevin Walzer that tipped me off to fiddle with the argv_emulation option https://mail.python.org/pipermail/tkinter-discuss/2012-May/003162.html

Also, it appears that argv[1] is being set correctly when using the following command, whether or not argv_emulation is set to True or False...

open -a foo.app --args foo://www.example.com/test?var=val

However, if I launch foo.app from Firefox via the following bookmarklet, argv_emulation must be set to True for argv[1] to be set correctly.

javascript:location.href='foo://AddItem?kind=Bookmark&name='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(window.location);

Any idea why these two methods of launching foo.app are showing different behavior?

I'm using OS X 10.9.4, and I'm running python 3.4.1 (via pyenv). I'm using py2app 0.9 from pypi.

Comments (8)

  1. David Riggs

    Confirming this behavior on OS X 10.9.5, python.org Python 2.7.12, ActiveTCL 8.6.5, py2app 0.10.

    I've got a link to my Tkinter app in the dock, and with argv_emulation=True I can drag files of the associated type to the dock icon, and my app is launched with the file's path as sys.argv[1]... but I can't see my Tk GUI until I click some of its menu options.

    If I build with argv_emulation=False and do the same action, my app is launched and I can see its GUI... but there is no argv[1] for me to open.

  2. David Riggs

    I see the following source comment in py2app's argv_emulation.py:

    This is a workaround to convert scripts that expect filenames on the command-line to work in a GUI environment. GUI applications should not use this feature.

    So perhaps the "bug" is that we're not supposed to use it with a Tkinter application in the first place! The documentation for this option is very sparse, but my goal was to be able to interface more closely with the OS since Tkinter doesn't support drag-and-drop from the Mac Finder. Is there a more correct way to launch a py2app application with an associated file type? (I have already associated my custom file extension with in my Info.plist CFBundleDocumentTypes.)

  3. Ronald Oussoren repo owner

    Argv_emulation should not be used with GUI event loops, as those should already have support for opening files. Tkinter has such support as well, the source code of IDLE contains an example of that.

    I'm currently traveling and don't have a link to the relevant bit of IDLE or TK's documentation.

    Btw. The documention being sparse is an understatement, I inherited he project like this and haven't had time to write proper documentation yet.

    Ronald

  4. Log in to comment