Skip to content

Commit ca97df7

Browse files
committed
Initial extensible display_hook
1 parent 3c60523 commit ca97df7

4 files changed

Lines changed: 102 additions & 21 deletions

File tree

app.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
# By accessing, using, copying or modifying this work you indicate your
88
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
99
# not expressly granted therein are reserved by Shotgun Software Inc.
10-
import os
1110
import sgtk
12-
from tank.util import sgre as re
1311

1412
logger = sgtk.platform.get_logger(__name__)
1513

@@ -40,29 +38,17 @@ def init_app(self):
4038
# make the base plugins available via the app
4139
self._base_hooks = tk_multi_publish2.base_hooks
4240

43-
display_name = self.get_setting("display_name")
44-
# "Publish Render" ---> publish_render
45-
command_name = display_name.lower()
46-
# replace all non alphanumeric characters by '_'
47-
command_name = re.sub(r"[^0-9a-zA-Z]+", "_", command_name)
48-
4941
self.modal = self.get_setting("modal")
5042

5143
pre_publish_hook_path = self.get_setting(self.CONFIG_PRE_PUBLISH_HOOK_PATH)
5244
self.pre_publish_hook = self.create_hook_instance(pre_publish_hook_path)
5345

5446
# register command
55-
cb = lambda: tk_multi_publish2.show_dialog(self)
56-
menu_caption = "%s..." % display_name
57-
menu_options = {
58-
"short_name": command_name,
59-
"description": "Publishing of data to Flow Production Tracking",
60-
# dark themed icon for engines that recognize this format
61-
"icons": {
62-
"dark": {"png": os.path.join(self.disk_location, "icon_256_dark.png")}
63-
},
64-
}
65-
self.engine.register_command(menu_caption, cb, menu_options)
47+
self.engine.register_command(
48+
self.display_hook.menu_name,
49+
lambda: tk_multi_publish2.show_dialog(self),
50+
properties=self.display_hook.menu_properties,
51+
)
6652

6753
@property
6854
def base_hooks(self):
@@ -83,6 +69,19 @@ def base_hooks(self):
8369
"""
8470
return self._base_hooks
8571

72+
@property
73+
def display_hook(self) -> sgtk.Hook:
74+
"""Exposes the extensible ``:display:hook`` instance from app settings.
75+
76+
Used to fetch information related to the display and UI of the app.
77+
"""
78+
self._display_hook = getattr(
79+
self,
80+
"_display_hook",
81+
self.create_hook_instance(self.get_setting("display")["hook"]),
82+
)
83+
return self._display_hook
84+
8685
@property
8786
def util(self):
8887
"""

hooks/display_hook.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright (c) 2026 Autodesk.
2+
#
3+
# CONFIDENTIAL AND PROPRIETARY
4+
#
5+
# This work is provided "AS IS" and subject to the ShotGrid Pipeline Toolkit
6+
# Source Code License included in this distribution package. See LICENSE.
7+
# By accessing, using, copying or modifying this work you indicate your
8+
# agreement to the ShotGrid Pipeline Toolkit Source Code License. All rights
9+
# not expressly granted therein are reserved by Autodesk.
10+
"""Hook that defines how the command/action to show the publish dialog is displayed.
11+
12+
The output of methods in this hook are used as follows when calling
13+
`.sgtk.platform.Application.register_command`::
14+
15+
app.register_command(
16+
app.execute_hook_method("display_hook", "menu_name"),
17+
...,
18+
properties=app.execute_hook_method("display_hook", "menu_properties"),
19+
)
20+
"""
21+
22+
import os
23+
import re
24+
from typing import Any
25+
26+
import sgtk
27+
28+
HookBaseClass = sgtk.get_hook_baseclass()
29+
30+
31+
class DisplayHook(HookBaseClass):
32+
"""Hook that defines how the action to show the publish dialog is displayed."""
33+
34+
@property
35+
def settings(self) -> dict[str, Any]:
36+
"""Return the settings that are available for this hook."""
37+
return self.parent.get_setting("display").get("settings") or {}
38+
39+
@property
40+
def action_name(self) -> str:
41+
"""Create text used when inferring to the "Publish" action in the GUI."""
42+
return self.parent.get_setting("display_action_name")
43+
44+
@property
45+
def button_name(self) -> str:
46+
"""Create the label text used when for "Publish" button."""
47+
return self.action_name
48+
49+
@property
50+
def menu_name(self) -> str:
51+
"""Create the command name used when registering the show dialog command."""
52+
return f"{self.parent.get_setting('display_name')}..."
53+
54+
@property
55+
def menu_properties(self) -> dict[str, Any]:
56+
"""Create the properties used when registering the show dialog command.
57+
58+
See expected property details at `.sgtk.platform.Application.register_command`.
59+
"""
60+
display_name = self.parent.get_setting("display_name")
61+
command_name = re.sub(r"[^0-9a-zA-Z]+", "_", display_name.lower())
62+
63+
return {
64+
"short_name": command_name,
65+
"description": "Publishing of data to Flow Production Tracking",
66+
"icons": {
67+
"dark": {
68+
"png": os.path.join(self.parent.disk_location, "icon_256_dark.png")
69+
}
70+
},
71+
}

info.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ configuration:
1515
description: Specify the name that should be used in menus and the main
1616
publish dialog
1717

18+
display:
19+
type: dict
20+
description: Hook and settings that defines how the command/action to
21+
show the publish dialog is displayed
22+
items:
23+
hook: {type: hook}
24+
settings: {type: dict, allows_empty: True}
25+
default_value:
26+
hook: "{self}/display_hook.py"
27+
settings: {}
28+
1829
display_action_name:
1930
type: str
2031
default_value: Publish

python/tk_multi_publish2/dialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ def __init__(self, parent=None):
281281
self._summary_thumbnail = None
282282

283283
# set publish button text
284-
self._display_action_name = self._bundle.get_setting("display_action_name")
285-
self.ui.publish.setText(self._display_action_name)
284+
self._display_action_name = self._bundle.display_hook.action_name
285+
self.ui.publish.setText(self._bundle.display_hook.button_name)
286286

287287
# Special UI tweaks based on the 'manual_load_enabled' property
288288
#

0 commit comments

Comments
 (0)