mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
Merge pull request #111 from aardschok/PLN55
Re-initialize Maya after context changed
This commit is contained in:
commit
7644b397db
1 changed files with 46 additions and 2 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
from functools import partial
|
import weakref
|
||||||
|
|
||||||
from maya import utils
|
from maya import utils
|
||||||
from maya import cmds
|
from maya import cmds
|
||||||
|
|
||||||
from avalon import api as avalon
|
from avalon import api as avalon, pipeline, maya
|
||||||
from pyblish import api as pyblish
|
from pyblish import api as pyblish
|
||||||
|
|
||||||
from ..lib import (
|
from ..lib import (
|
||||||
|
|
@ -38,6 +38,9 @@ def install():
|
||||||
avalon.on("save", on_save)
|
avalon.on("save", on_save)
|
||||||
avalon.on("open", on_open)
|
avalon.on("open", on_open)
|
||||||
|
|
||||||
|
log.info("Overriding existing event 'taskChanged'")
|
||||||
|
override_event("taskChanged", on_task_changed)
|
||||||
|
|
||||||
|
|
||||||
def uninstall():
|
def uninstall():
|
||||||
pyblish.deregister_plugin_path(PUBLISH_PATH)
|
pyblish.deregister_plugin_path(PUBLISH_PATH)
|
||||||
|
|
@ -47,6 +50,24 @@ def uninstall():
|
||||||
menu.uninstall()
|
menu.uninstall()
|
||||||
|
|
||||||
|
|
||||||
|
def override_event(event, callback):
|
||||||
|
"""
|
||||||
|
Override existing event callback
|
||||||
|
Args:
|
||||||
|
event (str): name of the event
|
||||||
|
callback (function): callback to be triggered
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
ref = weakref.WeakSet()
|
||||||
|
ref.add(callback)
|
||||||
|
|
||||||
|
pipeline._registered_event_handlers[event] = callback
|
||||||
|
|
||||||
|
|
||||||
def on_init(_):
|
def on_init(_):
|
||||||
avalon.logger.info("Running callback on init..")
|
avalon.logger.info("Running callback on init..")
|
||||||
|
|
||||||
|
|
@ -122,3 +143,26 @@ def on_open(_):
|
||||||
"your Maya scene.")
|
"your Maya scene.")
|
||||||
dialog.on_show.connect(_on_show_inventory)
|
dialog.on_show.connect(_on_show_inventory)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
|
|
||||||
|
|
||||||
|
def on_task_changed():
|
||||||
|
"""Wrapped function of app initialize and maya's on task changed"""
|
||||||
|
|
||||||
|
# Inputs (from the switched session and running app)
|
||||||
|
session = avalon.Session.copy()
|
||||||
|
app_name = os.environ["AVALON_APP_NAME"]
|
||||||
|
|
||||||
|
# Find the application definition
|
||||||
|
app_definition = pipeline.lib.get_application(app_name)
|
||||||
|
|
||||||
|
App = type("app_%s" % app_name,
|
||||||
|
(avalon.Application,),
|
||||||
|
{"config": app_definition.copy()})
|
||||||
|
|
||||||
|
# Initialize within the new session's environment
|
||||||
|
app = App()
|
||||||
|
env = app.environ(session)
|
||||||
|
app.initialize(env)
|
||||||
|
|
||||||
|
# Run
|
||||||
|
maya.pipeline._on_task_changed()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue