Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus handler on a menu doesn't see that the menu has lost focus #2245

Closed
v-ein opened this issue Dec 29, 2023 · 1 comment · Fixed by #2246
Closed

Focus handler on a menu doesn't see that the menu has lost focus #2245

v-ein opened this issue Dec 29, 2023 · 1 comment · Fixed by #2246
Labels
state: pending not addressed yet type: bug bug

Comments

@v-ein
Copy link
Contributor

v-ein commented Dec 29, 2023

Version of Dear PyGui

Version: 1.10.1
Operating System: Windows 10

My Issue/Question

When an item_focus_handler is bound to dpg.menu, it gets called every frame as soon as the menu is activated, which is expected behavior for this handler. What's not expected though, it goes on forever even after the menu has been deactivated. That is, the menu is no longer shown but the handler still gets called every frame. It looks as if the focused state for the menu were not properly reset to False.

An interesting fact, the Item Registry tool does show the menu as "not focused" when it's not active. However, the focus handler gets called even when Item Registry shows "Focused: False").

To Reproduce

Steps to reproduce the behavior:

  1. Bind a focus handler to a menu.
  2. In the handler, print a message (better include frame counter to see that new messages get printed).
  3. Click the menu. Messages from the handler should start popping up in the stdout.
  4. Deactivate the menu, e.g. by clicking somewhere else. You'll see that the focus handler still gets called, even though the menu is no longer focused. You can even focus a different widget - it won't help, there's no way to make the menu "unfocused" again.

Expected behavior

Menus should get back to the unfocused state when they are deactivated.

Screenshots/Video

menu-focus

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

dpg.create_context()

with dpg.window(label="Colored text", width=300, height=200) as wnd:
    with dpg.item_handler_registry() as focus_handlers:
        dpg.add_item_focus_handler(callback=lambda: print(f"[{dpg.get_frame_count()}] Focused"))
    with dpg.menu_bar():
        with dpg.menu(label="Menu"):
            dpg.bind_item_handler_registry(dpg.last_item(), focus_handlers)
            dpg.add_menu_item(label="New")
            dpg.add_menu_item(label="Open")
            dpg.add_menu_item(label="Save")
        with dpg.menu(label="Examples"):
            dpg.add_menu_item(label="Save")


dpg.show_item_registry()
dpg.create_viewport(title='Test', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
@v-ein v-ein added state: pending not addressed yet type: bug bug labels Dec 29, 2023
@v-ein
Copy link
Contributor Author

v-ein commented Dec 29, 2023

As usual, I've got a fix for this issue :). Going to push a bit later.

v-ein added a commit to v-ein/DearPyGui-fixes that referenced this issue Dec 30, 2023
Also, restored indentation in draw_menu() - it's much easier to read now.
hoffstadt pushed a commit that referenced this issue Jan 6, 2024
Also, restored indentation in draw_menu() - it's much easier to read now.
v-ein added a commit to v-ein/DearPyGui-fixes that referenced this issue Jan 10, 2024
SamuMazzi pushed a commit to SamuMazzi/DearPyGui that referenced this issue Jan 31, 2024
Also, restored indentation in draw_menu() - it's much easier to read now.
SamuMazzi pushed a commit to SamuMazzi/DearPyGui that referenced this issue Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: pending not addressed yet type: bug bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant