Skip to content

Commit 0d88d13

Browse files
committed
FEATURE: add generic component editor entry limits validation function
1 parent 1a50c65 commit 0d88d13

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

MethodicConfigurator/frontend_tkinter_component_editor.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,20 @@ def validate_combobox(self, event, path) -> bool:
275275
combobox.configure(style="comb_input_valid.TCombobox")
276276
return True
277277

278+
def validate_entry_limits(self, event, entry, data_type, limits, name, path): # pylint: disable=too-many-arguments
279+
is_focusout_event = event and event.type == "10"
280+
try:
281+
value = data_type(entry.get())
282+
if value < limits[0] or value > limits[1]:
283+
entry.configure(style="entry_input_invalid.TEntry")
284+
raise ValueError(f"{name} must be a {data_type.__name__} between {limits[0]} and {limits[1]}")
285+
except ValueError as e:
286+
if is_focusout_event:
287+
show_error_message("Error", f"Invalid value '{value}' for {'>'.join(list(path))}\n{e}")
288+
return False
289+
entry.configure(style="entry_input_valid.TEntry")
290+
return True
291+
278292
def validate_takeoff_weight(self, event, entry, path):
279293
is_focusout_event = event and event.type == "10"
280294
try:

0 commit comments

Comments
 (0)