better names

This commit is contained in:
2021-05-30 18:39:50 +02:00
parent 66bf36b7bd
commit ec871bbc65
+26 -30
View File
@@ -13,12 +13,12 @@ class Director:
self.doc = doc = curdoc()
doc.title = choice("👺👹") + " kabuki"
self.ti_add_pv = ti_add_pv = TextInput(value="", title="Add PV:")
ti_add_pv.on_change("value", self.on_add_pv)
self.ti_add_pvs = ti_add_pvs = TextInput(value="", title="Add PV:")
ti_add_pvs.on_change("value", self.on_add_pvs)
self.plot_container = plot_container = column()
layout = column(ti_add_pv, plot_container)
doc.add_root(layout)
root_container = column(ti_add_pvs, plot_container)
doc.add_root(root_container)
self.updates = []
self.doc.add_periodic_callback(self.periodic_update, 1000)
@@ -29,49 +29,47 @@ class Director:
func()
def on_add_pv(self, attr, old, new):
def on_add_pvs(self, attr, old, new):
if not new: return
self.ti_add_pv.value = ""
self.ti_add_pvs.value = ""
print(f"CB Add PV: attribute \"{attr}\" changed from \"{old}\" to \"{new}\"")
new = break_apart(new)
print(assemble(new))
self.add_pvs(new)
grid = break_apart(new)
print(normalized_string(grid))
self.add_pvs(grid)
def add_pvs(self, pvnames):
for line in reversed(pvnames):
figs_row = self.make_pvs_row(reversed(line))
self.plot_container.children.insert(0, figs_row)
def add_pvs(self, pvnames_grid):
for pvnames in reversed(pvnames_grid):
pvs_row = self.make_pvs_row(pvnames)
self.plot_container.children.insert(0, pvs_row)
def make_pvs_row(self, pvnames):
figs_row = row()
container = row()
for n in pvnames:
print("Add PV:", n)
try:
a = Actor(figs_row, n)
a = Actor(container, n)
except Exception as e:
print("caught:", type(e), e)
tn = type(e).__name__
print(f"failed due to: {tn}: {e}")
else:
def make_remover(x): #TODO: fix this
return lambda: self.remove_plot(x)
return lambda: self.remove_actor(x)
a.plt.on_click_close(make_remover(a))
self.add_plot(a)
return figs_row
self.add_actor(a)
return container
def add_plot(self, a):
def add_actor(self, a):
print("Add plot:", a)
fig = a.plt.fig
# a.container.children.append(fig)
a.container.children.insert(0, fig)
a.container.children.append(a.plt.fig)
self.updates.append(a.update)
def remove_plot(self, a):
def remove_actor(self, a):
print("Remove plot:", a)
fig = a.plt.fig
a.container.children.remove(fig) #TODO: remove container if emptied?
a.container.children.remove(a.plt.fig) #TODO: remove container if emptied?
self.updates.remove(a.update)
@@ -89,10 +87,8 @@ def break_apart(s):
res = [i.split() for i in lines]
return res
def assemble(lst):
return "; ".join(", ".join(line) for line in lst)
def normalized_string(grid):
return "; ".join(", ".join(names) for names in grid)