Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor 'targets' internal control #351

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyblish_qml/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
deregister_dispatch_wrapper,
dispatch_wrapper,
current_server,
current_context,
current_targets,
register_pyqt5,
register_python_executable,
uninstall,
Expand All @@ -15,6 +17,8 @@
"deregister_dispatch_wrapper",
"dispatch_wrapper",
"current_server",
"current_context",
"current_targets",
"register_pyqt5",
"register_python_executable",
"install",
Expand Down
15 changes: 3 additions & 12 deletions pyblish_qml/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ class Application(QtGui.QGuiApplication):
published = QtCore.pyqtSignal()
validated = QtCore.pyqtSignal()

targeted = QtCore.pyqtSignal(QtCore.QVariant)

risen = QtCore.pyqtSignal()
inFocused = QtCore.pyqtSignal()
outFocused = QtCore.pyqtSignal()

def __init__(self, source, targets=[]):
def __init__(self, source):
super(Application, self).__init__(sys.argv)

self.setWindowIcon(QtGui.QIcon(ICON_PATH))
Expand All @@ -88,7 +86,7 @@ def __init__(self, source, targets=[]):
engine.addImportPath(QML_IMPORT_DIR)

host = ipc.client.Proxy()
controller = control.Controller(host, targets=targets)
controller = control.Controller(host)
controller.finished.connect(lambda: window.alert(0))

context = engine.rootContext()
Expand All @@ -107,8 +105,6 @@ def __init__(self, source, targets=[]):
self.published.connect(self.publish)
self.validated.connect(self.validate)

self.targeted.connect(self.target)

self.risen.connect(self.rise)
self.inFocused.connect(self.inFocus)
self.outFocused.connect(self.outFocus)
Expand Down Expand Up @@ -229,9 +225,6 @@ def validate(self):
"""Fire up the validation sequance"""
self.controller.validate()

def target(self, targets):
self.controller.targets = targets

def listen(self):
"""Listen on incoming messages from host

Expand All @@ -258,8 +251,6 @@ def _listen():
"publish": "published",
"validate": "validated",

"target": "targeted",

"rise": "risen",
"inFocus": "inFocused",
"outFocus": "outFocused",
Expand Down Expand Up @@ -292,7 +283,7 @@ def main(demo=False, aschild=False, targets=[]):
if aschild:
print("Starting pyblish-qml")
compat.main()
app = Application(APP_PATH, targets)
app = Application(APP_PATH)
app.listen()

print("Done, don't forget to call `show()`")
Expand Down
11 changes: 2 additions & 9 deletions pyblish_qml/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ class Controller(QtCore.QObject):
resultModel = qtproperty(lambda self: self.data["models"]["result"])
resultProxy = qtproperty(lambda self: self.data["proxies"]["result"])

def __init__(self, host, parent=None, targets=[]):
def __init__(self, host, parent=None):
super(Controller, self).__init__(parent)

# Connection to host
self.host = host

self.targets = targets

self.data = {
"models": {
"item": models.ItemModel(),
Expand Down Expand Up @@ -843,11 +841,6 @@ def on_run(plugins):
def on_discover(plugins, context):
collectors = list()

# For backwards compatibility check for existance of
# "plugins_by_targets" method.
if hasattr(pyblish.api, "plugins_by_targets"):
plugins = pyblish.api.plugins_by_targets(plugins, self.targets)

for plugin in plugins:
self.data["models"]["item"].add_plugin(plugin.to_json())

Expand All @@ -870,7 +863,7 @@ def on_discover(plugins, context):

def on_context(context):
context.data["pyblishQmlVersion"] = version
context.data["targets"] = ", ".join(self.targets)
context.data["targets"] = self.host.targets()

self.data["models"]["item"].add_context(context.to_json())
self.data["models"]["result"].add_context(context.to_json())
Expand Down
16 changes: 14 additions & 2 deletions pyblish_qml/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ def current_server():
return _state.get("currentServer")


def current_context():
server = current_server()
if server:
return server.service._context


def current_targets():
server = current_server()
if server:
return list(server.service._targets)


def install(modal):
"""Perform first time install"""

Expand Down Expand Up @@ -108,10 +120,10 @@ def show(parent=None,
if _state.get("currentServer"):
server = _state["currentServer"]
proxy = ipc.server.Proxy(server)
# Update target
server.service.set_targets(targets)

try:
# Update target
proxy.target(targets)
proxy.show(show_settings)
return server

Expand Down
3 changes: 3 additions & 0 deletions pyblish_qml/ipc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def discover(self):

return self.cached_discover

def targets(self):
return self._dispatch("targets")

def emit(self, signal, **kwargs):
self._dispatch("emit", args=[signal, kwargs])

Expand Down
4 changes: 4 additions & 0 deletions pyblish_qml/ipc/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def format_context(context):
}


def format_targets(targets):
return ", ".join(targets)


def format_plugins(plugins):
"""Serialise multiple plug-in

Expand Down
7 changes: 2 additions & 5 deletions pyblish_qml/ipc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ def publish(self):
def validate(self):
self._dispatch("validate")

def target(self, targets):
self._dispatch("target", args=[targets])

def _dispatch(self, func, args=None):
data = json.dumps(
{
Expand Down Expand Up @@ -209,8 +206,8 @@ def __init__(self,
targets = ["default"] + pyblish.api.registered_targets()
print("Targets: {0}".format(", ".join(targets)))

kwargs["args"].append("--targets")
kwargs["args"].extend(targets)
self.service.set_targets(targets)
self.service.reset()

self.popen = subprocess.Popen(**kwargs)

Expand Down
15 changes: 13 additions & 2 deletions pyblish_qml/ipc/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ class Service(object):

def __init__(self):
self._context = None
self._targets = None
self._plugins = None
self._provider = None

self.reset()

def test(self, vars):
test = pyblish.logic.registered_test()
return test(**vars)
Expand All @@ -52,6 +51,11 @@ def reset(self):
self._plugins = pyblish.api.discover()
self._provider = pyblish.plugin.Provider()

# Plugins by Target, pyblish-base>=1.5.0
if hasattr(pyblish.api, "plugins_by_targets"):
self._plugins = pyblish.api.plugins_by_targets(self._plugins,
self._targets)

def context(self):
# Append additional metadata to context
port = os.environ.get("PYBLISH_CLIENT_PORT", -1)
Expand All @@ -71,6 +75,13 @@ def context(self):
def discover(self):
return formatting.format_plugins(self._plugins)

def targets(self):
# Only called on reset
return formatting.format_targets(self._targets)

def set_targets(self, targets):
self._targets = targets

def process(self, plugin, instance=None, action=None):
"""Given JSON objects from client, perform actual processing

Expand Down