Drag and Drop file not working if launched from interactive console

Dropping of files into a wx.Frame is not working if I launch the module from the command line. However the same module works from Eclipse. I need help figuring out what I have missed. This is on Windows 7-64bit.
import sys

if not hasattr(sys, ‘frozen’):
import wxversion
wxversion.select(‘2.8’)
import wx

class TestWxDrop(wx.Frame):

def __init__(self, parent):
    wx.Frame.__init__(self, parent, title="Test file drop window", size=(400, 200))
    self.SetDropTarget(FileDrop(self))
    self.Show()

class FileDrop (wx.FileDropTarget):
def init(self, window):

    super(FileDrop, self).__init__()
    self.window = window

def OnDragOver(self, *args, **kwargs):
    #print "DragOver"
    return wx.FileDropTarget.OnDragOver(self, *args, **kwargs)

def OnDropFiles(self, x, y, filenames):
    print "You dropped a file! " + str(filenames)

if name == “main”:
app = wx.App()
window = TestWxDrop(None)
app.MainLoop()

When I launch from Eclipse files dragged over the window everything works as expected.

When launched from a console via “python testwxdrop.py” the cursor does not change when a file is dragged over the window and no OnDragOver events even fire.

Any ideas?

James Anderson wrote:

Dropping of files into a wx.Frame is not working if I launch the module
from the command line. However the same module works from Eclipse. I
need help figuring out what I have missed. This is on Windows 7-64bit.
/
/import sys

if not hasattr(sys, 'frozen'):
import wxversion
wxversion.select('2.8')
import wx

class TestWxDrop(wx.Frame):

def __init__(self, parent):
wx.Frame.__init__(self, parent, title="Test file drop window",
size=(400, 200))
self.SetDropTarget(FileDrop(self))
self.Show()

class FileDrop (wx.FileDropTarget):
def __init__(self, window):

super(FileDrop, self).__init__()
self.window = window

def OnDragOver(self, *args, **kwargs):
#print "DragOver"
return wx.FileDropTarget.OnDragOver(self, *args, **kwargs)

def OnDropFiles(self, x, y, filenames):
print "You dropped a file! " + str(filenames)

if __name__ == "__main__":
app = wx.App()
window = TestWxDrop(None)
app.MainLoop()

When I launch from Eclipse files dragged over the window everything
works as expected.

When launched from a console via "python testwxdrop.py" the cursor does
not change when a file is dragged over the window and no OnDragOver
events even fire.

Any ideas?

It really shouldn't make a difference how it is launched on Windows. All things being equal it should work or not work the same way in both environments. Are you sure that the same Python and wxPython that are being used in each case?

···

--
Robin Dunn
Software Craftsman

I added some print statements and the same versions are listed.

Wx version: [‘2.8-msw-unicode’]
Python version: 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]

James Anderson wrote:

I added some print statements and the same versions are listed.

Wx version: ['2.8-msw-unicode']
Python version: 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64
bit (AMD64)]

Your sample works fine for me when run from a command line, although I see from the above that you are using a 64-bit Python and I was using the 32-bit build, but I wouldn't think that would make a difference for DnD functionality.

···

--
Robin Dunn
Software Craftsman