forked from M-Labs/artiq
1
0
Fork 0

client: use short_format in dataset display

This commit is contained in:
Sebastien Bourdeauducq 2015-10-12 18:10:58 +08:00
parent e6e93ab6ed
commit 22bffa98b5
4 changed files with 39 additions and 37 deletions

View File

@ -12,6 +12,7 @@ from prettytable import PrettyTable
from artiq.protocols.pc_rpc import Client from artiq.protocols.pc_rpc import Client
from artiq.protocols.sync_struct import Subscriber from artiq.protocols.sync_struct import Subscriber
from artiq.protocols import pyon from artiq.protocols import pyon
from artiq.tools import short_format
def clear_screen(): def clear_screen():
@ -192,7 +193,7 @@ def _show_datasets(datasets):
clear_screen() clear_screen()
table = PrettyTable(["Dataset", "Persistent", "Value"]) table = PrettyTable(["Dataset", "Persistent", "Value"])
for k, (persist, value) in sorted(datasets.items(), key=itemgetter(0)): for k, (persist, value) in sorted(datasets.items(), key=itemgetter(0)):
table.add_row([k, "Y" if persist else "N", str(value)]) table.add_row([k, "Y" if persist else "N", short_format(value)])
print(table) print(table)

View File

@ -8,7 +8,8 @@ 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, short_format from artiq.tools import short_format
from artiq.gui.tools import DictSyncModel
from artiq.gui.displays import * from artiq.gui.displays import *

View File

@ -2,41 +2,6 @@ from quamash import QtCore
import numpy as np import numpy as np
def elide(s, maxlen):
elided = False
if len(s) > maxlen:
s = s[:maxlen]
elided = True
try:
idx = s.index("\n")
except ValueError:
pass
else:
s = s[:idx]
elided = True
if elided:
maxlen -= 3
if len(s) > maxlen:
s = s[:maxlen]
s += "..."
return s
def short_format(v):
if v is None:
return "None"
t = type(v)
if np.issubdtype(t, int) or np.issubdtype(t, float):
return str(v)
elif t is str:
return "\"" + elide(v, 15) + "\""
else:
r = t.__name__
if t is list or t is dict or t is set:
r += " ({})".format(len(v))
return r
def si_prefix(scale): def si_prefix(scale):
try: try:
return { return {

View File

@ -23,6 +23,41 @@ def parse_arguments(arguments):
return d return d
def elide(s, maxlen):
elided = False
if len(s) > maxlen:
s = s[:maxlen]
elided = True
try:
idx = s.index("\n")
except ValueError:
pass
else:
s = s[:idx]
elided = True
if elided:
maxlen -= 3
if len(s) > maxlen:
s = s[:maxlen]
s += "..."
return s
def short_format(v):
if v is None:
return "None"
t = type(v)
if np.issubdtype(t, int) or np.issubdtype(t, float):
return str(v)
elif t is str:
return "\"" + elide(v, 15) + "\""
else:
r = t.__name__
if t is list or t is dict or t is set:
r += " ({})".format(len(v))
return r
def file_import(filename): def file_import(filename):
linecache.checkcache(filename) linecache.checkcache(filename)