import itertools
import qtcompat
import sigrok.core as sr
-import time
import util
try:
QtCore = qtcompat.QtCore
QtGui = qtcompat.QtGui
+class Trace(object):
+ '''Class to hold the measured samples.'''
+
+ def __init__(self):
+ self.samples = []
+ self.new = False
+
+ def append(self, sample):
+ self.samples.append(sample)
+ self.new = True
+
class MeasurementDataModel(QtGui.QStandardItemModel):
'''Model to hold the measured values.'''
'''Role used to store the device vendor and model.'''
descRole = QtCore.Qt.UserRole + 2
- '''Role used to store past samples.'''
- samplesRole = QtCore.Qt.UserRole + 3
+ '''Role used to store a dictionary with the traces'''
+ tracesRole = QtCore.Qt.UserRole + 3
'''Role used to store the color to draw the graph of the channel.'''
colorRole = QtCore.Qt.UserRole + 4
def _make_colorgen(self):
cols = [
QtGui.QColor(0x8F, 0x52, 0x02), # brown
+ QtGui.QColor(0x73, 0xD2, 0x16), # green
QtGui.QColor(0xCC, 0x00, 0x00), # red
+ QtGui.QColor(0x34, 0x65, 0xA4), # blue
QtGui.QColor(0xF5, 0x79, 0x00), # orange
QtGui.QColor(0xED, 0xD4, 0x00), # yellow
- QtGui.QColor(0x73, 0xD2, 0x16), # green
- QtGui.QColor(0x34, 0x65, 0xA4), # blue
QtGui.QColor(0x75, 0x50, 0x7B) # violet
]
item = QtGui.QStandardItem()
item.setData(uid, MeasurementDataModel.idRole)
item.setData(desc, MeasurementDataModel.descRole)
- item.setData(collections.defaultdict(list), MeasurementDataModel.samplesRole)
+ item.setData(collections.defaultdict(Trace), MeasurementDataModel.tracesRole)
item.setData(next(self._colorgen), MeasurementDataModel.colorRole)
self.appendRow(item)
self.sort(0)
return item
- @QtCore.Slot(object, object, object)
- def update(self, device, channel, data):
+ @QtCore.Slot(float, sr.classes.Device, sr.classes.Channel, tuple)
+ def update(self, timestamp, device, channel, data):
'''Update the data for the device (+channel) with the most recent
measurement from the given payload.'''
# The samples role is a dictionary that contains the old samples for each unit.
# Should be trimmed periodically, otherwise it grows larger and larger.
- sample = (time.time(), value)
- d = item.data(MeasurementDataModel.samplesRole)
- d[unit].append(sample)
+ sample = (timestamp, value)
+ traces = item.data(MeasurementDataModel.tracesRole)
+ traces[unit].append(sample)
class MultimeterDelegate(QtGui.QStyledItemDelegate):
'''Delegate to show the data items from a MeasurementDataModel.'''