From bd9d760812d569248a9dcffff22141f16a67a16b Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Sat, 29 May 2021 18:53:24 +0200 Subject: [PATCH] merge individual periodic callbacks (one for each plot) to one periodic callback --- actor.py | 2 +- director.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/actor.py b/actor.py index 240a5c6..e788029 100644 --- a/actor.py +++ b/actor.py @@ -57,7 +57,7 @@ class Actor: def __init__(self, pvname, cache_size=100): self.src, plt, self.cache, self._update = decide_src_plt_cache_update(pvname) self.plt = Frame(plt) - self.cb = self.container = None + self.container = None def update(self): self._update(self.plt, self.cache) diff --git a/director.py b/director.py index 4724a2e..8b32158 100644 --- a/director.py +++ b/director.py @@ -20,6 +20,14 @@ class Director: layout = column(ti_add_pv, plot_container) doc.add_root(layout) + self.updates = [] + self.doc.add_periodic_callback(self.periodic_update, 1000) + + + def periodic_update(self): + for func in self.updates: + func() + def on_add_pv(self, attr, old, new): if not new: return @@ -55,16 +63,18 @@ class Director: fig = a.plt.fig # a.container.children.append(fig) a.container.children.insert(0, fig) - assert a.cb is None #TODO - a.cb = self.doc.add_periodic_callback(a.update, 1000) +# assert a.cb is None #TODO +# a.cb = self.doc.add_periodic_callback(a.update, 1000) + self.updates.append(a.update) def remove_plot(self, a): print("Remove plot:", a) fig = a.plt.fig a.container.children.remove(fig) #TODO: remove container if emptied? - assert a.cb is not None #TODO - self.doc.remove_periodic_callback(a.cb) +# assert a.cb is not None #TODO +# self.doc.remove_periodic_callback(a.cb) + self.updates.remove(a.update)