Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/AY-5235_De…
Browse files Browse the repository at this point in the history
…livery-Farm-Publishing
  • Loading branch information
jakubjezek001 committed Dec 19, 2024
2 parents 45bbc2f + 50850b1 commit 0a994be
Show file tree
Hide file tree
Showing 32 changed files with 1,074 additions and 988 deletions.
73 changes: 16 additions & 57 deletions client/ayon_core/addon/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,67 +370,11 @@ def _load_ayon_addons(log):
return all_addon_modules


def _load_addons_in_core(log):
# Add current directory at first place
# - has small differences in import logic
addon_modules = []
modules_dir = os.path.join(AYON_CORE_ROOT, "modules")
if not os.path.exists(modules_dir):
log.warning(
f"Could not find path when loading AYON addons \"{modules_dir}\""
)
return addon_modules

ignored_filenames = IGNORED_FILENAMES | IGNORED_DEFAULT_FILENAMES
for filename in os.listdir(modules_dir):
# Ignore filenames
if filename in ignored_filenames:
continue

fullpath = os.path.join(modules_dir, filename)
basename, ext = os.path.splitext(filename)

# Validations
if os.path.isdir(fullpath):
# Check existence of init file
init_path = os.path.join(fullpath, "__init__.py")
if not os.path.exists(init_path):
log.debug((
"Addon directory does not contain __init__.py"
f" file {fullpath}"
))
continue

elif ext != ".py":
continue

# TODO add more logic how to define if folder is addon or not
# - check manifest and content of manifest
try:
# Don't import dynamically current directory modules
import_str = f"ayon_core.modules.{basename}"
default_module = __import__(import_str, fromlist=("", ))
addon_modules.append(default_module)

except Exception:
log.error(
f"Failed to import in-core addon '{basename}'.",
exc_info=True
)
return addon_modules


def _load_addons():
log = Logger.get_logger("AddonsLoader")

addon_modules = _load_ayon_addons(log)
# All addon in 'modules' folder are tray actions and should be moved
# to tray tool.
# TODO remove
addon_modules.extend(_load_addons_in_core(log))

# Store modules to local cache
_LoadCache.addon_modules = addon_modules
_LoadCache.addon_modules = _load_ayon_addons(log)


class AYONAddon(ABC):
Expand Down Expand Up @@ -950,6 +894,21 @@ def _collect_plugin_paths(self, method_name, *args, **kwargs):
output.extend(paths)
return output

def collect_launcher_action_paths(self):
"""Helper to collect launcher action paths from addons.
Returns:
list: List of paths to launcher actions.
"""
output = self._collect_plugin_paths(
"get_launcher_action_paths"
)
# Add default core actions
actions_dir = os.path.join(AYON_CORE_ROOT, "plugins", "actions")
output.insert(0, actions_dir)
return output

def collect_create_plugin_paths(self, host_name):
"""Helper to collect creator plugin paths from addons.
Expand Down
47 changes: 30 additions & 17 deletions client/ayon_core/addon/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def _get_plugin_paths_by_type(self, plugin_type):
paths = [paths]
return paths

def get_launcher_action_paths(self):
"""Receive launcher actions paths.
Give addons ability to add launcher actions paths.
"""
return self._get_plugin_paths_by_type("actions")

def get_create_plugin_paths(self, host_name):
"""Receive create plugin paths.
Expand Down Expand Up @@ -125,6 +132,7 @@ class ITrayAddon(AYONInterface):

tray_initialized = False
_tray_manager = None
_admin_submenu = None

@abstractmethod
def tray_init(self):
Expand Down Expand Up @@ -198,6 +206,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 +240,6 @@ class ITrayAction(ITrayAddon):
"""

admin_action = False
_admin_submenu = None
_action_item = None

@property
Expand All @@ -229,12 +257,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 +271,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
Empty file.
60 changes: 0 additions & 60 deletions client/ayon_core/modules/launcher_action.py

This file was deleted.

68 changes: 0 additions & 68 deletions client/ayon_core/modules/loader_action.py

This file was deleted.

This file was deleted.

42 changes: 0 additions & 42 deletions client/ayon_core/modules/python_console_interpreter/addon.py

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0a994be

Please sign in to comment.