-
Notifications
You must be signed in to change notification settings - Fork 29
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 #16 from mottosso/master
Updated for Endpoint 1.0.2
- Loading branch information
Showing
4 changed files
with
113 additions
and
75 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 |
---|---|---|
@@ -1,9 +1,76 @@ | ||
from .lib import (register_plugins, | ||
register_gui, | ||
maintained_selection, | ||
add_to_filemenu, | ||
launch_gui) | ||
import os | ||
import random | ||
import threading | ||
|
||
from .service import EndpointService | ||
from . import lib | ||
from . import service | ||
|
||
gui = None | ||
|
||
show = lib.show | ||
|
||
|
||
def setup(): | ||
"""Setup integration""" | ||
# Underscore prevents makes it less visible from within Maya | ||
|
||
if has_endpoint() and has_frontend(): | ||
setup_endpoint() | ||
setup_frontend() | ||
print "pyblish: Setting up frontend" | ||
else: | ||
pass | ||
|
||
setup_integration() | ||
|
||
|
||
def has_endpoint(): | ||
try: | ||
__import__("pyblish_endpoint.server") | ||
__import__("pyblish_endpoint.service") | ||
except ImportError: | ||
return False | ||
return True | ||
|
||
|
||
def has_frontend(): | ||
try: | ||
__import__("pyblish_qml") | ||
except ImportError: | ||
return False | ||
return True | ||
|
||
|
||
def setup_endpoint(): | ||
import pyblish_endpoint.server | ||
import pyblish_endpoint.service | ||
|
||
# Listen for externally running interfaces | ||
port = random.randint(6000, 7000) | ||
|
||
def server(): | ||
pyblish_endpoint.server.start_production_server( | ||
service=service.MayaService, | ||
port=port) | ||
|
||
worker = threading.Thread(target=server) | ||
worker.daemon = True | ||
worker.start() | ||
|
||
# Store reference to port for frontend(s) | ||
os.environ["ENDPOINT_PORT"] = str(port) | ||
|
||
print "pyblish: Endpoint running @ %i" % port | ||
|
||
|
||
def setup_frontend(): | ||
lib.register_gui("pyblish_qml") | ||
|
||
|
||
def setup_integration(): | ||
lib.register_plugins() | ||
|
||
# If a frontend is installed, it will be added | ||
# to the menu as an option-box. | ||
lib.add_to_filemenu() | ||
print "pyblish: Integration loaded.." |
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
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 |
---|---|---|
@@ -1,40 +1,10 @@ | ||
|
||
INTEGRATION = False | ||
ENDPOINT = False | ||
|
||
try: | ||
import pyblish_maya | ||
INTEGRATION = True | ||
except ImportError as e: | ||
print "Couldn't find pyblish_maya on your PYTHONPATH: ", e | ||
|
||
try: | ||
import pyblish_endpoint.server | ||
ENDPOINT = True | ||
except ImportError as e: | ||
# If Endpoint isn't installed, Maya won't be able to communicate | ||
# with externally running interfaces; such as the QML frontend. | ||
pass | ||
|
||
__import__("pyblish_maya") | ||
|
||
if INTEGRATION: | ||
# Register Maya plugins upon startup | ||
pyblish_maya.register_plugins() | ||
except ImportError: | ||
print "pyblish: Could not load integration" | ||
|
||
if ENDPOINT: | ||
# Listen for externally running interfaces | ||
pyblish_endpoint.server.start(service=pyblish_maya.EndpointService) | ||
|
||
try: | ||
import pyblish_qml | ||
pyblish_maya.register_gui("pyblish_qml") | ||
print "Registing QML GUI" | ||
except ImportError: | ||
pass | ||
|
||
print "Pyblish Endpoint started.." | ||
|
||
# Filemenu will append GUI only if there is an endpoint | ||
# willing to communicate with it. | ||
pyblish_maya.add_to_filemenu() | ||
print "Pyblish integration loaded.." | ||
else: | ||
import pyblish_maya | ||
pyblish_maya.setup() |
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 |
---|---|---|
@@ -1,39 +1,22 @@ | ||
import pyblish.main | ||
import pyblish.api | ||
|
||
# Dependencies | ||
import pyblish_endpoint.service | ||
|
||
from maya import utils | ||
|
||
|
||
class EndpointService(pyblish_endpoint.service.EndpointService): | ||
def instances(self): | ||
return utils.executeInMainThreadWithResult(get_instances) | ||
# def from_main_thread(func): | ||
# """Decorator to make `func` execute from main thread""" | ||
# def wrapper(*args, **kwargs): | ||
# return utils.executeInMainThreadWithResult(func, *args, **kwargs) | ||
# return wrapper | ||
|
||
def publish(self): | ||
return utils.executeInMainThreadWithResult(publish) | ||
|
||
class MayaService(pyblish_endpoint.service.EndpointService): | ||
def init(self, *args, **kwargs): | ||
return utils.executeInMainThreadWithResult( | ||
super(MayaService, self).init, *args, **kwargs) | ||
|
||
def publish(): | ||
pyblish.main.publish() | ||
|
||
|
||
def get_instances(): | ||
ctx = pyblish.api.Context() | ||
plugins = pyblish.api.discover(type="selectors") | ||
|
||
instances = [] | ||
for plugin in plugins: | ||
for inst, err in plugin().process(ctx): | ||
if err is not None: | ||
instances.append({"instance": None, | ||
"message": "Exception occured"}) | ||
|
||
for instance in ctx: | ||
instances.append({ | ||
"instance": instance.name, | ||
"family": instance.data("family") | ||
}) | ||
|
||
return instances | ||
def process(self, *args, **kwargs): | ||
return utils.executeInMainThreadWithResult( | ||
super(MayaService, self).process, *args, **kwargs) |