def __init__(self, type, width, height, x, y, window=None, scale=None): super(MouseLocationEventMeta, self).__init__(type) self._coords = DeviceCoordConverter(width, height, window=window, scale=scale) self._coords.setDC(x, y)
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
def _roi(self, p0, type, buttons, modifiers): for plot in self._lstPlot: roi = plot.getROI(p0) if roi: if roi.regionType == RegionOfInterest.LEGEND: eventObj = LegendEvent else: eventObj = ROIEvent coords = DeviceCoordConverter(self.dwidth, self.dheight) coords.setNDC(p0.x, p0.y) p0dc = coords.getDC() QtGui.QApplication.sendEvent( self, eventObj(type, self.dwidth, self.dheight, p0dc.x, p0dc.y, buttons, modifiers, roi))
def _roi(self, p0, type, buttons, modifiers): for plot in self._lstPlot: roi = plot.getROI(p0) if roi: if roi.regionType == RegionOfInterest.LEGEND: eventObj = LegendEvent else: eventObj = ROIEvent coords = DeviceCoordConverter(self.dwidth, self.dheight) coords.setNDC(p0.x, p0.y) p0dc = coords.getDC() QtGui.QApplication.sendEvent(self, eventObj(type, self.dwidth, self.dheight, p0dc.x, p0dc.y, buttons, modifiers, roi))
def paintEvent(self, event): super(InteractiveGRWidget, self).paintEvent(event) self._painter.begin(self) if self.getMouseSelectionEnabled() and self._tselect: p0, p1 = self._tselect coords = DeviceCoordConverter(self.dwidth, self.dheight) coords.setNDC(p0.x, p0.y) p0dc = coords.getDC() coords.setNDC(p1.x, p1.y) p1dc = coords.getDC() if self._getPlotsForPoint(p0): rect = QtCore.QRect(QtCore.QPoint(p0dc.x, p0dc.y), QtCore.QPoint(p1dc.x, p1dc.y)).normalized() self._painter.setOpacity(.75) self._painter.drawRect(rect) self._painter.setOpacity(1.) self._painter.end()
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()
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)