To retrieve the object, perform the same basic steps. For a clipboard retrieve, create a custom data object with the same format, then get the data and unpickle it.
data_object = wx.CustomDataObject("MyNiftyFormat") if wx.TheClipboard.Open():
success = wx.TheClipboard.GetData(data_object) wx.TheClipboard.Close() if success:
pickled_data = data_object.GetData() object = cPickle.loads(pickled_data)
A drag and drop works similarly. Set the data object of the drop source to your custom data object with the pickled data, and the data target unpickles the data in its OnData() method and puts the data someplace useful.
Another way to create custom data objects is to build your own subclass of wx.DataObject. If you choose to go that route, you'll want to make your class a subclass of either wx.PyDataObjectSimple (for the generic object), or wx.PyText-DataObject, wx.PyBitmapDataObject, or wx.PyFileDataObject. That will enable you to override all the necessary methods.
Was this article helpful?