'''The main window of the application.'''
# Number of seconds that the plots display.
- BACKLOG = 10
+ BACKLOG = 30
# Update interval of the plots in milliseconds.
UPDATEINTERVAL = 100
self.listView.setMinimumSize(self.delegate.sizeHint())
self.plotwidget = multiplotwidget.MultiPlotWidget(self)
+ self.plotwidget.plotHidden.connect(self._on_plotHidden)
# Maps from 'unit' to the corresponding plot.
self._plots = {}
return self._curves[key]
# create a new curve
- curve = pyqtgraph.PlotDataItem()
+ curve = pyqtgraph.PlotDataItem(
+ antialias=True,
+ symbolPen=pyqtgraph.mkPen(QtGui.QColor(QtCore.Qt.black)),
+ symbolBrush=pyqtgraph.mkBrush(QtGui.QColor(QtCore.Qt.black)),
+ symbolSize=1
+ )
plot.view.addItem(curve)
self._curves[key] = curve
def timerEvent(self, event):
'''Periodically updates all graphs.'''
- for row in range(self.model.rowCount()):
- idx = self.model.index(row, 0)
- deviceID = self.model.data(idx, datamodel.MeasurementDataModel.idRole)
- sampledict = self.model.data(idx, datamodel.MeasurementDataModel.samplesRole)
- for unit in sampledict:
- self._updatePlot(deviceID, unit, sampledict[unit])
-
- def _updatePlot(self, deviceID, unit, samples):
- '''Updates the curve of device 'deviceID' and 'unit' with 'samples'.'''
-
- plot = self._getPlot(unit)
- curve = self._getCurve(plot, deviceID)
-
- now = time.time()
+ self._updatePlots()
- # remove old samples
- l = now - MainWindow.BACKLOG
- while samples and samples[0][0] < l:
- samples.pop(0)
+ def _updatePlots(self):
+ '''Updates all plots.'''
- xdata = [s[0] - now for s in samples]
- ydata = [s[1] for s in samples]
+ # loop over all devices and channels
+ for row in range(self.model.rowCount()):
+ idx = self.model.index(row, 0)
+ deviceID = self.model.data(idx,
+ datamodel.MeasurementDataModel.idRole)
+ deviceID = tuple(deviceID) # PySide returns a list.
+ traces = self.model.data(idx,
+ datamodel.MeasurementDataModel.tracesRole)
+
+ for unit, trace in traces.items():
+ now = time.time()
+
+ # remove old samples
+ l = now - MainWindow.BACKLOG
+ while trace.samples and trace.samples[0][0] < l:
+ trace.samples.pop(0)
+
+ plot = self._getPlot(unit)
+ if not plot.visible:
+ if trace.new:
+ self.plotwidget.showPlot(plot)
+
+ if plot.visible:
+ xdata = [s[0] - now for s in trace.samples]
+ ydata = [s[1] for s in trace.samples]
+
+ color = self.model.data(idx,
+ datamodel.MeasurementDataModel.colorRole)
+
+ curve = self._getCurve(plot, deviceID)
+ curve.setPen(pyqtgraph.mkPen(color=color))
+ curve.setData(xdata, ydata)
+
+ @QtCore.Slot(multiplotwidget.Plot)
+ def _on_plotHidden(self, plot):
+ plotunit = [u for u, p in self._plots.items() if p == plot][0]
+
+ # Mark all traces of all devices/channels with the same unit as the
+ # plot as "old" ('trace.new = False'). As soon as a new sample arrives
+ # on one trace, the plot will be shown again
+ for row in range(self.model.rowCount()):
+ idx = self.model.index(row, 0)
+ traces = self.model.data(idx, datamodel.MeasurementDataModel.tracesRole)
- curve.setData(xdata, ydata)
+ for traceunit, trace in traces.items():
+ if traceunit == plotunit:
+ trace.new = False
def closeEvent(self, event):
self.thread.stop()