Using OnDragOver in wxFileDropTarget

Hi all,

if I use OnDragOver in wxFileDropTarget, wether the method OnDropFiles nor OnDrop will be called, if I finally drop the files. Do I have to use the wxDropTarget and implement the OnDropFiles method myself?

Does anybody know the solution?

(sorry for the boring newbie questions ...)

Thorsten Henninger

Thorsten Henninger wrote:

Hi all,

if I use OnDragOver in wxFileDropTarget, wether the method OnDropFiles nor OnDrop will be called, if I finally drop the files. Do I have to use the wxDropTarget and implement the OnDropFiles method myself?

No, that shouldn't be necessary, the wxPython version of wxFileDropTarget is written to allow overriding all the virtuals.

Does anybody know the solution?

Please reduce it to a small sample app that we can look at.

···

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

Here is the sample Application.

init with FileDropTarget -> OnDropFiles works
init with FileDropTarget -> OnDropFiles does not work

Thorsten

from wxPython.wx import *

#File DragAndDrop with OnDragOver
class FileDropTargetPlus(wxFileDropTarget):
   def __init__(self):
      wxFileDropTarget.__init__(self)

   def OnDragOver(self, x, y, d):
      print "CAPTURED MOUSE (%d,%d)" % (x,y)
        def OnDropFiles(self, x, y, filenames):
      print "FILES DROPPED"
      for file in filenames:
         print file

#File DragAndDrop without OnDragOver
class FileDropTarget(wxFileDropTarget):
   def __init__(self):
      wxFileDropTarget.__init__(self)
        def OnDropFiles(self, x, y, filenames):
      print "FILES DROPPED"
      for file in filenames:
         print file

class MainWindow(wxFrame):
   def __init__(self,parent,id,title):
       wxFrame.__init__(self,parent,-1, title, size = (200,200))
       self.Show(true)
        # init with FileDropTarget -> OnDropFiles works
       #drop_target = FileDropTarget()

       # init with FileDropTarget -> OnDropFiles does not work
       drop_target = FileDropTargetPlus()
             self.SetDropTarget(drop_target)
      
class MyApp(wxApp):
   def OnInit(self):
      frame = MainWindow(None, -1, "Drag and Drop Example")
      self.SetTopWindow(frame)
      return true
       app = MyApp(0)
app.MainLoop()

Robin Dunn wrote:

···

Thorsten Henninger wrote:

Hi all,

if I use OnDragOver in wxFileDropTarget, wether the method OnDropFiles nor OnDrop will be called, if I finally drop the files. Do I have to use the wxDropTarget and implement the OnDropFiles method myself?

No, that shouldn't be necessary, the wxPython version of wxFileDropTarget is written to allow overriding all the virtuals.

Does anybody know the solution?

Please reduce it to a small sample app that we can look at.

Thorsten Henninger wrote:

Here is the sample Application.

init with FileDropTarget -> OnDropFiles works
init with FileDropTarget -> OnDropFiles does not work

You need to return a wxDragResult value from the OnDragOver. A default one is passed to you, so this will work:

     def OnDragOver(self, x, y, d):
         print "CAPTURED MOUSE (%d,%d)" % (x,y)
         return d

···

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