wxPython - Drag & Drop problem

Gerson Kurz gerson.kurz at t-online.de
Sat Aug 9 01:55:15 EDT 2003


I want to have a window that can send and receive filenames per drag &
drop. The problem is: given code below I can 

- send files to Explorer
- get files from Explorer

but not copy files from e.g. one instance of the app to another
instance (or from one window of given class in a MDIFrame to another).
Here is the code, stripped down to the basics:

import wx

class MyFileDropTarget(wx.FileDropTarget):
    def __init__(self, parent):
        wx.FileDropTarget.__init__(self)
        self.parent = parent

    def OnDropFiles(self, x, y, files):
        for file in files:
            self.parent.c.InsertStringItem(0, file)

class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "test")
        size = self.GetClientSize()
        self.c = wx.ListCtrl(self, 1860,
            style=wx.LC_REPORT|wx.SUNKEN_BORDER,
            size=size, pos=(0,0))

        self.c.InsertColumn(0, "Filename",
            width = size[0])

        wx.EVT_MOTION(self.c, self.onStartDrag)
        self.SetDropTarget(MyFileDropTarget(self))

    def onStartDrag(self, evt):
        if evt.Dragging():
            data = wx.FileDataObject()
            data.AddFile("C:\\some.exe")
            dropSource = wx.DropSource(self)
            dropSource.SetData(data)
            dropSource.DoDragDrop(0)
        evt.Skip()

class TestApp(wx.App):
    def OnInit(self):
        frame = TestFrame()
        frame.Show(True)
        return True

if __name__ == '__main__':
    TestApp(0).MainLoop()

My Version is wxPython 2.4.1.2 + Python 2.3. Any help appreciated.





More information about the Python-list mailing list