from cacher import cacher 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(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.fig.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, pvname, cache_size=100): self.src, self.plt, self.cache, self._update = decide_src_plt_cache(pvname) def update(self): self._update(self.plt, self.cache)