merge individual periodic callbacks (one for each plot) to one periodic callback

This commit is contained in:
2021-05-29 18:53:24 +02:00
parent 70b64ab622
commit bd9d760812
2 changed files with 15 additions and 5 deletions
+1 -1
View File
@@ -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)
+14 -4
View File
@@ -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)