gui: common format for results/params

This commit is contained in:
Sebastien Bourdeauducq 2015-07-22 06:01:09 +08:00
parent bd2bd68a54
commit 073e09ed36
3 changed files with 16 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -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