Skip to content

Commit

Permalink
gui_settings.py: Add error handling for invalid value
Browse files Browse the repository at this point in the history
  • Loading branch information
khronokernel committed Oct 31, 2024
1 parent 868cfa6 commit 737aed5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion opencore_legacy_patcher/wx_gui/gui_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,16 @@ def _generate_elements(self, frame: wx.Frame = None) -> None:
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)
Expand Down

0 comments on commit 737aed5

Please sign in to comment.