def __init__(self, parent=None):
#pyqtgraph.setConfigOptions(imageAxisOrder='row-major')
super(self.__class__, self).__init__()
self.setupUi(self)
self.slider_spatialr.valueChanged.connect(self.runSegment)
self.slider_ranger.valueChanged.connect(self.runSegment)
self.slider_classes.valueChanged.connect(self.runClassification)
self.imageItem = pyqtgraph.ImageItem()
self.view = pyqtgraph.ViewBox()
self.view.addItem(self.imageItem)
#segResult is of class pyqtgraph.GraphicsView
self.segResult.setCentralItem(self.view)
#get file pathes with buttons
self.RGBimgpathButton.clicked.connect(self.getFileRGB)
self.smoothedpathButton.clicked.connect(self.getFilesmoothed)
self.saveClassificationButton.clicked.connect(self.saveFileClassified)
#temporary data of segmented image
self.segmentedout = "data/app_segmented.tif"
self.RGBimgpath = "data/test_image_cubic_resample.tif"
self.smoothedpath = "data/smoothed.tif"
python类ViewBox()的实例源码
def addAxis(self,plot,**args):
"""
Add an axis on the right side
.. tabularcolumns:: |p{3cm}|p{11cm}|
=============== ============================================================================================
**Arguments**
=============== ============================================================================================
plot pyqtgraph.PlotWidget
*args
1. label Label of the new axis
=============== ============================================================================================
:return: pg.ViewBox
"""
p3 = pg.ViewBox()
ax3 = pg.AxisItem('right')
plot.plotItem.layout.addItem(ax3, 2, 3+len(plot.axisItems))
plot.plotItem.scene().addItem(p3)
ax3.linkToView(p3)
p3.setXLink(plot.plotItem)
ax3.setZValue(-10000)
if args.get('label',False):
ax3.setLabel(args.get('label',False), color=args.get('color','#ffffff'))
p3.setGeometry(plot.plotItem.vb.sceneBoundingRect())
p3.linkedViewChanged(plot.plotItem.vb, p3.XAxis)
## Handle view resizing
Callback = functools.partial(self.updateViews,plot)
plot.getViewBox().sigStateChanged.connect(Callback)
plot.viewBoxes.append(p3)
plot.axisItems.append(ax3)
self.plots2D[p3]=[] # TODO do not consider a new axis as a plot. simply make it a part of the axisItems array of the main plot
return p3
def enableRightAxis(self,plot):
p = pg.ViewBox()
plot.showAxis('right')
plot.setMenuEnabled(False)
plot.scene().addItem(p)
plot.getAxis('right').linkToView(p)
p.setXLink(plot)
plot.viewBoxes.append(p)
Callback = functools.partial(self.updateViews,plot)
plot.getViewBox().sigStateChanged.connect(Callback)
if self.properties['colorScheme']=='white':
self.setColorSchemeWhite()
self.plots2D[p]=[]
return p
def _update_plot_views(self):
## view has resized; update auxiliary views to match
self._right_axis.setGeometry(self._plot_item.vb.sceneBoundingRect())
self._top_axis.setGeometry(self._plot_item.vb.sceneBoundingRect())
## need to re-update linked axes since this was called
## incorrectly while views had different shapes.
## (probably this should be handled in ViewBox.resizeEvent)
self._right_axis.linkedViewChanged(self._plot_item.vb, self._right_axis.XAxis)
self._top_axis.linkedViewChanged(self._plot_item.vb, self._top_axis.YAxis)
def updateViews(self):
## view has resized; update auxiliary views to match
self.plot2.setGeometry(self.plot1.vb.sceneBoundingRect())
## need to re-update linked axes since this was called
## incorrectly while views had different shapes.
## (probably this should be handled in ViewBox.resizeEvent)
self.plot2.linkedViewChanged(self.plot1.vb, self.plot2.XAxis)
def __init__(self, *args, **kwds):
pg.ViewBox.__init__(self, *args, **kwds)
self.setMouseMode(self.RectMode)
# reimplement right-click to zoom out
def mouseDragEvent(self, ev, axis=0):
if (ev.button() == QtCore.Qt.LeftButton) and (ev.modifiers() & QtCore.Qt.ControlModifier):
pg.ViewBox.mouseDragEvent(self, ev, axis)
else:
ev.ignore()
def updateViews(self):
""" Keep plot views for left and right axis identical when resizing the plot widget. """
# view has resized; update auxiliary views to match
self.plot2.setGeometry(self.plot1.vb.sceneBoundingRect())
# need to re-update linked axes since this was called incorrectly while views had different
# shapes. (probably this should be handled in ViewBox.resizeEvent)
self.plot2.linkedViewChanged(self.plot1.vb, self.plot2.XAxis)
def on_activate(self):
""" Definition and initialisation of the GUI.
"""
self._spectrum_logic = self.get_connector('spectrumlogic1')
# setting up the window
self._mw = SpectrometerWindow()
self._mw.stop_diff_spec_Action.setEnabled(False)
self._mw.resume_diff_spec_Action.setEnabled(False)
# giving the plots names allows us to link their axes together
self._pw = self._mw.plotWidget # pg.PlotWidget(name='Counter1')
self._plot_item = self._pw.plotItem
# create a new ViewBox, link the right axis to its coordinate system
self._right_axis = pg.ViewBox()
self._plot_item.showAxis('right')
self._plot_item.scene().addItem(self._right_axis)
self._plot_item.getAxis('right').linkToView(self._right_axis)
self._right_axis.setXLink(self._plot_item)
# create a new ViewBox, link the right axis to its coordinate system
self._top_axis = pg.ViewBox()
self._plot_item.showAxis('top')
self._plot_item.scene().addItem(self._top_axis)
self._plot_item.getAxis('top').linkToView(self._top_axis)
self._top_axis.setYLink(self._plot_item)
self._top_axis.invertX(b=True)
# handle resizing of any of the elements
self._pw.setLabel('left', 'Fluorescence', units='counts/s')
self._pw.setLabel('right', 'Number of Points', units='#')
self._pw.setLabel('bottom', 'Wavelength', units='nm')
self._pw.setLabel('top', 'Relative Frequency', units='Hz')
self._mw.rec_single_spectrum_Action.triggered.connect(self.record_single_spectrum)
self._mw.start_diff_spec_Action.triggered.connect(self.start_differential_measurement)
self._mw.stop_diff_spec_Action.triggered.connect(self.stop_differential_measurement)
self._mw.resume_diff_spec_Action.triggered.connect(self.resume_differential_measurement)
self._mw.save_spectrum_Action.triggered.connect(self.save_spectrum_data)
self._spectrum_logic.sig_specdata_updated.connect(self.updateData)
self._mw.show()
# Create an empty plot curve to be filled later, set its pen
self._curve1 = self._pw.plot()
self._curve1.setPen(palette.c2, width=2)
self._save_PNG = True