From 9d3d2d3f430554483fdf86b205032203355d3db1 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 14 May 2020 16:27:55 -0700 Subject: [PATCH] Log the wx.DragResult names rather than just the integer value --- demo/CustomDragAndDrop.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/demo/CustomDragAndDrop.py b/demo/CustomDragAndDrop.py index 0722025f..74324a5f 100644 --- a/demo/CustomDragAndDrop.py +++ b/demo/CustomDragAndDrop.py @@ -5,6 +5,14 @@ import wx #---------------------------------------------------------------------- +dragResultNames = { + wx.DragError : 'DragError', + wx.DragNone : 'DragNone', + wx.DragCopy : 'DragCopy', + wx.DragMove : 'DragMove', + wx.DragLink : 'DragLink', + wx.DragCancel : 'DragCancel', +} class DoodlePad(wx.Window): def __init__(self, parent, log): @@ -102,7 +110,7 @@ class DoodlePad(wx.Window): dropSource.SetData(data) self.log.WriteText("Beginning DragDrop\n") result = dropSource.DoDragDrop(wx.Drag_AllowMove) - self.log.WriteText("DragDrop completed: %d\n" % result) + self.log.WriteText("DragDrop completed: %s\n" % dragResultNames[result]) if result == wx.DragMove: self.lines = [] @@ -122,10 +130,11 @@ class DoodleDropTarget(wx.DropTarget): self.data = wx.CustomDataObject("application.DoodleLines") self.SetDataObject(self.data) + self.SetDefaultAction(wx.DragMove) # some virtual methods that track the progress of the drag def OnEnter(self, x, y, d): - self.log.WriteText("OnEnter: %d, %d, %d\n" % (x, y, d)) + self.log.WriteText("OnEnter: %d, %d, %s\n" % (x, y, dragResultNames[d])) return d def OnLeave(self): @@ -136,7 +145,7 @@ class DoodleDropTarget(wx.DropTarget): return True def OnDragOver(self, x, y, d): - #self.log.WriteText("OnDragOver: %d, %d, %d\n" % (x, y, d)) + self.log.WriteText("OnDragOver: %d, %d, %s\n" % (x, y, dragResultNames[d])) # The value returned here tells the source what kind of visual # feedback to give. For example, if wxDragCopy is returned then @@ -150,7 +159,7 @@ class DoodleDropTarget(wx.DropTarget): # Called when OnDrop returns True. We need to get the data and # do something with it. def OnData(self, x, y, d): - self.log.WriteText("OnData: %d, %d, %d\n" % (x, y, d)) + self.log.WriteText("OnData: %d, %d, %s\n" % (x, y, dragResultNames[d])) # copy the data from the drag source to our data object if self.GetData(): @@ -160,11 +169,16 @@ class DoodleDropTarget(wx.DropTarget): lines = pickle.loads(linesdata.tobytes()) self.dv.SetLines(lines) - # what is returned signals the source what to do - # with the original data (move, copy, etc.) In this - # case we again just return the suggested value given - # to us. - return d + # what is returned signals the source what to do + # with the original data (move, copy, etc.) In this + # case we again just return the suggested value given + # to us. + retval = d + else: + retval = wx.DragNone + + self.log.WriteText('OnData returning: %s\n' % (dragResultNames[retval],)) + return retval class DoodleViewer(wx.Window):