Skip to content

Commit

Permalink
FEATURE: close bitmask window when out-of-focus
Browse files Browse the repository at this point in the history
So that users do not need to close the window, just click outside of it
  • Loading branch information
amilcarlucas committed Jan 19, 2025
1 parent a2ca7ff commit 530b30e
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ def __create_new_value_entry( # pylint: disable=too-many-arguments, too-many-po
new_value_entry.bind(
"<FocusIn>", 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 @@ -417,6 +425,13 @@ def on_close() -> None:
"<FocusIn>", lambda event: self.__open_bitmask_selection_window(event, param_name, bitmask_dict, old_value)
)

def is_widget_visible(widget: tk.Misc | None) -> bool:
return bool(widget and widget.winfo_ismapped())

def focus_out_handler(_event: tk.Event) -> None:
if not is_widget_visible(window.focus_get()):
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 Down Expand Up @@ -452,6 +467,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 530b30e

Please sign in to comment.