From 5db24e34ae9860a1518c4000319a507d97fc0564 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 15 Dec 2020 13:39:17 +0100 Subject: [PATCH] extracted launcher from avalon module to launcher action --- pype/modules/avalon_apps/avalon_app.py | 33 +------------------- pype/modules/base.py | 1 + pype/modules/launcher_action.py | 43 ++++++++++++++++++++++++++ pype/tools/launcher/actions.py | 14 ++++++--- 4 files changed, 54 insertions(+), 37 deletions(-) create mode 100644 pype/modules/launcher_action.py diff --git a/pype/modules/avalon_apps/avalon_app.py b/pype/modules/avalon_apps/avalon_app.py index 683d804412..d00a306e9e 100644 --- a/pype/modules/avalon_apps/avalon_app.py +++ b/pype/modules/avalon_apps/avalon_app.py @@ -44,7 +44,6 @@ class AvalonModule(PypeModule, ITrayModule, IRestApi): ) # Tray attributes - self.app_launcher = None self.libraryloader = None self.rest_api_obj = None @@ -99,29 +98,8 @@ class AvalonModule(PypeModule, ITrayModule, IRestApi): exc_info=True ) - # Add launcher - try: - from pype.tools.launcher import LauncherWindow - self.app_launcher = LauncherWindow() - except Exception: - self.log.warning( - "Couldn't load Launch for tray.", - exc_info=True - ) - def connect_with_modules(self, _enabled_modules): - plugin_paths = self.manager.collect_plugin_paths()["actions"] - if plugin_paths: - env_paths_str = os.environ.get("AVALON_ACTIONS") or "" - env_paths = env_paths_str.split(os.pathsep) - env_paths.extend(plugin_paths) - os.environ["AVALON_ACTIONS"] = os.pathsep.join(env_paths) - - if self.tray_initialized: - from pype.tools.launcher import actions - # actions.register_default_actions() - actions.register_config_actions() - actions.register_environment_actions() + return def rest_api_initialization(self, rest_api_module): if self.tray_initialized: @@ -132,15 +110,12 @@ class AvalonModule(PypeModule, ITrayModule, IRestApi): def tray_menu(self, tray_menu): from Qt import QtWidgets # Actions - action_launcher = QtWidgets.QAction("Launcher", tray_menu) action_library_loader = QtWidgets.QAction( "Library loader", tray_menu ) - action_launcher.triggered.connect(self.show_launcher) action_library_loader.triggered.connect(self.show_library_loader) - tray_menu.addAction(action_launcher) tray_menu.addAction(action_library_loader) def tray_start(self, *_a, **_kw): @@ -149,12 +124,6 @@ class AvalonModule(PypeModule, ITrayModule, IRestApi): def tray_exit(self, *_a, **_kw): return - def show_launcher(self): - # if app_launcher don't exist create it/otherwise only show main window - self.app_launcher.show() - self.app_launcher.raise_() - self.app_launcher.activateWindow() - def show_library_loader(self): self.libraryloader.show() diff --git a/pype/modules/base.py b/pype/modules/base.py index 074fd43429..43ed570e19 100644 --- a/pype/modules/base.py +++ b/pype/modules/base.py @@ -422,6 +422,7 @@ class TrayModulesManager(ModulesManager): "user", "ftrack", "muster", + "launcher_tool", "avalon", "clockify", "standalonepublish_tool", diff --git a/pype/modules/launcher_action.py b/pype/modules/launcher_action.py new file mode 100644 index 0000000000..bc6ad507c4 --- /dev/null +++ b/pype/modules/launcher_action.py @@ -0,0 +1,43 @@ +from . import PypeModule, ITrayAction + + +class LauncherAction(PypeModule, ITrayAction): + label = "Launcher" + name = "launcher_tool" + + def initialize(self, _modules_settings): + # This module is always enabled + self.enabled = True + + # Tray attributes + self.window = None + + def tray_init(self): + self.create_window() + + def tray_start(self): + # Register actions + from pype.tools.launcher import actions + # actions.register_default_actions() + actions.register_config_actions() + actions_paths = self.manager.collect_plugin_paths()["actions"] + actions.register_actions_from_paths(actions_paths) + actions.register_environment_actions() + + def connect_with_modules(self, _enabled_modules): + return + + def create_window(self): + if self.window: + return + from pype.tools.launcher import LauncherWindow + self.window = LauncherWindow() + + def on_action_trigger(self): + self.show_launcher() + + def show_launcher(self): + if self.window: + self.window.show() + self.window.raise_() + self.window.activateWindow() diff --git a/pype/tools/launcher/actions.py b/pype/tools/launcher/actions.py index 6d0c94b676..db50c0c859 100644 --- a/pype/tools/launcher/actions.py +++ b/pype/tools/launcher/actions.py @@ -85,14 +85,11 @@ def register_config_actions(): config.register_launcher_actions() -def register_environment_actions(): - """Register actions from AVALON_ACTIONS for Launcher.""" - - paths = os.environ.get("AVALON_ACTIONS") +def register_actions_from_paths(paths): if not paths: return - for path in paths.split(os.pathsep): + for path in paths: api.register_plugin_path(api.Action, path) # Run "register" if found. @@ -110,6 +107,13 @@ def register_environment_actions(): ) +def register_environment_actions(): + """Register actions from AVALON_ACTIONS for Launcher.""" + + paths = os.environ.get("AVALON_ACTIONS") or "" + register_actions_from_paths(paths.split(os.pathsep)) + + class ApplicationAction(api.Action): """Pype's application launcher