extracted launcher from avalon module to launcher action

This commit is contained in:
iLLiCiTiT 2020-12-15 13:39:17 +01:00
parent dd5dea2c04
commit 5db24e34ae
4 changed files with 54 additions and 37 deletions

View file

@ -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()

View file

@ -422,6 +422,7 @@ class TrayModulesManager(ModulesManager):
"user",
"ftrack",
"muster",
"launcher_tool",
"avalon",
"clockify",
"standalonepublish_tool",

View file

@ -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()

View file

@ -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