[Pythonmac-SIG] py2app bug with argv_emulation=True

Michael O'Donnell micko at wagsoft.com
Sun Jun 3 13:03:00 CEST 2012


Dear Kevin,

  I don't know why, but your code works for me today,
even stripped of the time.sleep(). The initial openDoc
event is caught by doOpenFile.

I must have slipped up somewhere.

Note that the doOpenFile(sys.argv[1]) line was not
needed, because without argv_emulation, the clicked
file is NOT passed to my app in the arguments (which
was the starting point of this thread)

Thanks for your help, this was worrying me

Mick


On Sun, Jun 3, 2012 at 12:30 PM, Kevin Walzer <kw at codebykevin.com> wrote:

> On 6/2/12 9:24 PM, Michael O'Donnell wrote:
>
>> Kevin,
>>
>>   Seems we are not understanding each other. When a user
>> double clicks on a document associated to the app, the app
>> is launched. With argv emulation, I could read sys.argv to find
>> which document was clicked on.
>>
>> With openDocument events, the double clicking on a document
>> opens the application. The openDocument event is consumed
>> (but at this point, there is only dummy code for this). Then my
>> code is executed, overwriting the openDocument event handler.
>>
>> So, with this approach, there is no way to retrieve WHICH document
>> was clicked on to open the application.
>>
>> Mick
>>
>>
> Mick,
>
> (ccing back to the list as well)
>
> This brute-force method works for me--I double-click a "ctpx" file and the
> test app launches and then displays a messagebox with the name of the
> launched file:
>
> ----
> import sys
> import time
> from Tkinter import *
> import tkMessageBox
>
> def doOpenFile(*args):
>    for arg in args:
>        tkMessageBox._show(message=**str(arg), type="ok",
> icon=tkMessageBox.WARNING)
>
> tk = Tk()
> fr=Frame(tk, height=400, width=400, bg="red")
> fr.pack()
> time.sleep(2)
>
> tk.createcommand("::tk::mac::**OpenDocument", doOpenFile)
> for idx, value in enumerate(sys.argv):
>    print idx, value
> doOpenFile(sys.argv[1])
> tk.mainloop()
> ----
>
> I'm not sure if this works because you set argv_emulation in py2app's
> options, since I don't structure my apps this way, and obviously the hard
> command of "doOpenFile(sys.argv[1])" needs to be wrapped in some sort of
> try statement to guard against the app being launched without a file
> argument, but clearly what you want to do can be done. The opendoc event is
> still useful for dragging the file to the app icon in the Dock, regardless.
>
> --Kevin
>
> --
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20120603/f8f94c44/attachment.html>


More information about the Pythonmac-SIG mailing list