This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #667 from pypeclub/feature/663-aftereffects-integr…
…ation-with-websocket Feature/663 aftereffects integration with websocket
- Loading branch information
Showing
7 changed files
with
605 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
import sys | ||
|
||
from avalon import api, io | ||
from avalon.vendor import Qt | ||
from pype import lib | ||
import pyblish.api | ||
|
||
|
||
def check_inventory(): | ||
if not lib.any_outdated(): | ||
return | ||
|
||
host = api.registered_host() | ||
outdated_containers = [] | ||
for container in host.ls(): | ||
representation = container['representation'] | ||
representation_doc = io.find_one( | ||
{ | ||
"_id": io.ObjectId(representation), | ||
"type": "representation" | ||
}, | ||
projection={"parent": True} | ||
) | ||
if representation_doc and not lib.is_latest(representation_doc): | ||
outdated_containers.append(container) | ||
|
||
# Warn about outdated containers. | ||
print("Starting new QApplication..") | ||
app = Qt.QtWidgets.QApplication(sys.argv) | ||
|
||
message_box = Qt.QtWidgets.QMessageBox() | ||
message_box.setIcon(Qt.QtWidgets.QMessageBox.Warning) | ||
msg = "There are outdated containers in the scene." | ||
message_box.setText(msg) | ||
message_box.exec_() | ||
|
||
# Garbage collect QApplication. | ||
del app | ||
|
||
|
||
def application_launch(): | ||
check_inventory() | ||
|
||
|
||
def install(): | ||
print("Installing Pype config...") | ||
|
||
plugins_directory = os.path.join( | ||
os.path.dirname(os.path.dirname(os.path.dirname(__file__))), | ||
"plugins", | ||
"aftereffects" | ||
) | ||
|
||
pyblish.api.register_plugin_path( | ||
os.path.join(plugins_directory, "publish") | ||
) | ||
api.register_plugin_path( | ||
api.Loader, os.path.join(plugins_directory, "load") | ||
) | ||
api.register_plugin_path( | ||
api.Creator, os.path.join(plugins_directory, "create") | ||
) | ||
|
||
pyblish.api.register_callback( | ||
"instanceToggled", on_pyblish_instance_toggled | ||
) | ||
|
||
api.on("application.launched", application_launch) | ||
|
||
|
||
def on_pyblish_instance_toggled(instance, old_value, new_value): | ||
"""Toggle layer visibility on instance toggles.""" | ||
instance[0].Visible = new_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from pype.api import Logger | ||
from wsrpc_aiohttp import WebSocketRoute | ||
import functools | ||
|
||
import avalon.aftereffects as aftereffects | ||
|
||
log = Logger().get_logger("WebsocketServer") | ||
|
||
|
||
class AfterEffects(WebSocketRoute): | ||
""" | ||
One route, mimicking external application (like Harmony, etc). | ||
All functions could be called from client. | ||
'do_notify' function calls function on the client - mimicking | ||
notification after long running job on the server or similar | ||
""" | ||
instance = None | ||
|
||
def init(self, **kwargs): | ||
# Python __init__ must be return "self". | ||
# This method might return anything. | ||
log.debug("someone called AfterEffects route") | ||
self.instance = self | ||
return kwargs | ||
|
||
# server functions | ||
async def ping(self): | ||
log.debug("someone called AfterEffects route ping") | ||
|
||
# This method calls function on the client side | ||
# client functions | ||
|
||
async def read(self): | ||
log.debug("aftereffects.read client calls server server calls " | ||
"aftereffects client") | ||
return await self.socket.call('aftereffects.read') | ||
|
||
# panel routes for tools | ||
async def creator_route(self): | ||
self._tool_route("creator") | ||
|
||
async def workfiles_route(self): | ||
self._tool_route("workfiles") | ||
|
||
async def loader_route(self): | ||
self._tool_route("loader") | ||
|
||
async def publish_route(self): | ||
self._tool_route("publish") | ||
|
||
async def sceneinventory_route(self): | ||
self._tool_route("sceneinventory") | ||
|
||
async def projectmanager_route(self): | ||
self._tool_route("projectmanager") | ||
|
||
def _tool_route(self, tool_name): | ||
"""The address accessed when clicking on the buttons.""" | ||
partial_method = functools.partial(aftereffects.show, tool_name) | ||
|
||
aftereffects.execute_in_main_thread(partial_method) | ||
|
||
# Required return statement. | ||
return "nothing" |
Oops, something went wrong.