Skip to content

Create Context: Per instance attributes and Callbacks#935

Merged
iLLiCiTiT merged 115 commits intodevelopfrom
enhancement/AY-2420_Callbacks-and-groups-with-Publisher-attributes
Oct 21, 2024
Merged

Create Context: Per instance attributes and Callbacks#935
iLLiCiTiT merged 115 commits intodevelopfrom
enhancement/AY-2420_Callbacks-and-groups-with-Publisher-attributes

Conversation

@iLLiCiTiT
Copy link
Copy Markdown
Member

@iLLiCiTiT iLLiCiTiT commented Oct 3, 2024

Changelog Description

Create context now allows to define attribute definitions per instance and allows to register callbacks listening to changes (e.g. on instances).

Additional info

Create plugin can define different attribute definitions on each instance, for example only different default values using get_attr_defs_for_instance. Publish plugins can define attribute definitions for any instance, and both instance and context plugins can define attribute definitions for both instances and context, so context plugin can define attribute definitions for instances. That can be achieved by implementing get_attr_defs_for_instance abd get_attribute_defs_for_context. Everything should be backwards compatible and work as before this PR.

Added callbacks allow to do adhoc live changes. That allows to create/publish plugin to change attribute definitions when a value changes. There is almost no limit to this usage. For example when a folder and task of instance A changes it is possible to propagate the same change to instances B, C, D. When create attribute changes value, publish attribute can be hidden or shown again. Registered callbacks are reset on each reset of CreateContext.

To register callbacks use listen_to_added_instances, listen_to_removed_instances, listen_to_value_changes, listen_to_pre_create_attr_defs_change, listen_to_create_attr_defs_change, listen_to_publish_attr_defs_change on CreateContext. To change create attributes use set_create_attr_defs, to update publish attributes use set_publish_plugin_attr_defs on CreatedInstance and to update context publish attributes use set_context_publish_plugin_attr_defs on CreateContext .

Callbacks are not targeted to the plugin, so plugin has to filter out what is relevant for him, if anything is relevant.

NOTE it is possible, but has caviads, the plugins must care that everything is set up correctly when they decide they do it. For example when enum will rename one value it should make sure the value kept selected on instances that did have it selected.

Also note that callbacks should not be used to live propagation to scene. The changes can be reverted if save_changes is not called on CreateContext.

Dev note

I did a lot of changes on the fly and maybe forgot some lines that might not be necessary or are undocumented, if you find those please comment in the code. I will try to cleanup it and fill in docstrings, but it won't hurt me if you mark something as "unclear", "confusing", "unnecessary". Any suggestions welcommed.

Traypublisher

Traypublisher is making issues at this moment as it changes window behavior and is using controller methods that should be removed but can't. We should remove option to change project in traypublisher and instead allow to change project only on start.

Testing notes

All changes are important mainly for publisher UI, so please choose DCC/host of your preference and use publisher.

All existing plugins should work as before.

None of new features are use in code so it requires to implement them to test hem out. If you'll find a plugin in ayon core that would benefit from these changes, we can change it in this PR as example.

This opens a lot of possibilities, so I need creative approaches and real life use-cases to be applied with this PR more than fake testing.

My testing steps using fake plugins

All tests were done in traypublisher.

Per instance attribute definitions

  1. Added one create plugin and one publish plugin that randomly changes what attribute definitions are defined per instance and what are default values.
  2. Opened traypublisher.
  3. Created few instances using the creator and multiselect them.
  4. It should show all of them, and those who have same definitions (except for default value) should be merged into one.
  5. Changing value on them should work as before.

Callbacks

  1. We can reuse plugins from previous step.
  2. Implement register_callbacks on create plugin and classmethod register_create_context_callbacks on publish plugin.
  3. Register callbacks based on you usage, you can use methods on create context listen_to_added_instances, listen_to_removed_instances, listen_to_value_changes, listen_to_pre_create_attr_defs_change, listen_to_create_attr_defs_change, listen_to_publish_attr_defs_change.
  4. In you're callback you should be able to change attribute definitions or values of attributes on existin instances. You can also trigger refresh of pre-create attributes if needed. To change create attributes use set_create_attr_defs, to update publish attributes use set_publish_plugin_attr_defs on CreatedInstance. To change values of instance just use instance as dictionary.

Resolves #133
Resoves ynput/ayon-deadline#55

iLLiCiTiT and others added 30 commits August 19, 2024 18:29
…er-instance

# Conflicts:
#	client/ayon_core/pipeline/create/structures.py
@iLLiCiTiT
Copy link
Copy Markdown
Member Author

iLLiCiTiT commented Oct 9, 2024

Now it should be able to handle edge cases, maybe not "the nicest and clearest way", but it is possible. I would not bother until we hit issues related to that.

I had to add some implementations to attribute definitions to make it possible.

@iLLiCiTiT
Copy link
Copy Markdown
Member Author

Issue reported by @BigRoy . Publish buttons are disabled after reset, seems like it is related to instance context validation.

@iLLiCiTiT
Copy link
Copy Markdown
Member Author

iLLiCiTiT commented Oct 14, 2024

Discovered few more issues. Labels of instances were not updating and change of active state on instances was not propagated. Should be resolved now.

Copy link
Copy Markdown
Collaborator

@BigRoy BigRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good now - seems to work.

Except I'm not seeing any Context attributes anymore.
Going to the Context entry I get this error:

# Traceback (most recent call last):
#   File "F:\dev\ayon-core\client\ayon_core\tools\publisher\widgets\overview_widget.py", line 303, in _on_product_change
#     self._product_attributes_widget.set_current_instances(
#   File "F:\dev\ayon-core\client\ayon_core\tools\publisher\widgets\product_info.py", line 167, in set_current_instances
#     self._refresh_instances()
#   File "F:\dev\ayon-core\client\ayon_core\tools\publisher\widgets\product_info.py", line 191, in _refresh_instances
#     self.publish_attrs_widget.set_current_instances(
#   File "F:\dev\ayon-core\client\ayon_core\tools\publisher\widgets\product_attributes.py", line 246, in set_current_instances
#     self._refresh_content()
#   File "F:\dev\ayon-core\client\ayon_core\tools\publisher\widgets\product_attributes.py", line 261, in _refresh_content
#     result = self._controller.get_publish_attribute_definitions(
#              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "F:\dev\ayon-core\client\ayon_core\tools\publisher\control.py", line 424, in get_publish_attribute_definitions
#     return self._create_model.get_publish_attribute_definitions(
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "F:\dev\ayon-core\client\ayon_core\tools\publisher\models\create.py", line 861, in get_publish_attribute_definitions
#     attr_defs = attr_val.attr_defs
#                 ^^^^^^^^^^^^^^^^^^
# AttributeError: 'dict' object has no attribute 'attr_defs'

In both Maya 2025.3 and Fusion 18.

image

Other than that all the labels updating and instance variant name changing seem to update just fine - and of course the live toggling of attributes works fine for instances, etc.

@iLLiCiTiT
Copy link
Copy Markdown
Member Author

Should be fixed.

Copy link
Copy Markdown
Collaborator

@BigRoy BigRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely work - PR works for me. ❤️

@iLLiCiTiT iLLiCiTiT added type: feature Adding something new and exciting to the product and removed type: enhancement Improvement of existing functionality or minor addition labels Oct 21, 2024
Copy link
Copy Markdown
Member

@antirotor antirotor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works, tested in a bunch of hosts like 3dequalizer and 3dsmax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XXL type: feature Adding something new and exciting to the product

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Enhancement: Callbacks and groups with Publisher attributes

6 participants