Skip to content

Commit

Permalink
FEATURE: add generic component editor entry limits validation function
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Jun 13, 2024
1 parent 1a50c65 commit 0d88d13
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions MethodicConfigurator/frontend_tkinter_component_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,20 @@ def validate_combobox(self, event, path) -> bool:
combobox.configure(style="comb_input_valid.TCombobox")
return True

def validate_entry_limits(self, event, entry, data_type, limits, name, path): # pylint: disable=too-many-arguments
is_focusout_event = event and event.type == "10"
try:
value = data_type(entry.get())
if value < limits[0] or value > limits[1]:
entry.configure(style="entry_input_invalid.TEntry")
raise ValueError(f"{name} must be a {data_type.__name__} between {limits[0]} and {limits[1]}")
except ValueError as e:
if is_focusout_event:
show_error_message("Error", f"Invalid value '{value}' for {'>'.join(list(path))}\n{e}")
return False
entry.configure(style="entry_input_valid.TEntry")
return True

def validate_takeoff_weight(self, event, entry, path):
is_focusout_event = event and event.type == "10"
try:
Expand Down

0 comments on commit 0d88d13

Please sign in to comment.