Accepting files for Drag and drop on OS-X

HI all,

I'm working on making an app accept files for drag and drop on OS-X. I've started with what's on this page:

http://wiki.wxpython.org/index.cgi/Optimizing_for_Mac_OS_X

Which got me most of the way there. However, while I can now drag a file onto the icon in the doc when the app is running, and have it call MacOpenFile(), if I start the app by dropping a file on it, it doesn't seem to register it at all, it just starts without ever calling MacOpenFile().

How can I get it to start up with the file dropped on it?

Enclosed is a small sample, that should accept all files for dropping, once it's been bundled with py2app.

Tested with:
Python2.5
wxPython 2.8.1
py2app from SVN

I'll try to update the wiki some once I've got this all working.

-Chris

ConverterIcon.icns (21.4 KB)

setup.py (1.28 KB)

MacApp.py (3.25 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Hi Chris,

Hi Kevin,

I'm surprised there isn't any info about this on the wiki page.

I'll try to add it today.

Thanks!

Basically, your app won't start receiving AppleEvents until it's fully started, so you won't get a MacOpenFile notification. However, if you drag a file onto an app to start it, you will receive the filename of the dragged file in the app's command line arguments, so you need to parse sys.argv, pull out the filename, and load it that way.

I just figured that out myself, when I noticed that I had argv emulation turned on.

However, it would be nice have one point of entry, so I tried turning argv emulation off, and then did get a MacOpenFile event, but with:

"-psn_0_66322433"

instead of a file name. Curious.

The file name should still be there, it's just that it's 1-2 arguments down the line. The argument you're seeing is the app's process serial number (IIRC), which Apple passes in to the Mac application by default. Since most Python apps don't expect arguments like this, the argv emulation mode filters them out so you'd get what you would typically get if you ran the app straight from the command line instead of within an app bundle.

Regards,

Kevin

···

On Mar 8, 2007, at 11:51 AM, Christopher Barker wrote:

So I guess parsing sys.argv is the way to go. I suppose that's fine, as it will work for command line usage as well.

The next step is to figure out how to catch it when a file is dropped in the app Frame, in addition to dropping on the icon in the Finder or Doc.

Thanks,
-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Christopher Barker wrote:

I'm surprised there isn't any info about this on the wiki page.

I'll try to add it today.

Done -- and I've cleaned it up a bit, and added a sample app that does "all the right things"

The only thing I didn't add is an icon bundle, as I couldn't figure out how to enclose a file with a Wiki page -- can that be done?

Yes, you can attach files to a page. Click on "Attachements" at the bottom to upload them, or remove old files, etc. You can refer to an attachment within the text using "attachement:filename"

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!