Skip to content

Commit

Permalink
enhanced admin menu options
Browse files Browse the repository at this point in the history
  • Loading branch information
iLLiCiTiT committed Dec 10, 2024
1 parent 21e6013 commit a8441e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
40 changes: 23 additions & 17 deletions client/ayon_core/addon/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class ITrayAddon(AYONInterface):

tray_initialized = False
_tray_manager = None
_admin_submenu = None

@abstractmethod
def tray_init(self):
Expand Down Expand Up @@ -198,6 +199,27 @@ def add_doubleclick_callback(self, callback):
if hasattr(self.manager, "add_doubleclick_callback"):
self.manager.add_doubleclick_callback(self, callback)

@staticmethod
def admin_submenu(tray_menu):
if ITrayAddon._admin_submenu is None:
from qtpy import QtWidgets

admin_submenu = QtWidgets.QMenu("Admin", tray_menu)
admin_submenu.menuAction().setVisible(False)
ITrayAddon._admin_submenu = admin_submenu
return ITrayAddon._admin_submenu

@staticmethod
def add_action_to_admin_submenu(label, tray_menu):
from qtpy import QtWidgets

menu = ITrayAddon.admin_submenu(tray_menu)
action = QtWidgets.QAction(label, menu)
menu.addAction(action)
if not menu.menuAction().isVisible():
menu.menuAction().setVisible(True)
return action


class ITrayAction(ITrayAddon):
"""Implementation of Tray action.
Expand All @@ -211,7 +233,6 @@ class ITrayAction(ITrayAddon):
"""

admin_action = False
_admin_submenu = None
_action_item = None

@property
Expand All @@ -229,12 +250,7 @@ def tray_menu(self, tray_menu):
from qtpy import QtWidgets

if self.admin_action:
menu = self.admin_submenu(tray_menu)
action = QtWidgets.QAction(self.label, menu)
menu.addAction(action)
if not menu.menuAction().isVisible():
menu.menuAction().setVisible(True)

action = self.add_action_to_admin_submenu(self.label, tray_menu)
else:
action = QtWidgets.QAction(self.label, tray_menu)
tray_menu.addAction(action)
Expand All @@ -248,16 +264,6 @@ def tray_start(self):
def tray_exit(self):
return

@staticmethod
def admin_submenu(tray_menu):
if ITrayAction._admin_submenu is None:
from qtpy import QtWidgets

admin_submenu = QtWidgets.QMenu("Admin", tray_menu)
admin_submenu.menuAction().setVisible(False)
ITrayAction._admin_submenu = admin_submenu
return ITrayAction._admin_submenu


class ITrayService(ITrayAddon):
# Module's property
Expand Down
6 changes: 3 additions & 3 deletions client/ayon_core/tools/tray/ui/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from ayon_core.settings import get_studio_settings
from ayon_core.addon import (
ITrayAction,
ITrayAddon,
ITrayService,
)
from ayon_core.pipeline import install_ayon_plugins
Expand Down Expand Up @@ -156,7 +156,7 @@ def initialize_addons(self):

tray_menu = self.tray_widget.menu

console_action = ITrayAction.add_action_to_admin_submenu(
console_action = ITrayAddon.add_action_to_admin_submenu(
"Console", tray_menu
)
console_action.triggered.connect(self._show_console_window)
Expand All @@ -183,7 +183,7 @@ def initialize_addons(self):
"POST", "/tray/message", self._web_show_tray_message
)

admin_submenu = ITrayAction.admin_submenu(tray_menu)
admin_submenu = ITrayAddon.admin_submenu(tray_menu)
tray_menu.addMenu(admin_submenu)

# Add services if they are
Expand Down

0 comments on commit a8441e3

Please sign in to comment.