def mouseEvent(self, type, target, event): """transform QMouseEvent to MouseEvent""" btn_mask = MouseEvent.NO_BUTTON mod_mask = MouseEvent.NO_MODIFIER if event.buttons() & QtCore.Qt.LeftButton: btn_mask |= MouseEvent.LEFT_BUTTON if event.buttons() & QtCore.Qt.RightButton: btn_mask |= MouseEvent.RIGHT_BUTTON # special case: store last btn_mask in MouseEvent of type MOUSE_RELEASE # to indicate which button has been released. if (type == MouseEvent.MOUSE_RELEASE and btn_mask == MouseEvent.NO_BUTTON): btn_mask = self._last_btn_mask if event.modifiers() & QtCore.Qt.ShiftModifier: mod_mask |= MouseEvent.SHIFT_MODIFIER if event.modifiers() & QtCore.Qt.ControlModifier: mod_mask |= MouseEvent.CONTROL_MODIFIER if event.modifiers() & QtCore.Qt.AltModifier: mod_mask |= MouseEvent.ALT_MODIFIER if event.modifiers() & QtCore.Qt.MetaModifier: mod_mask |= MouseEvent.META_MODIFIER if event.modifiers() & QtCore.Qt.KeypadModifier: mod_mask |= MouseEvent.KEYPAD_MODIFIER if event.modifiers() & QtCore.Qt.GroupSwitchModifier: mod_mask |= MouseEvent.GROUP_SWITCH_MODIFIER # In order to support multiple plots in one widget # it is necessary to set the window in respect to the current # `PlotAxes` below the cursor. Otherwise the window will be determined # using the internal state machine of ``gr``. coords = DeviceCoordConverter(target.dwidth, target.dheight) coords.setDC(event.x(), event.y()) plots = target._getPlotsForPoint(coords.getNDC()) window, scale = None, None if plots and len(plots) == 1: # unambitious plot axes = plots[0].getAxes(0) # use first `PlotAxes` if axes: window = axes.getWindow() scale = axes.scale gr.setscale(axes.scale) mEvent = MouseEvent(type, target.dwidth, target.dheight, event.x(), event.y(), btn_mask, mod_mask, window=window, scale=scale) # special case: # save last btn_mask for handling in MouseEvent.MOUSE_RELEASE self._last_btn_mask = btn_mask return mEvent
def mouseEvent(self, type, target, event): """transform QMouseEvent to MouseEvent""" btn_mask = MouseEvent.NO_BUTTON mod_mask = MouseEvent.NO_MODIFIER if event.buttons() & QtCore.Qt.LeftButton: btn_mask |= MouseEvent.LEFT_BUTTON if event.buttons() & QtCore.Qt.RightButton: btn_mask |= MouseEvent.RIGHT_BUTTON # special case: store last btn_mask in MouseEvent of type MOUSE_RELEASE # to indicate which button has been released. if (type == MouseEvent.MOUSE_RELEASE and btn_mask == MouseEvent.NO_BUTTON): btn_mask = self._last_btn_mask if event.modifiers() & QtCore.Qt.ShiftModifier: mod_mask |= MouseEvent.SHIFT_MODIFIER if event.modifiers() & QtCore.Qt.ControlModifier: mod_mask |= MouseEvent.CONTROL_MODIFIER if event.modifiers() & QtCore.Qt.AltModifier: mod_mask |= MouseEvent.ALT_MODIFIER if event.modifiers() & QtCore.Qt.MetaModifier: mod_mask |= MouseEvent.META_MODIFIER if event.modifiers() & QtCore.Qt.KeypadModifier: mod_mask |= MouseEvent.KEYPAD_MODIFIER if event.modifiers() & QtCore.Qt.GroupSwitchModifier: mod_mask |= MouseEvent.GROUP_SWITCH_MODIFIER # In order to support multiple plots in one widget # it is necessary to set the window in respect to the current # `PlotAxes` below the cursor. Otherwise the window will be determined # using the internal state machine of ``gr``. coords = DeviceCoordConverter(target.dwidth, target.dheight) coords.setDC(event.x(), event.y()) plots = target._getPlotsForPoint(coords.getNDC()) window = None if plots and len(plots) == 1: # unambitious plot axes = plots[0].getAxes(0) # use first `PlotAxes` if axes: window = axes.getWindow() gr.setscale(axes.scale) mEvent = MouseEvent(type, target.dwidth, target.dheight, event.x(), event.y(), btn_mask, mod_mask, window=window) # special case: # save last btn_mask for handling in MouseEvent.MOUSE_RELEASE self._last_btn_mask = btn_mask return mEvent
class MouseLocationEventMeta(EventMeta): def __init__(self, type, width, height, x, y, window=None): super(MouseLocationEventMeta, self).__init__(type) self._coords = DeviceCoordConverter(width, height, window=window) self._coords.setDC(x, y) def getWindow(self): return self._coords.getWindow() def getWC(self, viewport): return self._coords.getWC(viewport) def getNDC(self): return self._coords.getNDC() def getDC(self): return self._coords.getDC()