From 38cdeb0a32c39699ea5f2101e244586aa4f4055f Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 10 Jan 2016 22:12:00 +0800 Subject: [PATCH] applets/simple: support mod buffering --- artiq/applets/big_number.py | 2 +- artiq/applets/simple.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/artiq/applets/big_number.py b/artiq/applets/big_number.py index bb26f22ba..7eb60cbcd 100755 --- a/artiq/applets/big_number.py +++ b/artiq/applets/big_number.py @@ -11,7 +11,7 @@ class NumberWidget(QtWidgets.QLCDNumber): self.setDigitCount(args.digit_count) self.dataset_name = args.dataset - def data_changed(self, data, mod): + def data_changed(self, data, mods): try: n = float(data[self.dataset_name][1]) except (KeyError, ValueError, TypeError): diff --git a/artiq/applets/simple.py b/artiq/applets/simple.py index f11f58ca3..93e293267 100644 --- a/artiq/applets/simple.py +++ b/artiq/applets/simple.py @@ -8,10 +8,15 @@ from artiq.protocols.pc_rpc import Client class SimpleApplet: - def __init__(self, main_widget_class, cmd_description=None): + def __init__(self, main_widget_class, cmd_description=None, + default_update_delay=0.0): self.main_widget_class = main_widget_class self.argparser = argparse.ArgumentParser(description=cmd_description) + self.argparser.add_argument("--update-delay", type=float, + default=default_update_delay, + help="time to wait after a mod (buffering other mods) " + "before updating (default: %(default).2f)") group = self.argparser.add_argument_group("data server") group.add_argument( "--server-notify", default="::1", @@ -71,8 +76,20 @@ class SimpleApplet: self.data = data return data + def flush_mod_buffer(self): + self.main_widget.data_changed(self.data, self.mod_buffer) + del self.mod_buffer + def sub_mod(self, mod): - self.main_widget.data_changed(self.data, mod) + if self.args.update_delay: + if hasattr(self, "mod_buffer"): + self.mod_buffer.append(mod) + else: + self.mod_buffer = [mod] + asyncio.get_event_loop().call_later(self.args.update_delay, + self.flush_mod_buffer) + else: + self.main_widget.data_changed(self.data, [mod]) def create_subscriber(self): self.subscriber = Subscriber("datasets",