mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
modules does not have to inherit from ILaunchHookPaths and application is passed to 'collect_launch_hook_paths
This commit is contained in:
parent
88be040598
commit
32176ba234
3 changed files with 67 additions and 8 deletions
|
|
@ -996,7 +996,9 @@ class ApplicationLaunchContext:
|
||||||
paths.append(path)
|
paths.append(path)
|
||||||
|
|
||||||
# Load modules paths
|
# Load modules paths
|
||||||
paths.extend(self.modules_manager.collect_launch_hook_paths())
|
paths.extend(
|
||||||
|
self.modules_manager.collect_launch_hook_paths(self.application)
|
||||||
|
)
|
||||||
|
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -789,24 +789,50 @@ class ModulesManager:
|
||||||
output.extend(paths)
|
output.extend(paths)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def collect_launch_hook_paths(self):
|
def collect_launch_hook_paths(self, app):
|
||||||
"""Helper to collect hooks from modules inherited ILaunchHookPaths.
|
"""Helper to collect application launch hooks.
|
||||||
|
|
||||||
|
It used to be based on 'ILaunchHookPaths' which is not true anymore.
|
||||||
|
Module just have to have implemented 'get_launch_hook_paths' method.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
app (Application): Application object which can be used for
|
||||||
|
filtering of which launch hook paths are returned.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: Paths to launch hook directories.
|
list: Paths to launch hook directories.
|
||||||
"""
|
"""
|
||||||
from openpype_interfaces import ILaunchHookPaths
|
|
||||||
|
|
||||||
str_type = type("")
|
str_type = type("")
|
||||||
expected_types = (list, tuple, set)
|
expected_types = (list, tuple, set)
|
||||||
|
|
||||||
output = []
|
output = []
|
||||||
for module in self.get_enabled_modules():
|
for module in self.get_enabled_modules():
|
||||||
# Skip module that do not inherit from `ILaunchHookPaths`
|
# Skip module if does not have implemented 'get_launch_hook_paths'
|
||||||
if not isinstance(module, ILaunchHookPaths):
|
func = getattr(module, "get_launch_hook_paths", None)
|
||||||
|
if func is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
func = module.get_launch_hook_paths
|
||||||
|
if hasattr(inspect, "signature"):
|
||||||
|
sig = inspect.signature(func)
|
||||||
|
expect_args = len(sig.parameters) > 0
|
||||||
|
else:
|
||||||
|
expect_args = len(inspect.getargspec(func)[0]) > 0
|
||||||
|
|
||||||
|
# Pass application argument if method expect it.
|
||||||
|
try:
|
||||||
|
if expect_args:
|
||||||
|
hook_paths = func(app)
|
||||||
|
else:
|
||||||
|
hook_paths = func()
|
||||||
|
except Exception:
|
||||||
|
self.log.warning(
|
||||||
|
"Failed to call 'get_launch_hook_paths'",
|
||||||
|
exc_info=True
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
hook_paths = module.get_launch_hook_paths()
|
|
||||||
if not hook_paths:
|
if not hook_paths:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,12 +50,32 @@ class IPluginPaths(OpenPypeInterface):
|
||||||
class ILaunchHookPaths(OpenPypeInterface):
|
class ILaunchHookPaths(OpenPypeInterface):
|
||||||
"""Module has launch hook paths to return.
|
"""Module has launch hook paths to return.
|
||||||
|
|
||||||
|
Modules does not have to inherit from this interface (changed 8.11.2022).
|
||||||
|
Module just have to have implemented 'get_launch_hook_paths' to be able use
|
||||||
|
the advantage.
|
||||||
|
|
||||||
Expected result is list of paths.
|
Expected result is list of paths.
|
||||||
["path/to/launch_hooks_dir"]
|
["path/to/launch_hooks_dir"]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_launch_hook_paths(self):
|
def get_launch_hook_paths(self, app):
|
||||||
|
"""Paths to directory with application launch hooks.
|
||||||
|
|
||||||
|
Method can be also defined without arguments.
|
||||||
|
```python
|
||||||
|
def get_launch_hook_paths(self):
|
||||||
|
return []
|
||||||
|
```
|
||||||
|
|
||||||
|
Args:
|
||||||
|
app (Application): Application object which can be used for
|
||||||
|
filtering of which launch hook paths are returned.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Iterable[str]: Path to directories where launch hooks can be found.
|
||||||
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -66,6 +86,7 @@ class ITrayModule(OpenPypeInterface):
|
||||||
The module still must be usable if is not used in tray even if
|
The module still must be usable if is not used in tray even if
|
||||||
would do nothing.
|
would do nothing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
tray_initialized = False
|
tray_initialized = False
|
||||||
_tray_manager = None
|
_tray_manager = None
|
||||||
|
|
||||||
|
|
@ -78,16 +99,19 @@ class ITrayModule(OpenPypeInterface):
|
||||||
This is where GUIs should be loaded or tray specific parts should be
|
This is where GUIs should be loaded or tray specific parts should be
|
||||||
prepared.
|
prepared.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def tray_menu(self, tray_menu):
|
def tray_menu(self, tray_menu):
|
||||||
"""Add module's action to tray menu."""
|
"""Add module's action to tray menu."""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def tray_start(self):
|
def tray_start(self):
|
||||||
"""Start procedure in Pype tray."""
|
"""Start procedure in Pype tray."""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|
@ -96,6 +120,7 @@ class ITrayModule(OpenPypeInterface):
|
||||||
|
|
||||||
This is place where all threads should be shut.
|
This is place where all threads should be shut.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def execute_in_main_thread(self, callback):
|
def execute_in_main_thread(self, callback):
|
||||||
|
|
@ -104,6 +129,7 @@ class ITrayModule(OpenPypeInterface):
|
||||||
Some callbacks need to be processed on main thread (menu actions
|
Some callbacks need to be processed on main thread (menu actions
|
||||||
must be added on main thread or they won't get triggered etc.)
|
must be added on main thread or they won't get triggered etc.)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not self.tray_initialized:
|
if not self.tray_initialized:
|
||||||
# TODO Called without initialized tray, still main thread needed
|
# TODO Called without initialized tray, still main thread needed
|
||||||
try:
|
try:
|
||||||
|
|
@ -128,6 +154,7 @@ class ITrayModule(OpenPypeInterface):
|
||||||
msecs (int): Duration of message visibility in miliseconds.
|
msecs (int): Duration of message visibility in miliseconds.
|
||||||
Default is 10000 msecs, may differ by Qt version.
|
Default is 10000 msecs, may differ by Qt version.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self._tray_manager:
|
if self._tray_manager:
|
||||||
self._tray_manager.show_tray_message(title, message, icon, msecs)
|
self._tray_manager.show_tray_message(title, message, icon, msecs)
|
||||||
|
|
||||||
|
|
@ -280,16 +307,19 @@ class ITrayService(ITrayModule):
|
||||||
|
|
||||||
def set_service_running_icon(self):
|
def set_service_running_icon(self):
|
||||||
"""Change icon of an QAction to green circle."""
|
"""Change icon of an QAction to green circle."""
|
||||||
|
|
||||||
if self.menu_action:
|
if self.menu_action:
|
||||||
self.menu_action.setIcon(self.get_icon_running())
|
self.menu_action.setIcon(self.get_icon_running())
|
||||||
|
|
||||||
def set_service_failed_icon(self):
|
def set_service_failed_icon(self):
|
||||||
"""Change icon of an QAction to red circle."""
|
"""Change icon of an QAction to red circle."""
|
||||||
|
|
||||||
if self.menu_action:
|
if self.menu_action:
|
||||||
self.menu_action.setIcon(self.get_icon_failed())
|
self.menu_action.setIcon(self.get_icon_failed())
|
||||||
|
|
||||||
def set_service_idle_icon(self):
|
def set_service_idle_icon(self):
|
||||||
"""Change icon of an QAction to orange circle."""
|
"""Change icon of an QAction to orange circle."""
|
||||||
|
|
||||||
if self.menu_action:
|
if self.menu_action:
|
||||||
self.menu_action.setIcon(self.get_icon_idle())
|
self.menu_action.setIcon(self.get_icon_idle())
|
||||||
|
|
||||||
|
|
@ -303,6 +333,7 @@ class ISettingsChangeListener(OpenPypeInterface):
|
||||||
"publish": ["path/to/publish_plugins"]
|
"publish": ["path/to/publish_plugins"]
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def on_system_settings_save(
|
def on_system_settings_save(
|
||||||
self, old_value, new_value, changes, new_value_metadata
|
self, old_value, new_value, changes, new_value_metadata
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue