IDLE can be opened by double clicking on python files, the code I linked
to should be responsible for implementing this. Also, the argv_emulation
code uses the openDocument event to do its work (argv_emulation basicly
runs a Carbon event loop until it has received some openDocument events
or until a timeout occurs).

Also:

*smacks head*

Mick, I didn't realize that you were trying to have your app respond to a file being dropped on the app icon. Ronald is right, argv_emulation is not necessary for this.

If the code sample Ronald pointed to isn't quite clear, let me explain it a bit more:

Tk on the Mac supports all of the basic Apple events (app launch, file open, etc.) out of the box -- stub commands are included in the code that you can fill out to trigger an action in response to one of the supported events.

In the case of opening a file by dropping it on the app icon, or double-clicking it, the relevant Tk command is "tk::mac::OpenDocument" . When this command is defined in Tk, the code contained in the command will be executed when an "odoc" ("open document") event is received.

To access this functionality from Tkinter, you should use Tkinter's createcommand() function. The "createcommand" functionality allows a Python function/method to be mapped to a Tk command. Hence, in the IDLE example, you have:

root.createcommand("::tk::mac::OpenDocument", doOpenFile)

which maps the following code to the "tk::mac::OpenDocument" command:

   def doOpenFile(*args):
            for fn in args:
                 flist.open(fn)


Tk's support for this stuff on the Mac, out of the box, is actually quite rich, but it's been poorly documented until quite recently. I contributed documentation on all these commands to the Tk man pages:

http://www.tcl.tk/man/tcl8.6/TkCmd/tk_mac.htm

The commands are documented for Tk 8.6, but they are all present in the Cocoa-based version of Tk 8.5 from ActiveState as well, so you may find some useful things to look at here.

Hope this helps,
Kevin
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

Reply via email to