gui_settings.py: Add error handling for invalid value

This commit is contained in:
Mykola Grymalyuk
2024-10-31 16:03:44 -06:00
parent 868cfa62c1
commit 737aed5635

View File

@@ -158,7 +158,16 @@ class SettingsFrame(wx.Frame):
if setting_info["type"] == "checkbox":
# Add checkbox, and description underneath
checkbox = wx.CheckBox(panel, label=setting, pos=(10 + width, 10 + height), size = (300,-1))
checkbox.SetValue(setting_info["value"] if setting_info["value"] else False)
value = False
if "value" in setting_info:
try:
value = bool(setting_info["value"])
except ValueError:
logging.error(f"Invalid value for {setting}, got {setting_info['value']} (type: {type(setting_info['value'])})")
value = False
checkbox.SetValue(value)
checkbox.SetFont(gui_support.font_factory(13, wx.FONTWEIGHT_BOLD))
event = lambda event, warning=setting_info["warning"] if "warning" in setting_info else "", override=bool(setting_info["override_function"]) if "override_function" in setting_info else False: self.on_checkbox(event, warning, override)
checkbox.Bind(wx.EVT_CHECKBOX, event)