-
Notifications
You must be signed in to change notification settings - Fork 40
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
feature added: update of menu options #18
base: develop
Are you sure you want to change the base?
Conversation
src/infi/systray/traybar.py
Outdated
if icon: | ||
self._icon = icon | ||
self._load_icon() | ||
if hover_text: | ||
self._hover_text = hover_text | ||
# "if menu_options" added to be allow the update of the menu options | ||
if menu_options: | ||
menu_options = menu_options or () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this line, since we are already checking if menu_options is not empty in the line above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I removed it!
src/infi/systray/traybar.py
Outdated
@@ -122,15 +122,25 @@ def shutdown(self): | |||
PostMessage(self._hwnd, WM_CLOSE, 0, 0) | |||
self._message_loop_thread.join() | |||
|
|||
def update(self, icon=None, hover_text=None): | |||
""" update icon image and/or hover text """ | |||
def update(self, icon=None, hover_text=None, menu_options=None): # "menu_options=None" added to be allow the update of the menu options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the comment. It's making the line too long and it isn't necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
self._menu_actions_by_id = set() | ||
self._menu_options = self._add_ids_to_menu_options(list(menu_options)) | ||
self._menu_actions_by_id = dict(self._menu_actions_by_id) | ||
self._menu = None # detroy the old menu created by right clicking the icon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm afraid of here is that we're not freeing the previous menu (and submenus and icons, maybe?), potentially causing resource leaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible but I don't know how to prevent this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would DestroyMenu
do the trick?
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-destroymenu
You'll probably have to add an alias for it in win32_adapter.py
but I managed to get this working by doing:
if menu_options:
[the menu update code]
ctypes.windll.user32.DestroyMenu(self._menu)
self._menu = None
No description provided.