From: Jens Steinhauser Date: Tue, 6 Oct 2015 11:52:43 +0000 (+0200) Subject: Add PySide compatibility. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1879265add9b3abfec2d651c452fbf5be20b236d;p=sigrok-meter.git Add PySide compatibility. --- diff --git a/datamodel.py b/datamodel.py index 2914fc3..2b29fa4 100644 --- a/datamodel.py +++ b/datamodel.py @@ -18,7 +18,6 @@ ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ## -import collections import itertools import math import qtcompat @@ -134,7 +133,7 @@ class MeasurementDataModel(QtGui.QStandardItemModel): item = QtGui.QStandardItem() item.setData(uid, MeasurementDataModel.idRole) item.setData(desc, MeasurementDataModel.descRole) - item.setData(collections.defaultdict(Trace), MeasurementDataModel.tracesRole) + item.setData({}, MeasurementDataModel.tracesRole) item.setData(next(self._colorgen), MeasurementDataModel.colorRole) self.appendRow(item) self.sort(0) @@ -161,8 +160,15 @@ class MeasurementDataModel(QtGui.QStandardItemModel): if not math.isinf(value) and not math.isnan(value): sample = (timestamp, value) traces = item.data(MeasurementDataModel.tracesRole) + + # It's not possible to use 'collections.defaultdict' here, because + # PySide doesn't return the original type that was passed in. + if not (unit in traces): + traces[unit] = Trace() traces[unit].append(sample) + item.setData(traces, MeasurementDataModel.tracesRole) + class MultimeterDelegate(QtGui.QStyledItemDelegate): '''Delegate to show the data items from a MeasurementDataModel.''' diff --git a/mainwindow.py b/mainwindow.py index 8ac3b3d..7398a5a 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -185,6 +185,7 @@ class MainWindow(QtGui.QMainWindow): 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)