From: Bill B. <bil...@pe...> - 2006-02-18 18:41:45
|
[Alex modifying Bill's code] > Why not simply do this in the OnDropFiles() function, > i.e. > <code> > class FileDropTarget(wx.FileDropTarget): > def __init__(self, obj): > wx.FileDropTarget.__init__(self) > self.obj = obj > > def OnDropFiles(self, x, y, filenames): > [self.obj.Append(f) for f in filenames] > print "component", self.obj.name, "received files", filenames > --- THIS > </code> > [Bill] >> When I drop files on the List, I can't seem to get the DROP_FILES event >> to fire. IOW, my program never prints 'files have been dropped'. >> >> Does anyone know what I'm doing wrong? >> [Alex] > I don't. > However, I think the event mechanism for dropping is different from the > usual one. If you could simply bind to EVT_DROP_FILES, then I think > there'd be no need for the SetDropTarget complexity, would there? > > However, I do know for sure that the above change works and prints out > the name of the component on which they've been dropped, and (just the > new) file names on a drop event, so it can be used even if you have > multiple drop targets. Alex, Thank you for the reply!! I'm just a python hobbyist which means - I'm not that good, yet :-) I hadn't considered putting the 'print' statement in the OnDropFiles function. How simple! BTW - I really don't want to print the names of the files. I was only using that as an example. I actually want to check: 1). If they're the type of files I want to accept (PDF & Tiff). 2). If the files are Landscape or Portrait. So now (using your suggestion), I can simply do something like this: <code> def OnDropFiles(self, x, y, filenames): if checkTheseFiles(filenames): [self.obj.Append(f) for f in filenames] </code> Where 'checkTheseFiles' is another function to maybe check the type and orientation. Although, I could check the file extension easily enough right within 'OnDropFiles'. Thanks again for the help!! Bill |