Use a global wx.DataFormat

This commit is contained in:
Robin Dunn
2021-01-07 14:52:34 -08:00
parent 224630cf64
commit 4ab028d7c3
2 changed files with 9 additions and 6 deletions

View File

@@ -3,6 +3,8 @@
import pickle
import wx
CUSTOM_DATA_FORMAT = wx.DataFormat('org.wxpython.DoodleLines')
#----------------------------------------------------------------------
dragResultNames = {
@@ -84,7 +86,7 @@ class DoodlePad(wx.Window):
# create our own data format and use it in a
# custom data object
ldata = wx.CustomDataObject("application.DoodleLines")
ldata = wx.CustomDataObject(CUSTOM_DATA_FORMAT)
ldata.SetData(linesdata)
# Also create a Bitmap version of the drawing
@@ -127,7 +129,7 @@ class DoodleDropTarget(wx.DropTarget):
self.dv = window
# specify the type of data we will accept
self.data = wx.CustomDataObject("application.DoodleLines")
self.data = wx.CustomDataObject(CUSTOM_DATA_FORMAT)
self.SetDataObject(self.data)
self.SetDefaultAction(wx.DragMove)
@@ -336,8 +338,8 @@ if __name__ == '__main__':
overview = """<html><body>
This demo shows Drag and Drop using a custom data type and a custom
data object. A type called "DoodleLines" is created and a Python
Pickle of a list is actually transferred in the drag and drop
data object. A type called "org.wxpython.DoodleLines" is created and
a Python Pickle of a list is actually transferred in the drag and drop
operation.
A second data object is also created containing a bitmap of the image

View File

@@ -1056,6 +1056,7 @@ class FNBDragInfo(object):
# Simply Used To Handle The OnDrop() Method When Dragging And Dropping Between
# Different FlatNotebooks.
# ---------------------------------------------------------------------------- #
FNB_DataFormat = wx.DataFormat('FlatNotebook')
class FNBDropTarget(wx.DropTarget):
"""
@@ -1074,7 +1075,7 @@ class FNBDropTarget(wx.DropTarget):
wx.DropTarget.__init__(self)
self._parent = parent
self._dataobject = wx.CustomDataObject(wx.DataFormat(six.u('FlatNotebook')))
self._dataobject = wx.CustomDataObject(FNB_DataFormat)
self.SetDataObject(self._dataobject)
@@ -5836,7 +5837,7 @@ class PageContainer(wx.Panel):
self._isdragging = True
draginfo = FNBDragInfo(self, tabIdx)
drginfo = pickle.dumps(draginfo)
dataobject = wx.CustomDataObject(wx.DataFormat(six.u('FlatNotebook')))
dataobject = wx.CustomDataObject(FNB_DataFormat)
dataobject.SetData(drginfo)
dragSource = FNBDropSource(self)
dragSource.SetData(dataobject)