From 502785021e5fcf364bb1b01217c1dc522114d17e Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Sat, 5 Mar 2022 08:30:29 +0100 Subject: [PATCH] moved events to openpype.lib --- openpype/__init__.py | 2 +- openpype/hosts/aftereffects/api/pipeline.py | 2 +- openpype/hosts/blender/api/pipeline.py | 2 +- openpype/hosts/harmony/api/pipeline.py | 2 +- openpype/hosts/hiero/api/events.py | 4 ++-- openpype/hosts/houdini/api/pipeline.py | 8 +++----- openpype/hosts/maya/api/pipeline.py | 10 +++++----- openpype/hosts/nuke/api/pipeline.py | 2 +- openpype/hosts/photoshop/api/pipeline.py | 2 +- openpype/hosts/tvpaint/api/communication_server.py | 2 +- openpype/hosts/tvpaint/api/pipeline.py | 2 +- openpype/lib/__init__.py | 7 +++++++ openpype/{pipeline => lib}/events.py | 11 ++++++++--- openpype/pipeline/__init__.py | 8 -------- openpype/tools/loader/app.py | 2 +- openpype/tools/workfiles/app.py | 2 +- 16 files changed, 35 insertions(+), 33 deletions(-) rename openpype/{pipeline => lib}/events.py (94%) diff --git a/openpype/__init__.py b/openpype/__init__.py index 9175727a54..63ad81d3ca 100644 --- a/openpype/__init__.py +++ b/openpype/__init__.py @@ -11,8 +11,8 @@ from .lib import ( filter_pyblish_plugins, set_plugin_attributes_from_settings, change_timer_to_current_context, + register_event_callback, ) -from .pipeline import register_event_callback pyblish = avalon = _original_discover = None diff --git a/openpype/hosts/aftereffects/api/pipeline.py b/openpype/hosts/aftereffects/api/pipeline.py index 6f7cd8c46d..96d04aad14 100644 --- a/openpype/hosts/aftereffects/api/pipeline.py +++ b/openpype/hosts/aftereffects/api/pipeline.py @@ -10,7 +10,7 @@ from avalon import io, pipeline from openpype import lib from openpype.api import Logger import openpype.hosts.aftereffects -from openpype.pipeline import register_event_callback +from openpype.lib import register_event_callback from .launch_logic import get_stub diff --git a/openpype/hosts/blender/api/pipeline.py b/openpype/hosts/blender/api/pipeline.py index 38312316cc..d1e7df3a93 100644 --- a/openpype/hosts/blender/api/pipeline.py +++ b/openpype/hosts/blender/api/pipeline.py @@ -15,7 +15,7 @@ from avalon import io, schema from avalon.pipeline import AVALON_CONTAINER_ID from openpype.api import Logger -from openpype.pipeline import ( +from openpype.lib import ( register_event_callback, emit_event ) diff --git a/openpype/hosts/harmony/api/pipeline.py b/openpype/hosts/harmony/api/pipeline.py index a94d30210e..8d7ac19eb9 100644 --- a/openpype/hosts/harmony/api/pipeline.py +++ b/openpype/hosts/harmony/api/pipeline.py @@ -9,7 +9,7 @@ import avalon.api from avalon.pipeline import AVALON_CONTAINER_ID from openpype import lib -from openpype.pipeline import register_event_callback +from openpype.lib import register_event_callback import openpype.hosts.harmony import openpype.hosts.harmony.api as harmony diff --git a/openpype/hosts/hiero/api/events.py b/openpype/hosts/hiero/api/events.py index 6e2580ed8c..9439199933 100644 --- a/openpype/hosts/hiero/api/events.py +++ b/openpype/hosts/hiero/api/events.py @@ -1,12 +1,12 @@ import os import hiero.core.events from openpype.api import Logger -from openpype.pipeline import register_event_callback from .lib import ( sync_avalon_data_to_workfile, launch_workfiles_app, selection_changed_timeline, - before_project_save + before_project_save, + register_event_callback ) from .tags import add_tags_to_workfile from .menu import update_menu_task_label diff --git a/openpype/hosts/houdini/api/pipeline.py b/openpype/hosts/houdini/api/pipeline.py index 86c85ad3a1..bbb7a7c512 100644 --- a/openpype/hosts/houdini/api/pipeline.py +++ b/openpype/hosts/houdini/api/pipeline.py @@ -11,15 +11,13 @@ import avalon.api from avalon.pipeline import AVALON_CONTAINER_ID from avalon.lib import find_submodule -from openpype.pipeline import ( - register_event_callback, - emit_event -) import openpype.hosts.houdini from openpype.hosts.houdini.api import lib from openpype.lib import ( - any_outdated + register_event_callback, + emit_event, + any_outdated, ) from .lib import get_asset_fps diff --git a/openpype/hosts/maya/api/pipeline.py b/openpype/hosts/maya/api/pipeline.py index 05db1b7b26..4945a9ba56 100644 --- a/openpype/hosts/maya/api/pipeline.py +++ b/openpype/hosts/maya/api/pipeline.py @@ -14,8 +14,8 @@ from avalon.pipeline import AVALON_CONTAINER_ID import openpype.hosts.maya from openpype.tools.utils import host_tools -from openpype.lib import any_outdated -from openpype.pipeline import ( +from openpype.lib import ( + any_outdated, register_event_callback, emit_event ) @@ -150,15 +150,15 @@ def _on_maya_initialized(*args): lib.get_main_window() -def _on_scene_new(): +def _on_scene_new(*args): emit_event("new") -def _on_scene_save(): +def _on_scene_save(*args): emit_event("save") -def _on_scene_open(): +def _on_scene_open(*args): emit_event("open") diff --git a/openpype/hosts/nuke/api/pipeline.py b/openpype/hosts/nuke/api/pipeline.py index 1a5116c9ea..419cfb1ac2 100644 --- a/openpype/hosts/nuke/api/pipeline.py +++ b/openpype/hosts/nuke/api/pipeline.py @@ -14,7 +14,7 @@ from openpype.api import ( BuildWorkfile, get_current_project_settings ) -from openpype.pipeline import register_event_callback +from openpype.lib import register_event_callback from openpype.tools.utils import host_tools from .command import viewer_update_and_undo_stop diff --git a/openpype/hosts/photoshop/api/pipeline.py b/openpype/hosts/photoshop/api/pipeline.py index 2aade59812..e424400465 100644 --- a/openpype/hosts/photoshop/api/pipeline.py +++ b/openpype/hosts/photoshop/api/pipeline.py @@ -6,7 +6,7 @@ import avalon.api from avalon import pipeline, io from openpype.api import Logger -from openpype.pipeline import register_event_callback +from openpype.lib import register_event_callback import openpype.hosts.photoshop from . import lib diff --git a/openpype/hosts/tvpaint/api/communication_server.py b/openpype/hosts/tvpaint/api/communication_server.py index b001b84203..65cb9aa2f3 100644 --- a/openpype/hosts/tvpaint/api/communication_server.py +++ b/openpype/hosts/tvpaint/api/communication_server.py @@ -21,7 +21,7 @@ from aiohttp_json_rpc.protocol import ( ) from aiohttp_json_rpc.exceptions import RpcError -from openpype.pipeline import emit_event +from openpype.lib import emit_event from openpype.hosts.tvpaint.tvpaint_plugin import get_plugin_files_path log = logging.getLogger(__name__) diff --git a/openpype/hosts/tvpaint/api/pipeline.py b/openpype/hosts/tvpaint/api/pipeline.py index b999478fb1..381c2c62f0 100644 --- a/openpype/hosts/tvpaint/api/pipeline.py +++ b/openpype/hosts/tvpaint/api/pipeline.py @@ -14,7 +14,7 @@ from avalon.pipeline import AVALON_CONTAINER_ID from openpype.hosts import tvpaint from openpype.api import get_current_project_settings -from openpype.pipeline import register_event_callback +from openpype.lib import register_event_callback from .lib import ( execute_george, diff --git a/openpype/lib/__init__.py b/openpype/lib/__init__.py index 6a24f30455..1ee9129fa7 100644 --- a/openpype/lib/__init__.py +++ b/openpype/lib/__init__.py @@ -16,6 +16,10 @@ sys.path.insert(0, python_version_dir) site.addsitedir(python_version_dir) +from .events import ( + emit_event, + register_event_callback +) from .env_tools import ( env_value_to_bool, get_paths_from_environ, @@ -193,6 +197,9 @@ from .openpype_version import ( terminal = Terminal __all__ = [ + "emit_event", + "register_event_callback", + "get_openpype_execute_args", "get_pype_execute_args", "get_linux_launcher_args", diff --git a/openpype/pipeline/events.py b/openpype/lib/events.py similarity index 94% rename from openpype/pipeline/events.py rename to openpype/lib/events.py index cae8b250f7..62c480d8e0 100644 --- a/openpype/pipeline/events.py +++ b/openpype/lib/events.py @@ -8,7 +8,7 @@ from uuid import uuid4 try: from weakref import WeakMethod except Exception: - from .python_2_comp import WeakMethod + from openpype.lib.python_2_comp import WeakMethod class EventCallback(object): @@ -83,6 +83,7 @@ class EventCallback(object): Args: event(Event): Event that was triggered. """ + self.log.info("Processing event {}".format(event.topic)) # Skip if callback is not enabled or has invalid reference if not self._ref_valid or not self._enabled: return @@ -93,9 +94,11 @@ class EventCallback(object): if not callback: # Change state if is invalid so the callback is removed self._ref_valid = False + self.log.info("Invalid reference") elif self.topic_matches(event.topic): # Try execute callback + self.log.info("Triggering callback") sig = inspect.signature(callback) try: if len(sig.parameters) == 0: @@ -109,6 +112,8 @@ class EventCallback(object): ), exc_info=True ) + else: + self.log.info("Not matchin callback") # Inherit from 'object' for Python 2 hosts @@ -172,7 +177,7 @@ class StoredCallbacks: elif callable(callback): ref = weakref.ref(callback) else: - # TODO add logs + print("Invalid callback") return function_name = callback.__name__ @@ -197,7 +202,7 @@ class StoredCallbacks: def emit_event(cls, event): invalid_callbacks = [] for callback in cls._registered_callbacks: - callback.process_event() + callback.process_event(event) if not callback.is_ref_valid: invalid_callbacks.append(callback) diff --git a/openpype/pipeline/__init__.py b/openpype/pipeline/__init__.py index 673608bded..e968df4011 100644 --- a/openpype/pipeline/__init__.py +++ b/openpype/pipeline/__init__.py @@ -1,10 +1,5 @@ from .lib import attribute_definitions -from .events import ( - emit_event, - register_event_callback -) - from .create import ( BaseCreator, Creator, @@ -22,9 +17,6 @@ from .publish import ( __all__ = ( "attribute_definitions", - "emit_event", - "register_event_callback", - "BaseCreator", "Creator", "AutoCreator", diff --git a/openpype/tools/loader/app.py b/openpype/tools/loader/app.py index afb94bf8fc..ec8f56e74b 100644 --- a/openpype/tools/loader/app.py +++ b/openpype/tools/loader/app.py @@ -4,7 +4,7 @@ from Qt import QtWidgets, QtCore from avalon import api, io from openpype import style -from openpype.pipeline import register_event_callback +from openpype.lib import register_event_callback from openpype.tools.utils import ( lib, PlaceholderLineEdit diff --git a/openpype/tools/workfiles/app.py b/openpype/tools/workfiles/app.py index 280fe2d8a2..87e1492a20 100644 --- a/openpype/tools/workfiles/app.py +++ b/openpype/tools/workfiles/app.py @@ -12,7 +12,6 @@ from Qt import QtWidgets, QtCore from avalon import io, api from openpype import style -from openpype.pipeline import emit_event from openpype.tools.utils.lib import ( qt_app_context ) @@ -21,6 +20,7 @@ from openpype.tools.utils.assets_widget import SingleSelectAssetsWidget from openpype.tools.utils.tasks_widget import TasksWidget from openpype.tools.utils.delegates import PrettyTimeDelegate from openpype.lib import ( + emit_event, Anatomy, get_workfile_doc, create_workfile_doc,