added buttons to get current ROI selected in screenpanel and insert for signal or background

This commit is contained in:
gac-maloja
2021-10-02 18:32:18 +02:00
parent 69f76e4832
commit 4c7cb24aa8

62
scam.py
View File

@ -42,7 +42,7 @@ from settings import SettingsList
pc = PipelineClient("http://sf-daqsync-01:8889")
si = pc.get_server_info()
pls = si["active_instances"]
pls = all_pls = si["active_instances"]
if not clargs.show_all_settings:
pls = (i for i in pls if "spec_db" in i)
pls = sorted(pls)
@ -73,6 +73,11 @@ class MainPanel(wx.Panel):
self.eb_bkg = eb_bkg = EntryButton(self, label="Background Images", value=100, button="Record Background")
eb_bkg.Disable()
self.btn_get_roi_bkg = btn_get_roi_bkg = wx.Button(self, label="Get ROI Background from ScreenPanel")
self.btn_get_roi_sig = btn_get_roi_sig = wx.Button(self, label="Get ROI Signal from ScreenPanel")
btn_get_roi_bkg.Disable()
btn_get_roi_sig.Disable()
self.entries = entries = SettingsList(self)
self.btn_print = btn_print = wx.Button(self, label="Print")
@ -83,13 +88,18 @@ class MainPanel(wx.Panel):
cb_pls.Bind(wx.EVT_COMBOBOX, self.on_select)
eb_bkg.button.Bind(wx.EVT_BUTTON, self.on_save_bkg)
btn_get_roi_bkg.Bind(wx.EVT_BUTTON, self.on_get_roi_bkg)
btn_get_roi_sig.Bind(wx.EVT_BUTTON, self.on_get_roi_sig)
btn_print.Bind(wx.EVT_BUTTON, self.on_print)
btn_save.Bind(wx.EVT_BUTTON, self.on_save_cfg)
widgets = [btn_print, btn_save]
btns_sizer = make_filled_hbox(widgets)
widgets = [btn_get_roi_bkg, btn_get_roi_sig]
btns_get_roi = make_filled_vbox(widgets)
widgets = [cb_pls, STRETCH, eb_bkg, STRETCH, entries, btns_sizer]
widgets = [btn_print, btn_save]
btns_bottom = make_filled_hbox(widgets)
widgets = [cb_pls, STRETCH, eb_bkg, btns_get_roi, STRETCH, entries, btns_bottom]
sizer = make_filled_vbox(widgets, border=10)
self.SetSizer(sizer)
@ -129,6 +139,8 @@ class MainPanel(wx.Panel):
bkg_setting.set_value(latest_bkg)
self.eb_bkg.Enable()
self.btn_get_roi_sig.Enable()
self.btn_get_roi_bkg.Enable()
self.btn_print.Enable()
self.btn_save.Enable()
@ -150,6 +162,48 @@ class MainPanel(wx.Panel):
return cfg
def on_get_roi_bkg(self, event):
roi = self._get_roi()
if roi is None:
return
self.entries.set("roi_background", roi)
def on_get_roi_sig(self, event):
roi = self._get_roi()
if roi is None:
return
self.entries.set("roi_signal", roi)
def _get_roi(self):
cam = self.camera
cam_pls = [i for i in all_pls if i.startswith(cam)]
suffices = ("sp", "sp1")
sp_pls = [i for i in cam_pls if i.split("_")[1] in suffices]
if len(sp_pls) == 0:
print("no screenpanel found for camera:", cam)
return None
if len(sp_pls) > 1:
print("several screenpanels found for camera:", cam)
for sp in sp_pls:
print("-", sp)
return None
sp = sp_pls[0]
cfg = pc.get_instance_config(sp)
roi = cfg["image_region_of_interest"]
if roi is None:
print("no roi set in screenpanel:", sp)
return None
xmin, xdelta, ymin, ydelta = roi
xmax = xmin + xdelta
ymax = ymin + ydelta
return xmin, xmax, ymin, ymax
def on_print(self, event):
old_cfg = self.orig_cfg
new_cfg = self.make_cfg()