Drag and Drop: dropping onto the app icon (Win)

Hi,

I can see on the wiki "Optimizing for Mac OS X" page[1] how to set a Mac application icon as a drop target for files; but I don't see corresponding instructions for Windows (or GTK), and for that matter the wx.App.MacOpenFile() method doesn't appear in the docs.

Is it possible to set a wxPython application icon, let's say frozen with py2exe, as a drop target for files in Windows explorer? And does it matter if the application is running or not? I was expecting that sys.argv might help if the application is not running (which seems not to be true), but wasn't sure where to look for drops on a running app.

Thanks much.

-M

[1] <http://wiki.wxpython.org/index.cgi/Optimizing_20for_20Mac_20OS_20X#head-5ce342e2a026b98d0e535d1d71403fdf3ea85b24>

Nicolas BRICHE wrote:

Marc Hedlund a écrit :

Hi,

I can see on the wiki "Optimizing for Mac OS X" page[1] how to set a Mac application icon as a drop target for files; but I don't see corresponding instructions for Windows (or GTK), and for that matter the wx.App.MacOpenFile() method doesn't appear in the docs.

Is it possible to set a wxPython application icon, let's say frozen with py2exe, as a drop target for files in Windows explorer? And does it matter if the application is running or not? I was expecting that sys.argv might help if the application is not running (which seems not to be true), but wasn't sure where to look for drops on a running app.

Thanks much.

-M

As far as I know, dropping a file on an icon is the same as running that app with the filename(s) as parameter.

This is correct. It is only the Mac that has special provisions for passing files dropped on the icon to an app that is already running. Windows and GTK just (re)launch the app with the file(s) on the command-line.

In other words, just code your app so that running

someapp.exe somefile1.ext [somefile2.ext]

does what you want the drag and drop to do. And yes, sys.argv is the way to go in that case.

Yes, it would matter if the app is running or not. Dropping a file on an icon usually launches another instance of that app. You will have to make your app aware of multiple instances of itself running (which is different from threading). On Windows, you'll have to create a temporary dir in %TEMP% for that and create status files or something, empty or not.

wxWidgets has the wx.SingleInstaceChecker class to help determine if there is another instance of the app already running, but it doesn't provide anything for passing the new files to the old app. Fortunately Python provides a several IPC mechanisms. It's probably overkill but I remember seeing an example of an app that did this by running an xmlrpc server in an alternate thread that the new instance could connect to and pass over the new files before it terminated itself.

···

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