From 22bffa98b5da846b35c5cfe84b084c5fd822b513 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 12 Oct 2015 18:10:58 +0800 Subject: [PATCH] client: use short_format in dataset display --- artiq/frontend/artiq_client.py | 3 ++- artiq/gui/datasets.py | 3 ++- artiq/gui/tools.py | 35 ---------------------------------- artiq/tools.py | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/artiq/frontend/artiq_client.py b/artiq/frontend/artiq_client.py index b1bdd2bf3..2f8995482 100755 --- a/artiq/frontend/artiq_client.py +++ b/artiq/frontend/artiq_client.py @@ -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) diff --git a/artiq/gui/datasets.py b/artiq/gui/datasets.py index d951143d3..ebe8d295c 100644 --- a/artiq/gui/datasets.py +++ b/artiq/gui/datasets.py @@ -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 * diff --git a/artiq/gui/tools.py b/artiq/gui/tools.py index 265a46491..242c66600 100644 --- a/artiq/gui/tools.py +++ b/artiq/gui/tools.py @@ -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 { diff --git a/artiq/tools.py b/artiq/tools.py index 56ae0fda1..7505081f8 100644 --- a/artiq/tools.py +++ b/artiq/tools.py @@ -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)