-
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
""" update icon image and/or hover text and/or menu options""" | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. You're right, I removed it! |
||
menu_options = menu_options + (('Quit', None, SysTrayIcon.QUIT),) | ||
self._next_action_id = SysTrayIcon.FIRST_ID | ||
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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Would You'll probably have to add an alias for it in if menu_options:
[the menu update code]
ctypes.windll.user32.DestroyMenu(self._menu)
self._menu = None |
||
self._refresh_icon() | ||
|
||
|
||
def _add_ids_to_menu_options(self, menu_options): | ||
result = [] | ||
for menu_option in 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!