|
16 | 16 | from platform import system as platform_system |
17 | 17 | from sys import exit as sys_exit |
18 | 18 | from tkinter import messagebox, ttk |
19 | | -from typing import Optional, Union |
| 19 | +from typing import Union |
20 | 20 |
|
21 | 21 | from ardupilot_methodic_configurator import _ |
22 | 22 | from ardupilot_methodic_configurator.annotate_params import Par |
|
30 | 30 | from ardupilot_methodic_configurator.data_model_configuration_step import ConfigurationStepProcessor |
31 | 31 | from ardupilot_methodic_configurator.frontend_tkinter_base_window import BaseWindow |
32 | 32 | from ardupilot_methodic_configurator.frontend_tkinter_entry_dynamic import EntryWithDynamicalyFilteredListbox |
33 | | -from ardupilot_methodic_configurator.frontend_tkinter_pair_tuple_combobox import PairTupleCombobox |
| 33 | +from ardupilot_methodic_configurator.frontend_tkinter_pair_tuple_combobox import ( |
| 34 | + PairTupleCombobox, |
| 35 | + setup_combobox_mousewheel_handling, |
| 36 | +) |
34 | 37 | from ardupilot_methodic_configurator.frontend_tkinter_rich_text import get_widget_font_family_and_size |
35 | 38 | from ardupilot_methodic_configurator.frontend_tkinter_scroll_frame import ScrollFrame |
36 | 39 | from ardupilot_methodic_configurator.frontend_tkinter_show import show_tooltip |
@@ -358,37 +361,6 @@ def _update_combobox_style_on_selection( # pylint: disable=too-many-arguments, |
358 | 361 | event.width = NEW_VALUE_WIDGET_WIDTH |
359 | 362 | combobox_widget.on_combo_configure(event) |
360 | 363 |
|
361 | | - def _setup_combobox_mousewheel_handling(self, combobox: PairTupleCombobox) -> None: |
362 | | - """Set up mouse wheel handling for combobox to prevent unwanted value changes.""" |
363 | | - |
364 | | - # Prevent mouse wheel from changing value when dropdown is not open |
365 | | - def handle_mousewheel(_event: tk.Event, widget: tk.Widget = combobox) -> Optional[str]: |
366 | | - # Check if dropdown is open by examining the combobox's state |
367 | | - dropdown_is_open = getattr(widget, "dropdown_is_open", False) |
368 | | - if not dropdown_is_open: |
369 | | - widget.master.event_generate("<MouseWheel>", delta=_event.delta) |
370 | | - return "break" # Prevent default behavior |
371 | | - return None # Allow default behavior when dropdown is open |
372 | | - |
373 | | - # Set flag when dropdown opens or closes |
374 | | - def dropdown_opened(_event: tk.Event, widget: tk.Widget = combobox) -> None: |
375 | | - widget.dropdown_is_open = True # type: ignore[attr-defined] |
376 | | - |
377 | | - def dropdown_closed(_event: tk.Event, widget: tk.Widget = combobox) -> None: |
378 | | - widget.dropdown_is_open = False # type: ignore[attr-defined] |
379 | | - |
380 | | - # Initialize the flag |
381 | | - combobox.dropdown_is_open = False # type: ignore[attr-defined] |
382 | | - |
383 | | - # Bind to events for dropdown opening and closing |
384 | | - combobox.bind("<<ComboboxDropdown>>", dropdown_opened) |
385 | | - combobox.bind("<FocusOut>", dropdown_closed, "+") |
386 | | - |
387 | | - # Bind mouse wheel events |
388 | | - combobox.bind("<MouseWheel>", handle_mousewheel) # Windows mouse wheel |
389 | | - combobox.bind("<Button-4>", handle_mousewheel) # Linux mouse wheel up |
390 | | - combobox.bind("<Button-5>", handle_mousewheel) # Linux mouse wheel down |
391 | | - |
392 | 364 | @staticmethod |
393 | 365 | def _update_new_value_entry_text(new_value_entry: ttk.Entry, param: ArduPilotParameter) -> None: |
394 | 366 | """Update the new value entry text and style.""" |
@@ -442,7 +414,7 @@ def _create_new_value_entry( # pylint: disable=too-many-statements # noqa: PLR0 |
442 | 414 | ) |
443 | 415 |
|
444 | 416 | # Set up mouse wheel handling to prevent unwanted value changes |
445 | | - self._setup_combobox_mousewheel_handling(new_value_entry) |
| 417 | + setup_combobox_mousewheel_handling(new_value_entry) |
446 | 418 | else: |
447 | 419 | new_value_entry = ttk.Entry(self.view_port, width=NEW_VALUE_WIDGET_WIDTH + 1, justify=tk.RIGHT) |
448 | 420 | self._update_new_value_entry_text(new_value_entry, param) |
|
0 commit comments