Module audian.selectviewbox
Classes
class SelectViewBox (channel, *args, **kwargs)
-
Bases: :class:
GraphicsWidget <pyqtgraph.GraphicsWidget>
Box that allows internal scaling/panning of children by mouse drag. This class is usually created automatically as part of a :class:
PlotItem <pyqtgraph.PlotItem>
or :ref:Canvas <Canvas>
or with :func:GraphicsLayout.addViewBox() <pyqtgraph.GraphicsLayout.addViewBox>
.Features
- Scaling contents by mouse or auto-scale when contents change
- View linking–multiple views display the same data ranges
- Configurable by context menu
- Item coordinate mapping methods
================= ============================================================= Arguments: parent (QGraphicsWidget) Optional parent widget border (QPen) Do draw a border around the view, give any single argument accepted by :func:
mkPen <pyqtgraph.mkPen>
lockAspect (False or float) The aspect ratio to lock the view coorinates to. (or False to allow the ratio to change) enableMouse (bool) Whether mouse can be used to scale/pan the view invertY (bool) See :func:invertY <pyqtgraph.ViewBox.invertY>
invertX (bool) See :func:invertX <pyqtgraph.ViewBox.invertX>
enableMenu (bool) Whether to display a context menu when right-clicking on the ViewBox background. name (str) Used to register this ViewBox so that it appears in the "Link axis" dropdown inside other ViewBox context menus. This allows the user to manually link the axes of any other view to this one. defaultPadding (float) fraction of the data range that will be added as padding by default ================= =============================================================Expand source code
class SelectViewBox(pg.ViewBox): sigSelectedRegion = Signal(object, object, object) def __init__(self, channel, *args, **kwargs): pg.ViewBox.__init__(self, *args, **kwargs) self.setMouseMode(pg.ViewBox.RectMode) self.rbScaleBox.setPen(pg.mkPen((200, 200, 200), width=1)) self.rbScaleBox.setBrush(pg.mkBrush(200, 200, 200, 100)) self.channel = channel def keyPressEvent(self, ev): ev.ignore() def mouseDragEvent(self, ev, axis=None): ## if axis is specified, event will only affect that axis. ev.accept() ## we accept all buttons pos = ev.pos() lastPos = ev.lastPos() dif = pos - lastPos dif = dif * -1 ## Ignore axes if mouse is disabled mouseEnabled = np.array(self.state['mouseEnabled'], dtype=np.float64) mask = mouseEnabled.copy() if axis is not None: mask[1-axis] = 0.0 ## Scale or translate based on mouse button if ev.button() in [Qt.MouseButton.LeftButton, Qt.MouseButton.MiddleButton]: if self.state['mouseMode'] == pg.ViewBox.RectMode and axis is None: if ev.isFinish(): # This is the final move in the drag; change the view scale now rect = QRectF(pg.Point(ev.buttonDownPos(ev.button())), pg.Point(pos)) rect = self.childGroup.mapRectFromParent(rect) # in data coordinates self.sigSelectedRegion.emit(self.channel, self, rect) else: ## update shape of scale box self.updateScaleBox(ev.buttonDownPos(), ev.pos()) else: tr = self.childGroup.transform() tr = pg.functions.invertQTransform(tr) tr = tr.map(dif*mask) - tr.map(pg.Point(0,0)) x = tr.x() if mask[0] == 1 else None y = tr.y() if mask[1] == 1 else None self._resetTarget() if x is not None or y is not None: self.translateBy(x=x, y=y) self.sigRangeChangedManually.emit(self.state['mouseEnabled']) if ev.isFinish(): self.add_region(self.viewRect()) elif ev.button() & Qt.MouseButton.RightButton: #print "vb.rightDrag" if self.state['aspectLocked'] is not False: mask[0] = 0 dif = ev.screenPos() - ev.lastScreenPos() dif = np.array([dif.x(), dif.y()]) dif[0] *= -1 s = ((mask * 0.02) + 1) ** dif tr = self.childGroup.transform() tr = pg.functions.invertQTransform(tr) x = s[0] if mouseEnabled[0] == 1 else None y = s[1] if mouseEnabled[1] == 1 else None center = pg.Point(tr.map(ev.buttonDownPos(Qt.MouseButton.RightButton))) self._resetTarget() self.scaleBy(x=x, y=y, center=center) self.sigRangeChangedManually.emit(self.state['mouseEnabled']) if ev.isFinish(): self.add_region(self.viewRect()) def updateScaleBox(self, p1, p2): r = QRectF(p1, p2) r = self.childGroup.mapRectFromParent(r) self.rbScaleBox.setPos(r.topLeft()) tr = QTransform.fromScale(r.width(), r.height()) self.rbScaleBox.setTransform(tr) self.rbScaleBox.show() def hide_region(self): self.rbScaleBox.hide() def add_region(self, rect): self.axHistoryPointer += 1 self.axHistory = self.axHistory[:self.axHistoryPointer] + [rect] def zoom_region(self, rect): self.hide_region() self.showAxRect(rect) self.add_region(rect) def zoom_back(self): self.scaleHistory(-1) def zoom_forward(self): self.scaleHistory(1) def zoom_home(self): self.scaleHistory(-len(self.axHistory)) def init_zoom_history(self): self.add_region(self.viewRect())
Ancestors
- pyqtgraph.graphicsItems.ViewBox.ViewBox.ViewBox
- pyqtgraph.graphicsItems.GraphicsWidget.GraphicsWidget
- pyqtgraph.graphicsItems.GraphicsItem.GraphicsItem
- PyQt5.QtWidgets.QGraphicsWidget
- PyQt5.QtWidgets.QGraphicsObject
- PyQt5.QtCore.QObject
- PyQt5.QtWidgets.QGraphicsItem
- PyQt5.QtWidgets.QGraphicsLayoutItem
- sip.wrapper
- sip.simplewrapper
Methods
def sigSelectedRegion(...)
-
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal's arguments.
def keyPressEvent(self, ev)
-
This routine should capture key presses in the current view box. Key presses are used only when mouse mode is RectMode The following events are implemented: ctrl-A : zooms out to the default "full" view of the plot ctrl-+ : moves forward in the zooming stack (if it exists) ctrl– : moves backward in the zooming stack (if it exists)
def mouseDragEvent(self, ev, axis=None)
def updateScaleBox(self, p1, p2)
def hide_region(self)
def add_region(self, rect)
def zoom_region(self, rect)
def zoom_back(self)
def zoom_forward(self)
def zoom_home(self)
def init_zoom_history(self)