ayon-core
ayon-core copied to clipboard
Create Context: Per instance attributes and Callbacks
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
- Added one create plugin and one publish plugin that randomly changes what attribute definitions are defined per instance and what are default values.
- Opened traypublisher.
- Created few instances using the creator and multiselect them.
- It should show all of them, and those who have same definitions (except for default value) should be merged into one.
- Changing value on them should work as before.
Callbacks
- We can reuse plugins from previous step.
- Implement
register_callbacks
on create plugin and classmethodregister_create_context_callbacks
on publish plugin. - 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
. - 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 useset_publish_plugin_attr_defs
onCreatedInstance
. To change values of instance just use instance as dictionary.