[wxPython-users] Accepting files for Drag and drop on OS-X

Kevin Ollivier kevino at theolliviers.com
Thu Mar 8 12:07:33 PST 2007


Hi Chris,

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

> 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

> 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 at noaa.gov
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users- 
> help at lists.wxwidgets.org
>





More information about the wxpython-users mailing list