store update callback; also remove update callback when removing plot
This commit is contained in:
1
actor.py
1
actor.py
@@ -55,6 +55,7 @@ class Actor:
|
||||
|
||||
def __init__(self, pvname, cache_size=100):
|
||||
self.src, self.plt, self.cache, self._update = decide_src_plt_cache(pvname)
|
||||
self.cb = None
|
||||
|
||||
def update(self):
|
||||
self._update(self.plt, self.cache)
|
||||
|
||||
35
director.py
35
director.py
@@ -43,24 +43,35 @@ class Director:
|
||||
print("caught:", type(e), e)
|
||||
return
|
||||
|
||||
def add_header_widgets(fig):
|
||||
btn = Button(label="🗙", button_type="light", width=35)
|
||||
lbl_width = fig.width - btn.width
|
||||
lbl = Div(text=fig.name, align="center", style={"font-size": "150%"}, width=lbl_width)
|
||||
res = column(row(btn, lbl), fig, Spacer(height=35))
|
||||
btn.on_click(lambda: self.remove_plot(res))
|
||||
return res
|
||||
self.frame(a)
|
||||
self.add_plot(a)
|
||||
|
||||
|
||||
def frame(self, a):
|
||||
fig = a.plt.fig
|
||||
btn = Button(label="🗙", button_type="light", width=35)
|
||||
lbl_width = fig.width - btn.width
|
||||
lbl = Div(text=fig.name, align="center", style={"font-size": "150%"}, width=lbl_width)
|
||||
framed_fig = column(row(btn, lbl), fig, Spacer(height=35))
|
||||
btn.on_click(lambda: self.remove_plot(a))
|
||||
a.plt.fig = framed_fig
|
||||
|
||||
|
||||
def add_plot(self, a):
|
||||
print("Add plot:", a)
|
||||
fig = a.plt.fig
|
||||
fig = add_header_widgets(fig)
|
||||
# self.layout.children.append(fig)
|
||||
self.layout.children.insert(1, fig) # 1 to skip TextInput
|
||||
self.doc.add_periodic_callback(a.update, 1000)
|
||||
assert a.cb is None #TODO
|
||||
a.cb = self.doc.add_periodic_callback(a.update, 1000)
|
||||
|
||||
|
||||
def remove_plot(self, which):
|
||||
print("Remove plot:", which)
|
||||
self.layout.children.remove(which)
|
||||
def remove_plot(self, a):
|
||||
print("Remove plot:", a)
|
||||
fig = a.plt.fig
|
||||
self.layout.children.remove(fig)
|
||||
assert a.cb is not None #TODO
|
||||
self.doc.remove_periodic_callback(a.cb)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user