mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 08:54:53 +01:00
added callbacks to be able change labels by current processing item
This commit is contained in:
parent
3178af7cad
commit
30decaecb7
2 changed files with 60 additions and 1 deletions
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue