merge individual periodic callbacks (one for each plot) to one periodic callback
This commit is contained in:
@@ -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
@@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user