generic drop target possible ?
Karsten Hilbert <[email protected]>
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <[email protected]> |
Hello all,
I am hoping to write a "generic" drop target meaning that it
accepts drops of "anything" and decides what to do with it
based upon the type received. Is that possible with
wxPython4 ?
I am trying like this:
class cGenericDropTarget(wx.DropTarget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
data_object = wx.DataObjectComposite()
data_object.Add(wx.FileDataObject(), True)
data_object.Add(wx.TextDataObject())
# not accepted by Add():
#data_object.Add(wx.URLDataObject())
data_object.Add(wx.BitmapDataObject())
self.SetDataObject(data_object)
def OnDrop(self, x, y):
print('received a drop request at', x, y, 'accepting')
return True # receive any drop
def OnData(self, x, y, suggested_drag_result):
print('receiving dropped data at', x, y)
print('suggested drag result:', suggested_drag_result)
# copy data from drop source to our data object
copied = self.GetData()
print('copied data from source into our data object:', copied)
print('our composite object:', self.DataObject)
received_format = self.DataObject.GetReceivedFormat()
print('received format obj:', received_format)
format_int = received_format.GetType()
try:
format_str = received_format.Id
except Exception:
_log.exception('wx.DataFormat.Id not supported')
format_str = None
print('format as int:', format_int)
print('format as str:', format_str)
filled_in_data_object = self.DataObject.GetObject(received_format)
print('filled in object:', filled_in_data_object)
print('data size:', filled_in_data_object.GetDataSize())
if format_int == wx.DF_FILENAME:
print('files:', filled_in_data_object.Filenames)
elif format_int == wx.DF_UNICODETEXT:
print('text:', filled_in_data_object.Text)
else:
print('unknown type')
# this segfaults:
#data = filled_in_data_object.GetDataHere(format_int)
#print('data:', data)
return suggested_drag_result
This is, of course, not generic, but restricted to file
lists, text data, and bitmap data. At the very least I would
like to also accept URLs dragged in from a browser.
Should I add a wx.CustomDataObject() as sub object and that
will somehow magically receive any data not accepted by the
other data objects ?
Thanks,
Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/20200831100100.GA27637%40hermes.hilbert.loc.