mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
code changes based on Ondrej's comment
This commit is contained in:
parent
d9f8b9e0f2
commit
be3bc7af8e
1 changed files with 13 additions and 43 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue