81 lines
2.0 KiB
Python
81 lines
2.0 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_latest
|
|
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}")
|
|
|
|
if src.nelm == 1:
|
|
print("Scalar")
|
|
plt = Plot0D
|
|
cache_size = 100
|
|
update = update_all
|
|
else:
|
|
print("Curve")
|
|
plt = Plot1D
|
|
cache_size = 1
|
|
update = update_latest
|
|
|
|
plt = plt()
|
|
plt.name = plt.layout.name = pvname #TODO this needs to be done in Plot*
|
|
|
|
cache = cacher.add_source(src, size=cache_size)
|
|
|
|
return src, plt, cache, update
|
|
|
|
|
|
|
|
class Actor:
|
|
|
|
def __init__(self, container, pvname, cache_size=100):
|
|
self.container = container
|
|
self.pvname = pvname
|
|
self.src, plt, self.cache, self._update = decide_src_plt_cache_update(pvname)
|
|
self.plt = Frame(plt)
|
|
|
|
self.plt.cfg_ti_cache_size.value = str(self.cache.size)
|
|
self.plt.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.plt.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}"
|
|
|
|
|
|
|