From 30decaecb71c56a6490d56ec39a007621b4219c4 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 22 Jul 2021 17:24:29 +0200 Subject: [PATCH] added callbacks to be able change labels by current processing item --- openpype/tools/new_publisher/control.py | 31 ++++++++++++++++++++++++- openpype/tools/new_publisher/window.py | 30 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/openpype/tools/new_publisher/control.py b/openpype/tools/new_publisher/control.py index 3922360010..1e42aacbf3 100644 --- a/openpype/tools/new_publisher/control.py +++ b/openpype/tools/new_publisher/control.py @@ -91,6 +91,9 @@ class PublisherController: self._instances_refresh_callback_refs = set() self._plugins_refresh_callback_refs = set() + self._publish_instance_changed_callback_refs = set() + self._publish_plugin_changed_callback_refs = set() + self._publishing_stopped_callback_refs = set() self._resetting_plugins = False self._resetting_instances = False @@ -123,13 +126,25 @@ class PublisherController: ref = weakref.WeakMethod(callback) self._plugins_refresh_callback_refs.add(ref) + def add_instance_change_callback(self, callback): + ref = weakref.WeakMethod(callback) + self._publish_instance_changed_callback_refs.add(ref) + + def add_plugin_change_callback(self, callback): + ref = weakref.WeakMethod(callback) + self._publish_plugin_changed_callback_refs.add(ref) + + def add_publish_stopped_callback(self, callback): + ref = weakref.WeakMethod(callback) + self._publishing_stopped_callback_refs.add(ref) + def _trigger_callbacks(self, callbacks, *args, **kwargs): # Trigger reset callbacks to_remove = set() for ref in callbacks: callback = ref() if callback: - callback() + callback(*args, **kwargs) else: to_remove.add(ref) @@ -272,6 +287,7 @@ class PublisherController: def _stop_publish(self): self._main_thread_processor.stop() + self._trigger_callbacks(self._publishing_stopped_callback_refs) def _publish_next_process(self): item = next(self._main_thread_iter) @@ -285,6 +301,9 @@ class PublisherController: ): yield MainThreadItem(self._stop_publish) + self._trigger_callbacks( + self._publish_plugin_changed_callback_refs, plugin + ) if plugin.__instanceEnabled__: instances = pyblish.logic.instances_by_plugin( self._publish_context, plugin @@ -296,6 +315,11 @@ class PublisherController: if instance.data.get("publish") is False: continue + self._trigger_callbacks( + self._publish_instance_changed_callback_refs, + self._publish_context, + instance + ) yield MainThreadItem( self._process_and_continue, plugin, instance ) @@ -307,6 +331,11 @@ class PublisherController: [plugin], families ) if plugins: + self._trigger_callbacks( + self._publish_instance_changed_callback_refs, + self._publish_context, + None + ) yield MainThreadItem( self._process_and_continue, plugin, None ) diff --git a/openpype/tools/new_publisher/window.py b/openpype/tools/new_publisher/window.py index 327e957774..ce79ed3609 100644 --- a/openpype/tools/new_publisher/window.py +++ b/openpype/tools/new_publisher/window.py @@ -163,6 +163,10 @@ class PublisherWindow(QtWidgets.QWidget): self._on_subset_change ) + controller.add_instance_change_callback(self._on_instance_change) + controller.add_plugin_change_callback(self._on_plugin_change) + controller.add_publish_stopped_callback(self._on_publish_stop) + self.main_frame = main_frame self.overlay_frame = overlay_frame @@ -339,6 +343,32 @@ class PublisherWindow(QtWidgets.QWidget): self.subset_attributes_widget.set_current_instances(instances) + def _on_plugin_change(self, plugin): + plugin_name = plugin.__name__ + if hasattr(plugin, "label") and plugin.label: + plugin_name = plugin.label + self.overlay_frame.set_plugin(plugin_name) + + def _on_instance_change(self, context, instance): + if instance is None: + new_name = ( + context.data.get("label") + or getattr(context, "label", None) + or context.data.get("name") + or "Context" + ) + else: + new_name = ( + instance.data.get("label") + or getattr(instance, "label", None) + or instance.data["name"] + ) + + self.overlay_frame.set_instance(new_name) + + def _on_publish_stop(self): + pass + def main(): """Main function for testing purposes."""