From be3bc7af8e64c727ab51ce834d5232d7d8fc7ce1 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 3 Jan 2024 23:20:17 +0800 Subject: [PATCH] code changes based on Ondrej's comment --- openpype/hosts/max/api/pipeline.py | 56 +++++++----------------------- 1 file changed, 13 insertions(+), 43 deletions(-) diff --git a/openpype/hosts/max/api/pipeline.py b/openpype/hosts/max/api/pipeline.py index 98895b858e..d0ae854dc8 100644 --- a/openpype/hosts/max/api/pipeline.py +++ b/openpype/hosts/max/api/pipeline.py @@ -3,7 +3,6 @@ import os import logging from operator import attrgetter -from functools import partial import json @@ -14,10 +13,6 @@ from openpype.pipeline import ( register_loader_plugin_path, AVALON_CONTAINER_ID, ) -from openpype.lib import ( - register_event_callback, - emit_event -) from openpype.hosts.max.api.menu import OpenPypeMenu from openpype.hosts.max.api import lib from openpype.hosts.max.api.plugin import MS_CUSTOM_ATTRIB @@ -51,14 +46,19 @@ class MaxHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): register_loader_plugin_path(LOAD_PATH) register_creator_plugin_path(CREATE_PATH) - self._register_callbacks() + # self._register_callbacks() self.menu = OpenPypeMenu() - register_event_callback( - "init", self._deferred_menu_creation) self._has_been_setup = True - register_event_callback("open", on_open) - register_event_callback("new", on_new) + + def context_setting(): + return lib.set_context_setting() + + rt.callbacks.addScript(rt.Name('systemPostNew'), + context_setting) + + rt.callbacks.addScript(rt.Name('filePostOpen'), + lib.check_colorspace) def has_unsaved_changes(self): # TODO: how to get it from 3dsmax? @@ -83,28 +83,11 @@ class MaxHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): return ls() def _register_callbacks(self): - unique_id = rt.Name("openpype_callbacks") - for handler, event in self._op_events.copy().items(): - if event is None: - continue - try: - rt.callbacks.removeScripts(id=unique_id) - self._op_events[handler] = None - except RuntimeError as exc: - self.log.info(exc) + rt.callbacks.removeScripts(id=rt.name("OpenPypeCallbacks")) - self._op_events["init"] = rt.callbacks.addScript( + rt.callbacks.addScript( rt.Name("postLoadingMenus"), - partial(_emit_event_notification_param, "init"), - id=unique_id) - self._op_events["new"] = rt.callbacks.addScript( - rt.Name('systemPostNew'), - partial(_emit_event_notification_param, "new"), - id=unique_id) - self._op_events["open"] = rt.callbacks.addScript( - rt.Name('filePostOpen'), - partial(_emit_event_notification_param, "open"), - id=unique_id) + self._deferred_menu_creation, id=rt.Name('OpenPypeCallbacks')) def _deferred_menu_creation(self): self.log.info("Building menu ...") @@ -161,19 +144,6 @@ attributes "OpenPypeContext" rt.saveMaxFile(dst_path) -def _emit_event_notification_param(event): - notification = rt.callbacks.notificationParam() - emit_event(event, {"notificationParam": notification}) - - -def on_open(): - return lib.check_colorspace() - - -def on_new(): - return lib.set_context_setting() - - def ls() -> list: """Get all OpenPype instances.""" objs = rt.objects