forked from M-Labs/artiq
client: use short_format in dataset display
This commit is contained in:
parent
e6e93ab6ed
commit
22bffa98b5
@ -12,6 +12,7 @@ from prettytable import PrettyTable
|
||||
from artiq.protocols.pc_rpc import Client
|
||||
from artiq.protocols.sync_struct import Subscriber
|
||||
from artiq.protocols import pyon
|
||||
from artiq.tools import short_format
|
||||
|
||||
|
||||
def clear_screen():
|
||||
@ -192,7 +193,7 @@ def _show_datasets(datasets):
|
||||
clear_screen()
|
||||
table = PrettyTable(["Dataset", "Persistent", "Value"])
|
||||
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)
|
||||
|
||||
|
||||
|
@ -8,7 +8,8 @@ from pyqtgraph import dockarea
|
||||
from pyqtgraph import LayoutWidget
|
||||
|
||||
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 *
|
||||
|
||||
|
||||
|
@ -2,41 +2,6 @@ from quamash import QtCore
|
||||
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):
|
||||
try:
|
||||
return {
|
||||
|
@ -23,6 +23,41 @@ def parse_arguments(arguments):
|
||||
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):
|
||||
linecache.checkcache(filename)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user