From ed650677e1e7fb9aa2ee4877bf1e5707f5d608c9 Mon Sep 17 00:00:00 2001 From: Roman Rolinsky Date: Mon, 30 Apr 2007 15:48:42 +0000 Subject: [PATCH] drag-and-drop with left button git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45719 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/wx/tools/XRCed/panel.py | 1 + wxPython/wx/tools/XRCed/params.py | 2 ++ wxPython/wx/tools/XRCed/tools.py | 34 ++++++++++++++++++++++++++----- wxPython/wx/tools/XRCed/tree.py | 2 +- wxPython/wx/tools/XRCed/undo.py | 3 ++- wxPython/wx/tools/XRCed/xrced.py | 4 ++++ 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/wxPython/wx/tools/XRCed/panel.py b/wxPython/wx/tools/XRCed/panel.py index 1bb555d530..361ab59b66 100644 --- a/wxPython/wx/tools/XRCed/panel.py +++ b/wxPython/wx/tools/XRCed/panel.py @@ -348,6 +348,7 @@ class PropPage(ParamPage): self.origChecks.append((param, True)) self.origControls.append((param, value, True)) except KeyError: + # Optional param not present in xxx - set empty value self.checks[param].SetValue(False) w.SetValue('') w.Enable(False) diff --git a/wxPython/wx/tools/XRCed/params.py b/wxPython/wx/tools/XRCed/params.py index 769f6d8f48..c62d3e1f49 100644 --- a/wxPython/wx/tools/XRCed/params.py +++ b/wxPython/wx/tools/XRCed/params.py @@ -397,9 +397,11 @@ class ParamUnit(PPanel): def GetValue(self): return self.text.GetValue() def SetValue(self, value): + self.freeze = True if not value: value = '0' self.text.SetValue(value) self.Change(0) + self.freeze = False def Change(self, x): self.freeze = True # Check if we are working with dialog units diff --git a/wxPython/wx/tools/XRCed/tools.py b/wxPython/wx/tools/XRCed/tools.py index 3471d256bb..6fda618cfc 100644 --- a/wxPython/wx/tools/XRCed/tools.py +++ b/wxPython/wx/tools/XRCed/tools.py @@ -100,6 +100,8 @@ class Tools(wx.Panel): wx.EVT_KEY_DOWN(self, self.OnKeyDown) wx.EVT_KEY_UP(self, self.OnKeyUp) + self.drag = None + def AddButton(self, id, image, text): from wx.lib import buttons button = buttons.GenBitmapButton(self, id, image, size=self.TOOL_SIZE, @@ -107,7 +109,8 @@ class Tools(wx.Panel): button.SetBezelWidth(0) wx.EVT_KEY_DOWN(button, self.OnKeyDown) wx.EVT_KEY_UP(button, self.OnKeyUp) - wx.EVT_RIGHT_DOWN(button, self.OnRightClick) + wx.EVT_LEFT_DOWN(button, self.OnLeftDownOnButton) + wx.EVT_MOTION(button, self.OnMotionOnButton) button.SetToolTipString(text) self.curSizer.Add(button) self.groups[-1][1][id] = button @@ -160,11 +163,32 @@ class Tools(wx.Panel): else: box.SetLabel('[-] ' + box.name) self.Layout() - # Drag - def OnRightClick(self, evt): + # DaD + def OnLeftDownOnButton(self, evt): + self.posDown = evt.GetPosition() + self.idDown = evt.GetId() + self.btnDown = evt.GetEventObject() + evt.Skip() + + def OnMotionOnButton(self, evt): + # Detect dragging + if evt.Dragging() and evt.LeftIsDown(): + d = evt.GetPosition() - self.posDown + if max(abs(d[0]), abs(d[1])) >= 5: + if self.btnDown.HasCapture(): + # Generate up event to release mouse + evt = wx.MouseEvent(wx.EVT_LEFT_UP.typeId) + evt.SetId(self.idDown) + # Set flag to prevent normal button operation this time + self.drag = True + self.btnDown.ProcessEvent(evt) + self.StartDrag() + evt.Skip() + + def StartDrag(self): do = MyDataObject() - do.SetData(str(evt.GetId())) - bm = evt.GetEventObject().GetBitmapLabel() + do.SetData(str(self.idDown)) + bm = self.btnDown.GetBitmapLabel() # wxGTK requires wxIcon cursor, wxWIN and wxMAC require wxCursor if wx.Platform == '__WXGTK__': icon = wx.EmptyIcon() diff --git a/wxPython/wx/tools/XRCed/tree.py b/wxPython/wx/tools/XRCed/tree.py index 8ed352c8b0..e2ab28a403 100644 --- a/wxPython/wx/tools/XRCed/tree.py +++ b/wxPython/wx/tools/XRCed/tree.py @@ -501,7 +501,7 @@ class XML_Tree(wx.TreeCtrl): # Register events wx.EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged) # One works on Linux, another on Windows - if wx.Platform == '__WXGTK__': + if wx.Platform == '__WXGTK__': # !!! MAC too? wx.EVT_TREE_ITEM_ACTIVATED(self, self.GetId(), self.OnItemActivated) else: wx.EVT_LEFT_DCLICK(self, self.OnDClick) diff --git a/wxPython/wx/tools/XRCed/undo.py b/wxPython/wx/tools/XRCed/undo.py index 4b28a76c38..f883f88e93 100644 --- a/wxPython/wx/tools/XRCed/undo.py +++ b/wxPython/wx/tools/XRCed/undo.py @@ -274,7 +274,8 @@ class UndoEdit: # Save current state for redo map(ParamPage.SaveState, g.panel.pages) pages = map(ParamPage.GetState, g.panel.pages) - map(ParamPage.SetState, g.panel.pages, self.pages) + if self.pages: + map(ParamPage.SetState, g.panel.pages, self.pages) self.pages = pages self.update(selected) def redo(self): diff --git a/wxPython/wx/tools/XRCed/xrced.py b/wxPython/wx/tools/XRCed/xrced.py index 67966b9c28..26d6bc6f30 100644 --- a/wxPython/wx/tools/XRCed/xrced.py +++ b/wxPython/wx/tools/XRCed/xrced.py @@ -1101,6 +1101,10 @@ Homepage: http://xrced.sourceforge.net\ print msg def OnCreate(self, evt): + # Ignore fake events generated while dragging + if g.tools.drag: + g.tools.drag = False + return selected = tree.selection if tree.ctrl: appendChild = False else: appendChild = not tree.NeedInsert(selected) -- 2.45.2