made image_background_enable an enforced setting

This commit is contained in:
gac-maloja
2021-09-30 10:47:21 +02:00
parent 15233e68f6
commit 2df1aa9c3f

46
scam.py
View File

@ -9,13 +9,16 @@ clargs = parser.parse_args()
SHOWN_SETTINGS = { SHOWN_SETTINGS = {
"image_background": "Background", "image_background": "Background",
"image_background_enable": "image_background_enable",
"image_threshold": "image_threshold", "image_threshold": "image_threshold",
"project_axis": "Projection axis", "project_axis": "Projection axis",
"roi_background": "ROI Background", "roi_background": "ROI Background",
"roi_signal": "ROI Signal" "roi_signal": "ROI Signal"
} }
ENFORCED_SETTINGS = [
"image_background_enable"
]
import wx import wx
@ -94,7 +97,12 @@ class MainPanel(wx.Panel):
cfg = pc.get_instance_config(instance) cfg = pc.get_instance_config(instance)
print(cfg) print(cfg)
self.orig_cfg = cfg
self.camera = cfg["camera_name"] self.camera = cfg["camera_name"]
if not clargs.show_all_settings:
check_incoming_cfg(cfg)
self.eb_bkg.Enable() self.eb_bkg.Enable()
self.btn_print.Enable() self.btn_print.Enable()
self.btn_save.Enable() self.btn_save.Enable()
@ -114,24 +122,48 @@ class MainPanel(wx.Panel):
parent.Fit() parent.Fit()
def on_print(self, event): def make_cfg(self):
new_cfg = self.entries.get() cfg = self.entries.get()
print(new_cfg)
old_cfg = pc.get_instance_config(self.instance)
if not clargs.show_all_settings: if not clargs.show_all_settings:
old_cfg = {k: v for k, v in old_cfg.items() if k in SHOWN_SETTINGS} cfg = check_outgoing_cfg(cfg)
return cfg
def on_print(self, event):
new_cfg = self.make_cfg()
old_cfg = self.orig_cfg
if not clargs.show_all_settings:
old_cfg = {k: v for k, v in old_cfg.items() if k in list(SHOWN_SETTINGS) + ENFORCED_SETTINGS}
print("old config:", old_cfg)
print("new config:", new_cfg)
print("unchanged" if old_cfg == new_cfg else "changed") print("unchanged" if old_cfg == new_cfg else "changed")
def on_save_cfg(self, event): def on_save_cfg(self, event):
new_cfg = self.entries.get() new_cfg = self.make_cfg()
res = pc.set_instance_config(self.instance, new_cfg) res = pc.set_instance_config(self.instance, new_cfg)
print(res) print(res)
def check_incoming_cfg(cfg):
bkg_enable = cfg.get("image_background_enable")
if bkg_enable not in (None, "passive"):
printable_bkg_enable = repr(bkg_enable).replace("'", '"')
print(f"Warning: found: image_background_enable = {printable_bkg_enable}, this will be set to None or \"passive\" upon saving")
def check_outgoing_cfg(cfg):
bkg = cfg["image_background"]
cfg["image_background_enable"] = "passive" if bkg else None
return cfg
app = wx.App() app = wx.App()