def OnMotion(self, evt): # Ignore mouse movement if we're not dragging. if not self.dragShape or not evt.Dragging() or not evt.LeftIsDown(): return # if we have a shape, but haven't started dragging yet if self.dragShape and not self.dragImage: # only start the drag after having moved a couple pixels tolerance = 2 pt = evt.GetPosition() dx = abs(pt.x - self.dragStartPos.x) dy = abs(pt.y - self.dragStartPos.y) if dx <= tolerance and dy <= tolerance: return # refresh the area of the window where the shape was so it # will get erased. self.dragShape.shown = False self.RefreshRect(self.dragShape.GetRect(), True) self.Update() if self.dragShape.text: self.dragImage = wx.DragString(self.dragShape.text, wx.StockCursor(wx.CURSOR_HAND)) else: self.dragImage = wx.DragImage(self.dragShape.bmp, wx.StockCursor(wx.CURSOR_HAND)) hotspot = self.dragStartPos - self.dragShape.pos self.dragImage.BeginDrag(hotspot, self, self.dragShape.fullscreen) self.dragImage.Move(pt) self.dragImage.Show() # if we have shape and image then move it, posibly highlighting another shape. elif self.dragShape and self.dragImage: onShape = self.FindShape(evt.GetPosition()) unhiliteOld = False hiliteNew = False # figure out what to hilite and what to unhilite if self.hiliteShape: if onShape is None or self.hiliteShape is not onShape: unhiliteOld = True if onShape and onShape is not self.hiliteShape and onShape.shown: hiliteNew = True # if needed, hide the drag image so we can update the window if unhiliteOld or hiliteNew: self.dragImage.Hide() if unhiliteOld: dc = wx.ClientDC(self) self.hiliteShape.Draw(dc) self.hiliteShape = None if hiliteNew: dc = wx.ClientDC(self) self.hiliteShape = onShape self.hiliteShape.Draw(dc, wx.INVERT) # now move it and show it again if needed self.dragImage.Move(evt.GetPosition()) if unhiliteOld or hiliteNew: self.dragImage.Show()
def OnMotion(self, evt): tool = self.GetParent().toolSelect dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) print tool othrtools = (tool == "imageicons/polexdrawicon.png" or tool == "imageicons/poledrawicon.png" or tool == "imageicons/linedrawicon.png" or tool == "imageicons/Hpolexdrawicon.png" or tool == "imageicons/Hpoledrawicon.png") if evt.Dragging() and evt.LeftIsDown() and ( tool == "imageicons/freehandicon2.png"): self.drawMotion(dc, evt) elif evt.Moving() and othrtools and not evt.RightIsDown(): self.drawimaglineMotion(dc, evt) elif evt.Dragging() and othrtools and evt.RightIsDown(): #print 'should drag!!!' # if we have a shape, but haven't started dragging yet if self.dragShape and not self.dragImage: # print'not yet moving' # only start the drag after having moved a couple pixels tolerance = 2 pt = evt.GetPosition() dx = abs(pt.x - self.dragStartPos.x) dy = abs(pt.y - self.dragStartPos.y) if dx <= tolerance and dy <= tolerance: return # refresh the area of the window where the shape was so it # will get erased. self.dragShape.shown = False self.RefreshRect(self.dragShape.GetRect(), True) self.Update() if self.dragShape.text: self.dragImage = wx.DragString( self.dragShape.text, wx.StockCursor(wx.CURSOR_HAND)) else: self.dragImage = wx.DragImage( self.dragShape.bmp, wx.StockCursor(wx.CURSOR_HAND)) hotspot = self.dragStartPos - self.dragShape.pos self.dragImage.BeginDrag(hotspot, self, self.dragShape.fullscreen) self.dragImage.Move(pt) self.dragImage.Show() # if we have shape and image then move it, posibly highlighting another shape. elif self.dragShape and self.dragImage: #print'moving' onShape = self.FindShape(evt.GetPosition()) unhiliteOld = False hiliteNew = False # figure out what to hilite and what to unhilite if self.hiliteShape: if onShape is None or self.hiliteShape is not onShape: unhiliteOld = True if onShape and onShape is not self.hiliteShape and onShape.shown: hiliteNew = True # if needed, hide the drag image so we can update the window if unhiliteOld or hiliteNew: self.dragImage.Hide() if unhiliteOld: dc = wx.ClientDC(self) self.hiliteShape.Draw(dc) self.hiliteShape = None if hiliteNew: dc = wx.ClientDC(self) self.hiliteShape = onShape self.hiliteShape.Draw(dc, wx.INVERT) # now move it and show it again if needed pos = evt.GetPositionTuple() self.dragImage.Move(pos) self.shapedict[self.dragShape][0] = pos[0] self.shapedict[self.dragShape][1] = pos[1] if unhiliteOld or hiliteNew: self.dragImage.Show() #self.InitBuffer() evt.Skip()