Closed dbenarfa closed 8 months ago
Thank you for your request,
This is actually already implemented; please see the documentation. You need to provide lambdas or functions instead of plain values to enable dynamism, so setting visible=lambda v: some_function_to_determine_visibility()
should do it.
Thank you for your prompt reply.
Description:
Currently, PyStray provides comprehensive support for creating system tray applications in Python. However, it seems that there is no built-in functionality to enable or disable individual MenuItems within the tray icon's context menu. Adding this feature would greatly enhance the flexibility and usability of PyStray for developers who need to dynamically control the availability of certain menu options based on application state or user permissions.
Proposed Solution:
Introduce methods or properties within the PyStray library that allow developers to programmatically enable or disable specific MenuItems. This could involve adding new methods such as enable_item() and disable_item() to the Menu or MenuItem classes, or introducing a new property like enabled that can be set for each MenuItem instance.
Example Use Case:
`# Example code demonstrating how to enable/disable a MenuItem in PyStray
import pystray
def on_quit_clicked(icon, item): icon.stop()
menu = (pystray.MenuItem('Quit', on_quit_clicked), pystray.MenuItem('Disableable Item', lambda: None))
def enable_disable_item(enabled):
Logic to enable/disable the specific menu item
icon = pystray.Icon("name", icon=image, title="Title", menu=menu) icon.run()
Later in the application, enable or disable the menu item based on certain conditions
enable_disable_item(enabled=True) # Enable the menu item enable_disable_item(enabled=False) # Disable the menu item `
Note:
It maybe already existing but I couldn't find it anywhere.