drag-and-drop adding of controls to test window
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45678 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -71,3 +71,16 @@ class Globals:
|
|||||||
|
|
||||||
|
|
||||||
g = Globals()
|
g = Globals()
|
||||||
|
|
||||||
|
|
||||||
|
class MyDataObject(wx.PyDataObjectSimple):
|
||||||
|
def __init__(self):
|
||||||
|
wx.PyDataObjectSimple.__init__(self, wx.CustomDataFormat('XRCed_DND'))
|
||||||
|
self.data = ''
|
||||||
|
def GetDataSize(self):
|
||||||
|
return len(self.data)
|
||||||
|
def GetDataHere(self):
|
||||||
|
return self.data # returns a string
|
||||||
|
def SetData(self, data):
|
||||||
|
self.data = data
|
||||||
|
return True
|
||||||
|
@@ -16,7 +16,6 @@ GROUP_WINDOWS, GROUP_MENUS, GROUP_SIZERS, GROUP_CONTROLS = range(GROUPNUM)
|
|||||||
|
|
||||||
# States depending on current selection and Control/Shift keys
|
# States depending on current selection and Control/Shift keys
|
||||||
STATE_ROOT, STATE_MENUBAR, STATE_TOOLBAR, STATE_MENU, STATE_STDDLGBTN, STATE_ELSE = range(6)
|
STATE_ROOT, STATE_MENUBAR, STATE_TOOLBAR, STATE_MENU, STATE_STDDLGBTN, STATE_ELSE = range(6)
|
||||||
|
|
||||||
# Left toolbar for GUI elements
|
# Left toolbar for GUI elements
|
||||||
class Tools(wx.Panel):
|
class Tools(wx.Panel):
|
||||||
TOOL_SIZE = (30, 30)
|
TOOL_SIZE = (30, 30)
|
||||||
@@ -108,6 +107,7 @@ class Tools(wx.Panel):
|
|||||||
button.SetBezelWidth(0)
|
button.SetBezelWidth(0)
|
||||||
wx.EVT_KEY_DOWN(button, self.OnKeyDown)
|
wx.EVT_KEY_DOWN(button, self.OnKeyDown)
|
||||||
wx.EVT_KEY_UP(button, self.OnKeyUp)
|
wx.EVT_KEY_UP(button, self.OnKeyUp)
|
||||||
|
wx.EVT_RIGHT_DOWN(button, self.OnRightClick)
|
||||||
button.SetToolTipString(text)
|
button.SetToolTipString(text)
|
||||||
self.curSizer.Add(button)
|
self.curSizer.Add(button)
|
||||||
self.groups[-1][1][id] = button
|
self.groups[-1][1][id] = button
|
||||||
@@ -160,6 +160,22 @@ class Tools(wx.Panel):
|
|||||||
else: box.SetLabel('[-] ' + box.name)
|
else: box.SetLabel('[-] ' + box.name)
|
||||||
self.Layout()
|
self.Layout()
|
||||||
|
|
||||||
|
# Drag
|
||||||
|
def OnRightClick(self, evt):
|
||||||
|
do = MyDataObject()
|
||||||
|
do.SetData(str(evt.GetId()))
|
||||||
|
bm = evt.GetEventObject().GetBitmapLabel()
|
||||||
|
if wx.Platform != '__WXMAC__':
|
||||||
|
icon = wx.EmptyIcon()
|
||||||
|
icon.CopyFromBitmap(bm)
|
||||||
|
dragSource = wx.DropSource(self, icon)
|
||||||
|
else: # on Mac DragSource requires cursor (but does not work anyway)
|
||||||
|
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
|
# Process key events
|
||||||
def OnKeyDown(self, evt):
|
def OnKeyDown(self, evt):
|
||||||
if evt.GetKeyCode() == wx.WXK_CONTROL:
|
if evt.GetKeyCode() == wx.WXK_CONTROL:
|
||||||
|
Reference in New Issue
Block a user