X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/552240ce1743c5370d392f0726500875fc1da7a4..621b83d9b34572321873cf3d54920a7749b2f53c:/wxPython/wx/tools/XRCed/tools.py diff --git a/wxPython/wx/tools/XRCed/tools.py b/wxPython/wx/tools/XRCed/tools.py index 45687f850a..6fda618cfc 100644 --- a/wxPython/wx/tools/XRCed/tools.py +++ b/wxPython/wx/tools/XRCed/tools.py @@ -16,7 +16,6 @@ GROUP_WINDOWS, GROUP_MENUS, GROUP_SIZERS, GROUP_CONTROLS = range(GROUPNUM) # States depending on current selection and Control/Shift keys STATE_ROOT, STATE_MENUBAR, STATE_TOOLBAR, STATE_MENU, STATE_STDDLGBTN, STATE_ELSE = range(6) - # Left toolbar for GUI elements class Tools(wx.Panel): TOOL_SIZE = (30, 30) @@ -97,17 +96,21 @@ class Tools(wx.Panel): self.SetSizeHints(self.GetSize()[0], -1) # Events wx.EVT_COMMAND_RANGE(self, ID_NEW.PANEL, ID_NEW.LAST, - wx.wxEVT_COMMAND_BUTTON_CLICKED, g.frame.OnCreate) + wx.wxEVT_COMMAND_BUTTON_CLICKED, g.frame.OnCreate) 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, - style=wx.NO_BORDER|wx.WANTS_CHARS) + style=wx.NO_BORDER|wx.WANTS_CHARS) button.SetBezelWidth(0) wx.EVT_KEY_DOWN(button, self.OnKeyDown) wx.EVT_KEY_UP(button, self.OnKeyUp) + 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,6 +163,44 @@ class Tools(wx.Panel): else: box.SetLabel('[-] ' + box.name) self.Layout() + # 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(self.idDown)) + bm = self.btnDown.GetBitmapLabel() + # wxGTK requires wxIcon cursor, wxWIN and wxMAC require wxCursor + if wx.Platform == '__WXGTK__': + icon = wx.EmptyIcon() + icon.CopyFromBitmap(bm) + dragSource = wx.DropSource(self, icon) + else: + curs = wx.CursorFromImage(wx.ImageFromBitmap(bm)) + dragSource = wx.DropSource(self, curs) + dragSource.SetData(do) + g.frame.SetStatusText('Release the mouse button over the test window') + dragSource.DoDragDrop() + # Process key events def OnKeyDown(self, evt): if evt.GetKeyCode() == wx.WXK_CONTROL: