diff --git a/pyblish_qml/api.py b/pyblish_qml/api.py index b9c25c6d..5ea1444e 100644 --- a/pyblish_qml/api.py +++ b/pyblish_qml/api.py @@ -3,6 +3,8 @@ deregister_dispatch_wrapper, dispatch_wrapper, current_server, + current_context, + current_targets, register_pyqt5, register_python_executable, uninstall, @@ -15,6 +17,8 @@ "deregister_dispatch_wrapper", "dispatch_wrapper", "current_server", + "current_context", + "current_targets", "register_pyqt5", "register_python_executable", "install", diff --git a/pyblish_qml/app.py b/pyblish_qml/app.py index c5a12b42..4dfc893d 100644 --- a/pyblish_qml/app.py +++ b/pyblish_qml/app.py @@ -68,13 +68,11 @@ class Application(QtGui.QGuiApplication): published = QtCore.Signal() validated = QtCore.Signal() - targeted = QtCore.Signal("QVariant") - risen = QtCore.Signal() inFocused = QtCore.Signal() outFocused = QtCore.Signal() - def __init__(self, source, targets=None): + def __init__(self, source): super(Application, self).__init__(sys.argv) self.setWindowIcon(QtGui.QIcon(ICON_PATH)) @@ -86,7 +84,8 @@ def __init__(self, source, targets=None): engine.addImportPath(QML_IMPORT_DIR) host = ipc.client.Proxy() - controller = control.Controller(host, targets=targets, parent=window) + + controller = control.Controller(host) controller.finished.connect(lambda: window.alert(0)) context = engine.rootContext() @@ -105,8 +104,6 @@ def __init__(self, source, targets=None): 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) @@ -225,9 +222,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 @@ -254,8 +248,6 @@ def _listen(): "publish": "published", "validate": "validated", - "target": "targeted", - "rise": "risen", "inFocus": "inFocused", "outFocus": "outFocused", @@ -288,7 +280,7 @@ def main(demo=False, aschild=False, targets=None): 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()`") diff --git a/pyblish_qml/control.py b/pyblish_qml/control.py index 8885dc2a..bbb87036 100644 --- a/pyblish_qml/control.py +++ b/pyblish_qml/control.py @@ -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=None): + def __init__(self, host, parent=None): super(Controller, self).__init__(parent) # Connection to host self.host = host - self.targets = targets or [] - self.data = { "models": { "item": models.ItemModel(), @@ -853,11 +851,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()) @@ -880,7 +873,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()) diff --git a/pyblish_qml/host.py b/pyblish_qml/host.py index 8c05e22e..ab457237 100644 --- a/pyblish_qml/host.py +++ b/pyblish_qml/host.py @@ -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""" @@ -114,10 +126,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 targets - proxy.target(targets) proxy.show(show_settings) return server diff --git a/pyblish_qml/ipc/client.py b/pyblish_qml/ipc/client.py index f13d65b5..3a6a6194 100644 --- a/pyblish_qml/ipc/client.py +++ b/pyblish_qml/ipc/client.py @@ -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]) diff --git a/pyblish_qml/ipc/formatting.py b/pyblish_qml/ipc/formatting.py index 0c8765d8..d36d3b83 100644 --- a/pyblish_qml/ipc/formatting.py +++ b/pyblish_qml/ipc/formatting.py @@ -194,6 +194,10 @@ def format_context(context): } +def format_targets(targets): + return ", ".join(targets) + + def format_plugins(plugins): """Serialise multiple plug-in diff --git a/pyblish_qml/ipc/server.py b/pyblish_qml/ipc/server.py index 0feb08d8..205f424e 100644 --- a/pyblish_qml/ipc/server.py +++ b/pyblish_qml/ipc/server.py @@ -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( { @@ -202,8 +199,9 @@ def __init__(self, kwargs["creationflags"] = CREATE_NO_WINDOW 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) diff --git a/pyblish_qml/ipc/service.py b/pyblish_qml/ipc/service.py index 9f8354d5..d93ba253 100644 --- a/pyblish_qml/ipc/service.py +++ b/pyblish_qml/ipc/service.py @@ -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) @@ -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) @@ -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