def _startruler(self, evt): self.scene.sigMouseClicked.disconnect(self._startruler) self.rulers.append(pg.PlotDataItem( symbol='+', pen=pg.mkPen(color=self.pColor.value(), width=2), symbolSize=16, symbolBrush=pg.mkBrush(self.pColor.value()) )) self.rulersLen.append(pg.TextItem( text='', color=(0, 0, 0), html=None, anchor=(0, 0), border=None, fill=pg.mkBrush(self.pColor.value()), angle=0 )) self.view.addItem(self.rulers[-1]) self.view.addItem(self.rulersLen[-1]) self.rulersStartX, self.rulersStartY = self.mouseCoord(evt) self.rulersLen[-1].setPos(self.rulersStartX, self.rulersStartY) self.scene.sigMouseMoved.connect(self._moveruler) self.scene.sigMouseClicked.connect(self._stopruler)
def __init__(self, tool, name, pos, pen): super(_POI, self).__init__(pos, size=[0,0]) self.handlePen = pen self.addTranslateHandle([0.5, 0.5]) self._name = name self.tool = tool self.view = tool.view self.slaveDock = tool.slave self.master = tool.display.widget self.masterDisplay = tool.display slave = self.slaveDock.widget #PLOT self.plot = slave.addLayer(name=self._name, pen=pen) #LABEL self.text = pg.TextItem( text=self._name, color=(0,0,0), html=None, anchor=(0, 0), border=None, fill=pg.mkBrush(255, 255, 255, 80), angle=0) #CONNECT self.slaveDock.closed.connect(lambda: self.toggleShow(False)) self.sigRegionChanged.connect(self.updateView) #UPDATE self.updateView() self.toggleShow()
def _setPOI(self, evt): mx, my = self.mouseCoord(evt) self.poiMarker.addPoints(x=[mx], y=[my], symbol="+", size=10) textPOI = pg.TextItem(text=self.poiText, color=(0, 0, 0), html=None, anchor=(self.anchorX, self.anchorY), border=None, fill=pg.mkBrush(255, 255, 255, 80), angle=0) textPOI.setPos(mx, my) self.poiTextList.append(textPOI) self.view.addItem(textPOI)
def __init__(self, tool, masterDisplay, slaveDisplay, name, index, pen='r', pos=[10, 10], size=[50, 50]): self.text = pg.TextItem(text=name, color=(0, 0, 0), html=None, anchor=(0, 0), border=None, fill=pg.mkBrush(255, 255, 255, 80), angle=0) pg.ROI.__init__(self, pos=pos, size=size, angle=0.0, pen=pen) self.tool = tool self.masterDisplay = masterDisplay self.master = masterDisplay.widget self.slaveDisplay = slaveDisplay self.index = index self._pen = pen # CONNECT SIGNALS: self.masterDisplay.closed.connect(self._masterClosed) self.master.item.sigImageChanged.connect(self.updateView) # display closed: self.slaveDisplay.closed.connect(self.close) # TODO: layer removed: # if index != None: # self.slaveDisplay.stack.childs[].sigClosed... self.sigRegionChanged.connect(self.updateView) self.tool.pPlotAll.sigValueChanged.connect(self.setup) self.tool.display.stack.sigValuesChanged.connect(self.updateView) # FURTHER METHODS: self.setup() self.updateView()
def __init__(self, master, slave, name, fromTo, pen='r'): pg.LineSegmentROI.__init__(self, fromTo, pen=pen) self.master = master self.slaveDock = slave self.text = pg.TextItem(text=name, color=(0, 0, 0), html=None, anchor=(0, 0), border=None, fill=pg.mkBrush(255, 255, 255, 80), angle=0) self.slaveDock.closed.connect(lambda: self.toggleShow(False)) self.sigRegionChanged.connect(self.updateView) # UPDATE self.updateView() self.toggleShow() # DISABLE LOCK ASPECT: slave.widget.view.vb.setAspectLocked(False)
def build(self): self.poiMarker = pg.ScatterPlotItem(pen='r', brush='r') w = self.display.widget w.sigTimeChanged.connect(self._updateValues) w.imageItem.sigImageChanged.connect(self._updateValues) self.view.addItem(self.poiMarker) # draw text for crosshair self.anchorX, self.anchorY = 0, 1 self.crosshair = pg.TextItem(text='', color=(0, 0, 0), html=None, anchor=(self.anchorX, self.anchorY), border=None, fill=pg.mkBrush(255, 255, 255, 80), angle=0) # draw lines self.vLine = pg.InfiniteLine(angle=90, movable=False) self.hLine = pg.InfiniteLine(angle=0, movable=False) # add to viewBox self.view.addItem(self.vLine, ignoreBounds=True) self.view.addItem(self.hLine, ignoreBounds=True) self.view.addItem(self.crosshair) def mouseMoved(evt): w = self.display.widget if self.view.sceneBoundingRect().contains(evt.x(), evt.y()): x, y = self.mouseCoord(evt) if w.image is None: return img = w.image[w.currentIndex] s0, s1 = img.shape[:2] ix = np.clip(int(x), 0, s1 - 1) iy = np.clip(int(y), 0, s0 - 1) z = img[iy, ix] # set anchor of crosshair if evt.y() - 30 > self.crosshair.boundingRect().height(): self.anchorY = 1 # at upper corner else: self.anchorY = 0 if (evt.x() + self.crosshair.boundingRect().width() > self.view.sceneBoundingRect().width()): self.anchorX = 1 # at right corner else: self.anchorX = 0 # set relative position of crosshair self.crosshair.anchor = pg.Point((self.anchorX, self.anchorY)) # set absolute position of crosshair self.crosshair.setPos(x, y) # move crosshair-lines to mousepos. self.vLine.setPos(x) self.hLine.setPos(y) self.poiText = self._getPOItext(x, y, z) self.crosshair.setText(self.poiText) # except IndexError: # pass # out of bounds # connect mouse-signals to new methods: self.scene.sigMouseMoved.connect(mouseMoved)