Skip to content

Commit c5dcf10

Browse files
committed
FEATURE: Implement TOW validation
1 parent dd41bc2 commit c5dcf10

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

MethodicConfigurator/frontend_tkinter_component_editor.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ def add_entry_or_combobox(self, value, entry_frame, path):
218218

219219
entry = ttk.Entry(entry_frame)
220220
entry_config = {
221+
('Frame', 'Specifications', 'TOW min Kg'): {
222+
"type": float,
223+
"validate": lambda event, entry=entry, path=path: self.validate_takeoff_weight(event, entry, path),
224+
},
225+
('Frame', 'Specifications', 'TOW max Kg'): {
226+
"type": float,
227+
"validate": lambda event, entry=entry, path=path: self.validate_takeoff_weight(event, entry, path),
228+
},
221229
('Battery', 'Specifications', 'Volt per cell max'): {
222230
"type": float,
223231
"validate": lambda event, entry=entry, path=path: self.validate_cell_voltage(event, entry, path),
@@ -239,7 +247,7 @@ def add_entry_or_combobox(self, value, entry_frame, path):
239247
"validate": lambda event, entry=entry, path=path: self.validate_motor_poles(event, entry, path),
240248
},
241249
('Propellers', 'Specifications', 'Diameter_inches'): {
242-
"type": int,
250+
"type": float,
243251
"validate": lambda event, entry=entry, path=path: self.validate_propeller(event, entry, path),
244252
},
245253
}
@@ -267,6 +275,20 @@ def validate_combobox(self, event, path) -> bool:
267275
combobox.configure(style="comb_input_valid.TCombobox")
268276
return True
269277

278+
def validate_takeoff_weight(self, event, entry, path):
279+
is_focusout_event = event and event.type == "10"
280+
try:
281+
weight = float(entry.get())
282+
if weight < 0.01 or weight > 600:
283+
entry.configure(style="entry_input_invalid.TEntry")
284+
raise ValueError("Takeoff weight must be a float between 0.01 and 600")
285+
except ValueError as e:
286+
if is_focusout_event:
287+
show_error_message("Error", f"Invalid value '{weight}' for {'>'.join(list(path))}\n{e}")
288+
return False
289+
entry.configure(style="entry_input_valid.TEntry")
290+
return True
291+
270292
def validate_cell_voltage(self, event, entry, path): # pylint: disable=too-many-branches
271293
"""
272294
Validates the value of a battery cell voltage entry.
@@ -393,6 +415,12 @@ def validate_data(self): # pylint: disable=too-many-branches
393415
fc_serial_connection[value] = path[0]
394416
entry.configure(style="comb_input_valid.TCombobox")
395417

418+
if path == ('Frame', 'Specifications', 'TOW min Kg'):
419+
if not self.validate_takeoff_weight(None, entry, path):
420+
invalid_values = True
421+
if path == ('Frame', 'Specifications', 'TOW max Kg'):
422+
if not self.validate_takeoff_weight(None, entry, path):
423+
invalid_values = True
396424
if path in [('Battery', 'Specifications', 'Volt per cell max'), ('Battery', 'Specifications', 'Volt per cell low'),
397425
('Battery', 'Specifications', 'Volt per cell crit')]:
398426
if not self.validate_cell_voltage(None, entry, path):

0 commit comments

Comments
 (0)