forked from M-Labs/artiq
1
0
Fork 0

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 pyqtgraph import LayoutWidget
from artiq.protocols.sync_struct import Subscriber from artiq.protocols.sync_struct import Subscriber
from artiq.gui.tools import DictSyncModel from artiq.gui.tools import DictSyncModel, short_format
class ParametersModel(DictSyncModel): class ParametersModel(DictSyncModel):
@ -20,7 +20,7 @@ class ParametersModel(DictSyncModel):
if column == 0: if column == 0:
return k return k
elif column == 1: elif column == 1:
return str(v) return short_format(v)
else: else:
raise ValueError raise ValueError

View File

@ -7,21 +7,13 @@ from pyqtgraph import dockarea
from pyqtgraph import LayoutWidget from pyqtgraph import LayoutWidget
from artiq.protocols.sync_struct import Subscriber 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 * 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): class ResultsModel(DictSyncModel):
def __init__(self, parent, init): def __init__(self, parent, init):
DictSyncModel.__init__(self, ["Result", "Type"], DictSyncModel.__init__(self, ["Result", "Value"],
parent, init) parent, init)
def sort_key(self, k, v): def sort_key(self, k, v):
@ -31,7 +23,7 @@ class ResultsModel(DictSyncModel):
if column == 0: if column == 0:
return k return k
elif column == 1: elif column == 1:
return _fmt_type(v) return short_format(v)
else: else:
raise ValueError raise ValueError

View File

@ -1,6 +1,17 @@
from quamash import QtCore 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: class _SyncSubstruct:
def __init__(self, update_cb, ref): def __init__(self, update_cb, ref):
self.update_cb = update_cb self.update_cb = update_cb