X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/372bde9b72b67036482dcc170f6260846e7a3b64..0604740afd3f5e1cc576787592761c8a0e14cdac:/wxPython/demo/CustomDragAndDrop.py?ds=sidebyside diff --git a/wxPython/demo/CustomDragAndDrop.py b/wxPython/demo/CustomDragAndDrop.py index fcb0947287..f5404cd4db 100644 --- a/wxPython/demo/CustomDragAndDrop.py +++ b/wxPython/demo/CustomDragAndDrop.py @@ -1,11 +1,3 @@ -# 11/5/2003 - Modified by grimmtooth@softhome.net (Jeff Grimmett) -# -# o Updated for wx namespace -# -# 11/24/2003 - Modified by grimmtooth@softhome.net (Jeff Grimmett) -# -# o Issues around line 167. I'm stuck. -# import cPickle import wx @@ -22,11 +14,11 @@ class DoodlePad(wx.Window): self.x = self.y = 0 self.SetMode("Draw") - wx.EVT_LEFT_DOWN(self, self.OnLeftDown) - wx.EVT_LEFT_UP(self, self.OnLeftUp) - wx.EVT_RIGHT_UP(self, self.OnRightUp) - wx.EVT_MOTION(self, self.OnMotion) - wx.EVT_PAINT(self, self.OnPaint) + self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) + self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) + self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp) + self.Bind(wx.EVT_MOTION, self.OnMotion) + self.Bind(wx.EVT_PAINT, self.OnPaint) def SetMode(self, mode): @@ -46,7 +38,7 @@ class DoodlePad(wx.Window): dc.SetPen(wx.Pen(wx.BLUE, 3)) for line in self.lines: for coords in line: - dc.DrawLineXY(*coords) + dc.DrawLine(*coords) dc.EndDrawing() @@ -63,22 +55,23 @@ class DoodlePad(wx.Window): def OnLeftUp(self, event): - self.lines.append(self.curLine) - self.curLine = [] - self.ReleaseMouse() + if self.HasCapture(): + self.lines.append(self.curLine) + self.curLine = [] + self.ReleaseMouse() def OnRightUp(self, event): self.lines = [] self.Refresh() def OnMotion(self, event): - if event.Dragging() and not self.mode == "Drag": + if self.HasCapture() and event.Dragging() and not self.mode == "Drag": dc = wx.ClientDC(self) dc.BeginDrawing() dc.SetPen(wx.Pen(wx.BLUE, 3)) - coords = ((self.x, self.y), event.GetPosition()) + coords = (self.x, self.y) + event.GetPositionTuple() self.curLine.append(coords) - dc.DrawLineXY(*coords) + dc.DrawLine(*coords) self.x, self.y = event.GetPositionTuple() dc.EndDrawing() @@ -89,7 +82,7 @@ class DoodlePad(wx.Window): # create our own data format and use it in a # custom data object - ldata = wx.CustomDataObject(wx.CustomDataFormat("DoodleLines")) + ldata = wx.CustomDataObject("DoodleLines") ldata.SetData(linesdata) # Also create a Bitmap version of the drawing @@ -132,8 +125,7 @@ class DoodleDropTarget(wx.PyDropTarget): self.dv = window # specify the type of data we will accept - self.df = wx.CustomDataFormat("DoodleLines") - self.data = wx.CustomDataObject(self.df) + self.data = wx.CustomDataObject("DoodleLines") self.SetDataObject(self.data) @@ -171,7 +163,7 @@ class DoodleDropTarget(wx.PyDropTarget): if self.GetData(): # convert it back to a list of lines and give it to the viewer linesdata = self.data.GetData() - lines = wx.InputStream(cPickle.loads(linesdata)) + lines = cPickle.loads(linesdata) self.dv.SetLines(lines) # what is returned signals the source what to do @@ -190,7 +182,7 @@ class DoodleViewer(wx.Window): self.x = self.y = 0 dt = DoodleDropTarget(self, log) self.SetDropTarget(dt) - wx.EVT_PAINT(self, self.OnPaint) + self.Bind(wx.EVT_PAINT, self.OnPaint) def SetLines(self, lines): @@ -207,7 +199,7 @@ class DoodleViewer(wx.Window): for line in self.lines: for coords in line: - dc.DrawLineXY(*coords) + dc.DrawLine(*coords) dc.EndDrawing() #---------------------------------------------------------------------- @@ -223,8 +215,8 @@ class CustomDnDPanel(wx.Panel): "Draw a little picture in this window\n" "then switch the mode below and drag the\n" "picture to the lower window or to another\n" - "application that accepts BMP's as a drop\n" - "target.\n" + "application that accepts Bitmaps as a\n" + "drop target.\n" ) rb1 = wx.RadioButton(self, -1, "Draw", style=wx.RB_GROUP) @@ -264,8 +256,8 @@ class CustomDnDPanel(wx.Panel): self.SetSizer(sizer) # Events - wx.EVT_RADIOBUTTON(self, rb1.GetId(), self.OnRadioButton) - wx.EVT_RADIOBUTTON(self, rb2.GetId(), self.OnRadioButton) + self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton, rb1) + self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton, rb2) def OnRadioButton(self, evt): @@ -322,11 +314,11 @@ if __name__ == '__main__': def MakeFrame(self, event=None): frame = wx.Frame(None, -1, "Custom Drag and Drop", size=(550,400)) menu = wx.Menu() - menu.Append(6543, "Window") + item = menu.Append(-1, "Window") mb = wx.MenuBar() mb.Append(menu, "New") frame.SetMenuBar(mb) - wx.EVT_MENU(frame, 6543, self.MakeFrame) + frame.Bind(wx.EVT_MENU, self.MakeFrame, item) panel = TestPanel(frame, DummyLog()) frame.Show(True) self.SetTopWindow(frame)