Skip to content

Commit

Permalink
FEATURE: allow editing bitmask values numerically
Browse files Browse the repository at this point in the history
It now requires a double-click to open the bitmask editing window
  • Loading branch information
amilcarlucas committed Jan 17, 2025
1 parent 4eea884 commit 0920348
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,17 @@ def __create_new_value_entry( # pylint: disable=too-many-arguments, too-many-po
new_value_entry.config(state="disabled", background="light grey")
elif bitmask_dict:
new_value_entry.bind(
"<FocusIn>", lambda event: self.__open_bitmask_selection_window(event, param_name, bitmask_dict, old_value)
"<Double-Button>",
lambda event: self.__open_bitmask_selection_window(event, param_name, bitmask_dict, old_value),
)
# pylint: disable=line-too-long
new_value_entry.bind(
"<FocusOut>",
lambda event, current_file=self.current_file, param_name=param_name: self.__on_parameter_value_change( # type: ignore[misc]
event, current_file, param_name
),
)
# pylint: enable=line-too-long
else:
# pylint: disable=line-too-long
new_value_entry.bind(
Expand Down Expand Up @@ -414,9 +423,14 @@ def on_close() -> None:
self.root.update_idletasks()
# Re-bind the FocusIn event to new_value_entry
event.widget.bind(
"<FocusIn>", lambda event: self.__open_bitmask_selection_window(event, param_name, bitmask_dict, old_value)
"<Double-Button>",
lambda event: self.__open_bitmask_selection_window(event, param_name, bitmask_dict, old_value),
)

def focus_out_handler(event: tk.Event) -> None:

Check failure on line 430 in ardupilot_methodic_configurator/frontend_tkinter_parameter_editor_table.py

View workflow job for this annotation

GitHub Actions / ruff (py39)

Ruff (ARG001)

ardupilot_methodic_configurator/frontend_tkinter_parameter_editor_table.py:430:31: ARG001 Unused function argument: `event`
if not window.focus_get() or not window.focus_get().winfo_ismapped():

Check failure on line 431 in ardupilot_methodic_configurator/frontend_tkinter_parameter_editor_table.py

View workflow job for this annotation

GitHub Actions / mypy

ardupilot_methodic_configurator/frontend_tkinter_parameter_editor_table.py#L431

[error] Item
on_close()

def get_param_value_msg(_param_name: str, checked_keys: set) -> str:
_new_decimal_value = sum(1 << key for key in checked_keys)
text = _("{_param_name} Value: {_new_decimal_value}")
Expand All @@ -427,7 +441,7 @@ def update_label() -> None:
close_label.config(text=get_param_value_msg(param_name, checked_keys))

# Temporarily unbind the FocusIn event to prevent triggering the window again
event.widget.unbind("<FocusIn>")
event.widget.unbind("<Double-Button>")
window = tk.Toplevel(self.root)
title = _("Select {param_name} Bitmask Options")
window.title(title.format(**locals()))
Expand All @@ -452,6 +466,9 @@ def update_label() -> None:

# Bind the on_close function to the window's WM_DELETE_WINDOW protocol
window.protocol("WM_DELETE_WINDOW", on_close)
window.bind("<FocusOut>", focus_out_handler)
for child in window.winfo_children():
child.bind("<FocusOut>", focus_out_handler)

# Make sure the window is visible before disabling the parent window
window.deiconify()
Expand Down

0 comments on commit 0920348

Please sign in to comment.