From 073e09ed364c6e790125fff6a92bc217f4ce79be Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 22 Jul 2015 06:01:09 +0800 Subject: [PATCH] gui: common format for results/params --- artiq/gui/parameters.py | 4 ++-- artiq/gui/results.py | 14 +++----------- artiq/gui/tools.py | 11 +++++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/artiq/gui/parameters.py b/artiq/gui/parameters.py index 86495b6bf..e608beae2 100644 --- a/artiq/gui/parameters.py +++ b/artiq/gui/parameters.py @@ -5,7 +5,7 @@ from pyqtgraph import dockarea from pyqtgraph import LayoutWidget from artiq.protocols.sync_struct import Subscriber -from artiq.gui.tools import DictSyncModel +from artiq.gui.tools import DictSyncModel, short_format class ParametersModel(DictSyncModel): @@ -20,7 +20,7 @@ class ParametersModel(DictSyncModel): if column == 0: return k elif column == 1: - return str(v) + return short_format(v) else: raise ValueError diff --git a/artiq/gui/results.py b/artiq/gui/results.py index 40522d719..900e16663 100644 --- a/artiq/gui/results.py +++ b/artiq/gui/results.py @@ -7,21 +7,13 @@ from pyqtgraph import dockarea from pyqtgraph import LayoutWidget from artiq.protocols.sync_struct import Subscriber -from artiq.gui.tools import DictSyncModel +from artiq.gui.tools import DictSyncModel, short_format from artiq.gui.displays import * -def _fmt_type(v): - t = type(v) - r = t.__name__ - if t is list or t is dict or t is set: - r += " ({})".format(len(v)) - return r - - class ResultsModel(DictSyncModel): def __init__(self, parent, init): - DictSyncModel.__init__(self, ["Result", "Type"], + DictSyncModel.__init__(self, ["Result", "Value"], parent, init) def sort_key(self, k, v): @@ -31,7 +23,7 @@ class ResultsModel(DictSyncModel): if column == 0: return k elif column == 1: - return _fmt_type(v) + return short_format(v) else: raise ValueError diff --git a/artiq/gui/tools.py b/artiq/gui/tools.py index ece8125b8..cab4e256d 100644 --- a/artiq/gui/tools.py +++ b/artiq/gui/tools.py @@ -1,6 +1,17 @@ from quamash import QtCore +def short_format(v): + t = type(v) + if t is int or t is float: + return str(v) + else: + r = t.__name__ + if t is list or t is dict or t is set: + r += " ({})".format(len(v)) + return r + + class _SyncSubstruct: def __init__(self, update_cb, ref): self.update_cb = update_cb