Log the wx.DragResult names rather than just the integer value

This commit is contained in:
Robin Dunn
2020-05-14 16:27:55 -07:00
parent 2d241d0fb7
commit 9d3d2d3f43

View File

@@ -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):