-
Notifications
You must be signed in to change notification settings - Fork 62
Extensible display_hook #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
th-jyu
wants to merge
5
commits into
shotgunsoftware:master
Choose a base branch
from
Treehouse-Digital:display-hook
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| Hooks | ||
| ===== | ||
|
|
||
| Apart from the core collector and publish plugin hooks and settings, many other | ||
| parts of the publishing process and GUI can be customized by defining and extending | ||
| various hook configurations. The specifications are defined in the ``info.yml`` | ||
| file at the root of the code repository. | ||
|
|
||
|
|
||
| Publishing | ||
| ---------- | ||
|
|
||
| .. code-block:: yaml | ||
| :caption: info.yml | ||
|
|
||
| post_phase: | ||
| type: hook | ||
| description: | ||
| "A hook that defines logic to be executed after each phase of publish | ||
| execution including validation, publish, and finalization. This allows | ||
| for very specific curation and customization of the publish tree | ||
| during a publish session. Serializing the publish tree to disk after | ||
| validation, for example is possible via this hook." | ||
| default_value: "{self}/post_phase.py" | ||
|
|
||
| pre_publish: | ||
| type: hook | ||
| description: | ||
| "This hook defines logic to be executed before showing the publish | ||
| dialog. There may be conditions that need to be checked before allowing | ||
| the user to proceed to publishing." | ||
| default_value: "{self}/pre_publish.py" | ||
|
|
||
| path_info: | ||
| type: hook | ||
| description: | ||
| "This hook contains methods that are used during publishing to infer | ||
| information from file paths. This includes version and frame number | ||
| identification, publish display name, image sequence paths, etc." | ||
| default_value: "{self}/path_info.py" | ||
|
|
||
| thumbnail_generator: | ||
| type: hook | ||
| description: | ||
| "This hook contains methods that are used during publishing to auto | ||
| generate a thumbnail from the file being published." | ||
| default_value: "{self}/thumbnail_generator.py" | ||
|
|
||
| GUI | ||
| --- | ||
|
|
||
| For basic GUI customizations, these configurations can be used/modified: | ||
|
|
||
| .. code-block:: yaml | ||
| :caption: info.yml | ||
|
|
||
| display_name: | ||
| type: str | ||
| default_value: Publish | ||
| description: Specify the name that should be used in menus and the main | ||
| publish dialog | ||
|
|
||
| display_action_name: | ||
| type: str | ||
| default_value: Publish | ||
| description: "Shorter version of display_name setting, used as button name." | ||
|
|
||
|
|
||
| Display Hook and Settings | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. versionadded:: v2.x.x | ||
|
|
||
| When more advanced GUI customizations are needed, the ``display`` configuration | ||
| can be used to extend and customize the display hook and any settings to feed into | ||
| it. | ||
|
|
||
| .. code-block:: yaml | ||
| :caption: info.yml | ||
|
|
||
| display: | ||
| type: dict | ||
| description: Hook and settings that defines how the command/action to | ||
| show the publish dialog is displayed | ||
| items: | ||
| hook: {type: hook} | ||
| settings: {type: dict, allows_empty: True} | ||
| default_value: | ||
| hook: "{self}/display_hook.py" | ||
| settings: {} | ||
|
|
||
| By default, it uses the values from ``display_name`` and ``display_action_name`` | ||
| configurations across various menu text, window title, button label, etc. | ||
|
|
||
| These can all be overridden as much as needed. The ``display:settings`` values | ||
| are free for developers to define and use as they see fit for their custom | ||
| ``display:hook`` implementations. | ||
|
|
||
| Here is an exaggerated simple example where each part are defined via custom | ||
| ``display:settings``, except ``menu_properties()`` which remains inherited from the | ||
| default ``{self}/display_hook.py``. | ||
|
|
||
| .. code-block:: yaml | ||
| :caption: Example tk-config-default2/env/includes/settings/tk-multi-publish2.yml | ||
| :emphasize-lines: 11-19 | ||
|
|
||
| settings.tk-multi-publish2.standalone: | ||
| collector: "{self}/collector.py" | ||
| publish_plugins: | ||
| - name: Publish to Flow Production Tracking | ||
| hook: "{self}/publish_file.py" | ||
| settings: {} | ||
| - name: Upload for review | ||
| hook: "{self}/upload_version.py" | ||
| settings: {} | ||
| help_url: *help_url | ||
| display: | ||
| hook: | ||
| "{self}/display_hook.py\ | ||
| :{config}/hooks/tk-multi-publish2/display_hook.py" | ||
| settings: | ||
| action_name: Verb | ||
| button_name: Click Me | ||
| window_title: I'm Here | ||
| menu_name: Publish Stuff | ||
| location: "@apps.tk-multi-publish2.location" | ||
|
|
||
| .. code-block:: python | ||
| :caption: Example tk-config-default2/hooks/tk-multi-publish2/display_hook.py | ||
|
|
||
| import sgtk | ||
|
|
||
| HookBaseClass = sgtk.get_hook_baseclass() | ||
|
|
||
|
|
||
| class SettingsBasedDisplayHook(HookBaseClass): | ||
| """Hook that defines how the action to show the publish dialog is displayed.""" | ||
|
|
||
| @property | ||
| def action_name(self) -> str: | ||
| """Text (verb) used when referring to the _Publish_ action in the GUI.""" | ||
| return self.settings["action_name"] | ||
|
|
||
| @property | ||
| def button_name(self) -> str: | ||
| """Label text used for the _Publish_ button.""" | ||
| return self.settings["button_name"] | ||
|
|
||
| @property | ||
| def window_title(self) -> str: | ||
| """Window title used for `.Engine.show_modal`/`.Engine.show_dialog`.""" | ||
| return self.settings["window_title"] | ||
|
|
||
| @property | ||
| def menu_name(self) -> str: | ||
| """Command name used when registering the show dialog command to menus.""" | ||
| return self.settings["menu_name"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,3 +106,4 @@ for publish workflow building and customization. | |
| logging | ||
| utility | ||
| application | ||
| hooks | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Copyright (c) 2026 Autodesk. | ||
| # | ||
| # CONFIDENTIAL AND PROPRIETARY | ||
| # | ||
| # This work is provided "AS IS" and subject to the ShotGrid Pipeline Toolkit | ||
| # Source Code License included in this distribution package. See LICENSE. | ||
| # By accessing, using, copying or modifying this work you indicate your | ||
| # agreement to the ShotGrid Pipeline Toolkit Source Code License. All rights | ||
| # not expressly granted therein are reserved by Autodesk. | ||
| """Hook that defines how the command/action to show the publish dialog is displayed. | ||
|
|
||
| The output of methods in this hook are used as follows when calling | ||
| `.sgtk.platform.Application.register_command`:: | ||
|
|
||
| app.register_command( | ||
| app.execute_hook_method("display_hook", "menu_name"), | ||
| ..., | ||
| properties=app.execute_hook_method("display_hook", "menu_properties"), | ||
| ) | ||
| """ | ||
|
|
||
| import os | ||
| import re | ||
| from typing import Any | ||
|
|
||
| import sgtk | ||
|
|
||
| HookBaseClass = sgtk.get_hook_baseclass() | ||
|
|
||
|
|
||
| class DisplayHook(HookBaseClass): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this default implementation be moved into |
||
| """Hook that defines how the action to show the publish dialog is displayed.""" | ||
|
|
||
| @property | ||
| def settings(self) -> dict[str, Any]: | ||
| """Return the settings that are available for this hook.""" | ||
| return self.parent.get_setting("display").get("settings") or {} | ||
|
|
||
| @property | ||
| def action_name(self) -> str: | ||
| """Text (verb) used when referring to the _Publish_ action in the GUI.""" | ||
| return self.parent.get_setting("display_action_name") | ||
|
|
||
| @property | ||
| def button_name(self) -> str: | ||
| """Label text used for the _Publish_ button.""" | ||
| return self.action_name | ||
|
|
||
| @property | ||
| def window_title(self) -> str: | ||
| """Window title used for `.Engine.show_modal`/`.Engine.show_dialog`.""" | ||
| return self.parent.get_setting("display_name") | ||
|
|
||
| @property | ||
| def menu_name(self) -> str: | ||
| """Command name used when registering the show dialog command to menus.""" | ||
| return f"{self.parent.get_setting('display_name')}..." | ||
|
|
||
| @property | ||
| def menu_properties(self) -> dict[str, Any]: | ||
| """Properties used when registering the show dialog command. | ||
|
|
||
| See expected property details at `.sgtk.platform.Application.register_command`. | ||
| """ | ||
| display_name = self.parent.get_setting("display_name") | ||
| command_name = re.sub(r"[^0-9a-zA-Z]+", "_", display_name.lower()) | ||
|
|
||
| return { | ||
| "short_name": command_name, | ||
| "description": "Publishing of data to Flow Production Tracking", | ||
| "icons": { | ||
| "dark": { | ||
| "png": os.path.join(self.parent.disk_location, "icon_256_dark.png") | ||
| } | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Copyright (c) 2026 Autodesk. | ||
| # | ||
| # CONFIDENTIAL AND PROPRIETARY | ||
| # | ||
| # This work is provided "AS IS" and subject to the ShotGrid Pipeline Toolkit | ||
| # Source Code License included in this distribution package. See LICENSE. | ||
| # By accessing, using, copying or modifying this work you indicate your | ||
| # agreement to the ShotGrid Pipeline Toolkit Source Code License. All rights | ||
| # not expressly granted therein are reserved by Autodesk. | ||
| import os | ||
|
|
||
| from publish_api_test_base import PublishApiTestBase | ||
| from tank_test.tank_test_base import setUpModule # noqa | ||
|
|
||
|
|
||
| class TestDisplayHook(PublishApiTestBase): | ||
| def test_attributes_exist(self): | ||
| from sgtk import Hook | ||
|
|
||
| assert hasattr(self.app, "display_hook") | ||
| assert isinstance(self.app.display_hook, Hook) | ||
| for prop in ("action_name", "button_name", "menu_name", "menu_properties"): | ||
| assert hasattr(self.app.display_hook, prop) | ||
|
|
||
| def test_matches_v2_10_7(self): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I update all instances of |
||
| """Test new display hook properties match same values from on v2.10.7 tag. | ||
|
|
||
| This ensures drop-in compatibility with existing code and configurations. | ||
| """ | ||
| app = self.app | ||
|
|
||
| # tk-multi-publish2/app.py:MultiPublish2.init_app() | ||
| from tank.util import sgre as re | ||
|
|
||
| display_name = app.get_setting("display_name") | ||
| command_name = display_name.lower() | ||
| command_name = re.sub(r"[^0-9a-zA-Z]+", "_", command_name) | ||
| menu_caption = "%s..." % display_name | ||
| menu_options = { | ||
| "short_name": command_name, | ||
| "description": "Publishing of data to Flow Production Tracking", | ||
| "icons": { | ||
| "dark": {"png": os.path.join(app.disk_location, "icon_256_dark.png")} | ||
| }, | ||
| } | ||
| # self.engine.register_command(menu_caption, cb, menu_options) | ||
| assert app.display_hook.menu_name == menu_caption | ||
| assert app.display_hook.menu_properties == menu_options | ||
|
|
||
| # tk-multi-publish2/python/tk_multi_publish2/dialog.py:AppDialog.__init__() | ||
| display_action_name = app.get_setting("display_action_name") | ||
| # self._display_action_name = self._bundle.get_setting("display_action_name") | ||
| # self.ui.publish.setText(self._display_action_name) | ||
| assert app.display_hook.action_name == display_action_name | ||
| assert app.display_hook.button_name == display_action_name | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left this as
v2.x.xas I'm not sure how the merge and release process goes from Autodesk's side, but this should be changed prior to release