made image_threshold an enforced setting, transfer value to threshold if useful; add missing settings as None

This commit is contained in:
gac-maloja
2021-09-30 11:06:24 +02:00
parent 2df1aa9c3f
commit 2ecd9b3e90

26
scam.py
View File

@ -9,14 +9,15 @@ clargs = parser.parse_args()
SHOWN_SETTINGS = { SHOWN_SETTINGS = {
"image_background": "Background", "image_background": "Background",
"image_threshold": "image_threshold", "threshold": "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 = [ ENFORCED_SETTINGS = [
"image_background_enable" "image_background_enable",
"image_threshold"
] ]
@ -111,6 +112,9 @@ class MainPanel(wx.Panel):
self.entries.update(cfg) self.entries.update(cfg)
else: else:
filtered_cfg = {k: v for k, v in cfg.items() if k in SHOWN_SETTINGS} filtered_cfg = {k: v for k, v in cfg.items() if k in SHOWN_SETTINGS}
for k in SHOWN_SETTINGS:
if k not in filtered_cfg:
filtered_cfg[k] = None
self.entries.update(filtered_cfg, SHOWN_SETTINGS) self.entries.update(filtered_cfg, SHOWN_SETTINGS)
self._adjust_size() self._adjust_size()
@ -153,16 +157,32 @@ class MainPanel(wx.Panel):
def check_incoming_cfg(cfg): def check_incoming_cfg(cfg):
bkg_enable = cfg.get("image_background_enable") bkg_enable = cfg.get("image_background_enable")
if bkg_enable not in (None, "passive"): if bkg_enable not in (None, "passive"):
printable_bkg_enable = repr(bkg_enable).replace("'", '"') printable_bkg_enable = printable(bkg_enable)
print(f"Warning: found: image_background_enable = {printable_bkg_enable}, this will be set to None or \"passive\" upon saving") print(f"Warning: found: image_background_enable = {printable_bkg_enable}, this will be set to None or \"passive\" upon saving")
img_thresh = cfg.get("image_threshold")
if img_thresh is not None:
printable_img_thresh = printable(img_thresh)
print(f"Warning: found: image_threshold = {printable_img_thresh}, this will be set to None upon saving")
thresh = cfg.get("threshold")
if thresh is None:
print(f"Warning: found: threshold = None, will overwrite with value of image_threshold ({printable_img_thresh})")
def check_outgoing_cfg(cfg): def check_outgoing_cfg(cfg):
bkg = cfg["image_background"] bkg = cfg["image_background"]
cfg["image_background_enable"] = "passive" if bkg else None cfg["image_background_enable"] = "passive" if bkg else None
cfg["image_threshold"] = None
return cfg return cfg
def printable(val):
return repr(val).replace("'", '"')