|
18 | 18 | from logging import basicConfig as logging_basicConfig
|
19 | 19 | from logging import getLevelName as logging_getLevelName
|
20 | 20 | from tkinter import ttk
|
21 |
| -from typing import Callable, Optional, Union |
| 21 | +from typing import Optional, Union |
22 | 22 |
|
23 | 23 | from ardupilot_methodic_configurator import _, __version__
|
24 | 24 | from ardupilot_methodic_configurator.backend_filesystem import LocalFilesystem
|
@@ -94,20 +94,6 @@ def set_mcu_series(self, mcu: str) -> None:
|
94 | 94 | if mcu.upper() in ("STM32F4XX", "STM32F7XX", "STM32H7XX"):
|
95 | 95 | self.data_model.schema.modify_schema_for_mcu_series(is_optional=True)
|
96 | 96 |
|
97 |
| - def set_vehicle_configuration_template(self, configuration_template: str) -> None: |
98 |
| - """Set the configuration template name in the data.""" |
99 |
| - self.data_model.set_configuration_template(configuration_template) |
100 |
| - |
101 |
| - def set_values_from_fc_parameters(self, fc_parameters: dict, doc: dict) -> None: |
102 |
| - """ |
103 |
| - Process flight controller parameters and update the data model. |
104 |
| -
|
105 |
| - This delegates to the data model's process_fc_parameters method to handle |
106 |
| - all the business logic of processing parameters. |
107 |
| - """ |
108 |
| - # Delegate to the data model for parameter processing |
109 |
| - self.data_model.process_fc_parameters(fc_parameters, doc) |
110 |
| - |
111 | 97 | def update_component_protocol_combobox_entries(self, component_path: ComponentPath, connection_type: str) -> str:
|
112 | 98 | """Updates the Protocol combobox entries based on the selected component connection Type."""
|
113 | 99 | self.data_model.set_component_value(component_path, connection_type)
|
@@ -183,12 +169,15 @@ def add_entry_or_combobox(
|
183 | 169 | # Determine foreground color based on is_optional flag
|
184 | 170 | fg_color = "gray" if is_optional else "black"
|
185 | 171 |
|
| 172 | + def on_validate_combobox(event: tk.Event) -> bool: |
| 173 | + return self._validate_combobox(event, path) |
| 174 | + |
186 | 175 | if combobox_values:
|
187 | 176 | cb = ttk.Combobox(entry_frame, values=combobox_values, foreground=fg_color)
|
188 |
| - cb.bind("<FocusOut>", lambda event, path=path: self._validate_combobox(event, path)) # type: ignore[misc] |
189 |
| - cb.bind("<KeyRelease>", lambda event, path=path: self._validate_combobox(event, path)) # type: ignore[misc] |
190 |
| - cb.bind("<Return>", lambda event, path=path: self._validate_combobox(event, path)) # type: ignore[misc] |
191 |
| - cb.bind("<ButtonRelease>", lambda event, path=path: self._validate_combobox(event, path)) # type: ignore[misc] |
| 177 | + cb.bind("<FocusOut>", on_validate_combobox) |
| 178 | + cb.bind("<KeyRelease>", on_validate_combobox) |
| 179 | + cb.bind("<Return>", on_validate_combobox) |
| 180 | + cb.bind("<ButtonRelease>", on_validate_combobox) |
192 | 181 |
|
193 | 182 | # Prevent mouse wheel from changing value when dropdown is not open
|
194 | 183 | def handle_mousewheel(_event: tk.Event, widget: tk.Widget = cb) -> Optional[str]:
|
@@ -237,18 +226,15 @@ def dropdown_closed(_event: tk.Event, widget: tk.Widget = cb) -> None:
|
237 | 226 | return cb
|
238 | 227 |
|
239 | 228 | entry = ttk.Entry(entry_frame, foreground=fg_color)
|
240 |
| - update_if_valid_function = self.get_validate_function(entry, path) |
241 |
| - entry.bind("<FocusOut>", update_if_valid_function) |
242 |
| - entry.bind("<KeyRelease>", update_if_valid_function) |
243 |
| - entry.bind("<Return>", update_if_valid_function) |
244 |
| - entry.insert(0, str(value)) |
245 |
| - return entry |
246 | 229 |
|
247 |
| - def get_validate_function(self, entry: ttk.Entry, path: ComponentPath) -> Union[Callable[[tk.Event], object], None]: |
248 |
| - def validate_limits(event: tk.Event) -> bool: |
249 |
| - return self.validate_entry_limits_ui(event, entry, path) |
| 230 | + def on_validate_entry_limits_ui(event: tk.Event) -> bool: |
| 231 | + return self._validate_entry_limits_ui(event, entry, path) |
250 | 232 |
|
251 |
| - return validate_limits |
| 233 | + entry.bind("<FocusOut>", on_validate_entry_limits_ui) |
| 234 | + entry.bind("<KeyRelease>", on_validate_entry_limits_ui) |
| 235 | + entry.bind("<Return>", on_validate_entry_limits_ui) |
| 236 | + entry.insert(0, str(value)) |
| 237 | + return entry |
252 | 238 |
|
253 | 239 | def _validate_combobox(self, event: tk.Event, path: ComponentPath) -> bool:
|
254 | 240 | """Validates the value of a combobox."""
|
@@ -285,7 +271,7 @@ def _validate_combobox(self, event: tk.Event, path: ComponentPath) -> bool:
|
285 | 271 | combobox.configure(style="comb_input_valid.TCombobox")
|
286 | 272 | return True
|
287 | 273 |
|
288 |
| - def validate_entry_limits_ui(self, event: Union[None, tk.Event], entry: ttk.Entry, path: ComponentPath) -> bool: |
| 274 | + def _validate_entry_limits_ui(self, event: Union[None, tk.Event], entry: ttk.Entry, path: ComponentPath) -> bool: |
289 | 275 | """UI wrapper for entry limits validation."""
|
290 | 276 | is_focusout_event = event and event.type in {
|
291 | 277 | tk.EventType.FocusOut,
|
|
0 commit comments