Files
kabuki/actor.py

80 lines
1.9 KiB
Python

from cacher import cacher
from frame import Frame
from plots import Plot0D, Plot1D, Plot2D
from sources import Camera, Source
def update_all(plt, cache):
plt.set(*cache.xy)
#def update_latest(plt, cache):
# plt.set(cache.latest)
def decide_src_plt_cache_update(pvname):
pvname = pvname.upper()
if pvname.endswith(":FPICTURE"):
print("Camera", pvname)
src = Camera(pvname)
plt = Plot2D
cache_size = 1
update = update_all
if not src.is_connected:
raise RuntimeError(f"{pvname} is not connected")
else:
print("Source", pvname)
src = Source(pvname)
if not src.is_connected:
raise RuntimeError(f"{pvname} is not connected")
print(src.nelm)
if src.nelm == 0:
raise RuntimeError(f"{src}: {src.value}")
cache_size = 100
update = update_all
if src.nelm == 1:
print("Scalar")
plt = Plot0D
else:
print("Curve")
plt = Plot1D
plt = plt(name=pvname)
cache = cacher.add_source(src, size=cache_size)
return src, plt, cache, update
class Actor:
def __init__(self, pvname, cache_size=100):
self.pvname = pvname
self.src, plt, cache, self._update = decide_src_plt_cache_update(pvname)
self.cache = cache
self.plt = plt
self.frm = frm = Frame(plt)
self.frm.cfg_ti_cache_size.value = str(cache.size)
self.frm.cfg_ti_cache_size.on_change("value", self.do_update_cache_size)
def do_update_cache_size(self, attr, old, new):
print(f"CB Update cache size: attribute \"{attr}\" changed from \"{old}\" to \"{new}\"")
self.cache.set_size(int(new))
self.frm.cfg_ti_cache_size.value = str(self.cache.size)
def update(self):
self._update(self.plt, self.cache)
def __repr__(self):
return f"Actor: {self.pvname}"