moved events to openpype.lib

This commit is contained in:
Jakub Trllo 2022-03-05 08:30:29 +01:00
parent 9c111fa9d4
commit 502785021e
16 changed files with 35 additions and 33 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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