Skip to content

Commit d926ae5

Browse files
committed
Initial work
1 parent 51cee41 commit d926ae5

5 files changed

Lines changed: 197 additions & 45 deletions

File tree

hooks/summary_hook.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 the summary overlay content and display details."""
11+
12+
from typing import Any
13+
14+
import sgtk
15+
16+
HookBaseClass = sgtk.get_hook_baseclass()
17+
18+
19+
class SummaryHook(HookBaseClass):
20+
"""Hook that defines the summary overlay content and display details."""
21+
22+
@property
23+
def settings(self) -> dict[str, Any]:
24+
"""Return the settings that are available for this hook."""
25+
return self.parent.get_setting("summary").get("settings") or {}
26+
27+
def no_items_error(self, summary_overlay) -> dict[str, Any]:
28+
"""Return UI values for the no items collected summary state."""
29+
return summary_overlay.show_summary(
30+
":/tk_multi_publish2/publish_failed.png",
31+
# Hardcoding line break so the message displays on 2 lines.
32+
# Usage of label's own word wrap displays the message below on 3 lines.
33+
# NOTE: Can't manually break line when using <p></p>
34+
"Could not find any\nitems to publish.",
35+
"For more details, <b><u>click here</u></b>.",
36+
)
37+
38+
def success(self, summary_overlay) -> dict[str, Any]:
39+
"""Return UI values for the publish success summary state."""
40+
return summary_overlay.show_summary(
41+
":/tk_multi_publish2/publish_complete.png",
42+
"Publish\nComplete",
43+
"For more details, <b><u>click here</u></b>.",
44+
publish_again_text="To publish again, <b><u>click here</u></b>.",
45+
)
46+
47+
def fail(self, summary_overlay) -> dict[str, Any]:
48+
"""Return UI values for the publish fail summary state."""
49+
return summary_overlay.show_summary(
50+
":/tk_multi_publish2/publish_failed.png",
51+
"Publish\nFailed!",
52+
"For more details, <b><u>click here</u></b>.",
53+
)
54+
55+
def loading(self, summary_overlay) -> dict[str, Any]:
56+
"""Return UI values for the loading summary state."""
57+
return summary_overlay.show_summary(
58+
":/tk_multi_publish2/overlay_loading.png",
59+
"Loading and processing",
60+
"Hold tight while we analyze your data",
61+
)

info.yml

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

18-
summary:
19-
type: dict
20-
description: Hook and settings that defines how the summary overlay is displayed
21-
items:
22-
hook: {type: hook}
23-
settings: {type: dict, allows_empty: True}
24-
default_value:
25-
hook: "{self}/summary_hook.py"
26-
settings:
27-
28-
2918
display_action_name:
3019
type: str
3120
default_value: Publish
@@ -41,6 +30,16 @@ configuration:
4130
description: "Collector-specific configuration settings."
4231
default_value: {}
4332

33+
summary:
34+
type: dict
35+
description: Hook and settings that defines how the summary overlay is displayed
36+
items:
37+
hook: {type: hook}
38+
settings: {type: dict, allows_empty: True}
39+
default_value:
40+
hook: "{self}/summary_hook.py"
41+
settings: {}
42+
4443
post_phase:
4544
type: hook
4645
description:

python/tk_multi_publish2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from . import base_hooks # noqa
1515
from . import util # noqa
1616
from . import publish_tree_widget # noqa
17+
from . import summary_overlay # noqa
1718

1819

1920
def show_dialog(app):

python/tk_multi_publish2/summary_overlay.py

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, parent):
3838
super().__init__(parent)
3939

4040
self._bundle = sgtk.platform.current_bundle()
41+
self._summary_hook = self._bundle.summary_hook
4142

4243
# set up the UI
4344
self.ui = Ui_SummaryOverlay()
@@ -54,60 +55,54 @@ def __init__(self, parent):
5455
self.ui.info.clicked.connect(self.info_clicked.emit)
5556
self.ui.publish_again.clicked.connect(self.publish_again_clicked.emit)
5657

58+
def show_summary(
59+
self,
60+
icon_path: str,
61+
label_text: str,
62+
info_text: str,
63+
publish_again_text: str = "",
64+
):
65+
"""Show summary with given messaging and icon.
66+
67+
:param icon_path: Path/value used directly to construct icon's QPixmap.
68+
:param label_text: Main label text to display
69+
:param info_text: Information text for the info button/label
70+
:param publish_again_text: Text to show the publish again button with.
71+
If empty (default) the button will be hidden.
72+
"""
73+
self.ui.icon.setPixmap(QtGui.QPixmap(icon_path))
74+
self.ui.label.setText(label_text)
75+
self.ui.info.setText(info_text)
76+
77+
self.ui.publish_again.setText(publish_again_text or "")
78+
self.ui.publish_again.setVisible(bool(publish_again_text))
79+
80+
self.show()
81+
5782
def show_no_items_error(self):
5883
"""
5984
Shows a special message when there is no items collected under an alternate
6085
UI operation determined by the 'enable_manual_load' application option.
6186
"""
62-
self.ui.icon.setPixmap(QtGui.QPixmap(":/tk_multi_publish2/publish_failed.png"))
63-
# Hardcoding line break so the message displays on 2 lines.
64-
# Usage of label's own word wrap displays the message below on 3 lines.
65-
# NOTE: Can't manually break line when using <p></p>
66-
self.ui.label.setText("Could not find any\nitems to publish.")
67-
self.ui.info.setText("For more details, <b><u>click here</u></b>.")
68-
self.ui.publish_again.hide()
69-
self.show()
87+
self._summary_hook.no_items_error(self)
7088

7189
def show_success(self):
7290
"""
7391
Shows standard "publish completed successfully!" prompt
7492
"""
75-
self.ui.icon.setPixmap(
76-
QtGui.QPixmap(":/tk_multi_publish2/publish_complete.png")
77-
)
78-
self.ui.label.setText("Publish\nComplete")
79-
self.ui.info.setText("For more details, <b><u>click here</u></b>.")
80-
81-
self.ui.publish_again.setText("To publish again, <b><u>click here</u></b>.")
82-
self.ui.publish_again.show()
83-
84-
self.show()
93+
self._summary_hook.success(self)
8594

8695
def show_fail(self):
8796
"""
8897
Shows standard "publish failed!" prompt
8998
"""
90-
self.ui.icon.setPixmap(QtGui.QPixmap(":/tk_multi_publish2/publish_failed.png"))
91-
self.ui.label.setText("Publish\nFailed!")
92-
self.ui.info.setText("For more details, <b><u>click here</u></b>.")
93-
94-
self.ui.publish_again.hide()
95-
self.ui.publish_again.setText("")
96-
97-
self.show()
99+
self._summary_hook.fail(self)
98100

99101
def show_loading(self):
100102
"""
101103
Shows standard "loading stuff" prompt
102104
"""
103-
self.ui.icon.setPixmap(QtGui.QPixmap(":/tk_multi_publish2/overlay_loading.png"))
104-
self.ui.label.setText("Loading and processing")
105-
self.ui.info.setText("Hold tight while we analyze your data")
106-
107-
self.ui.publish_again.hide()
108-
self.ui.publish_again.setText("")
109-
110-
self.show()
105+
self._summary_hook.loading(self)
111106

112107
def show(self):
113108
"""

tests/test_summary_hook.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
11+
from unittest import mock
12+
13+
from publish_api_test_base import PublishApiTestBase
14+
from tank_test.tank_test_base import setUpModule # noqa
15+
16+
17+
class TestSummaryHook(PublishApiTestBase):
18+
def check_values_match_v2_10_7(self, summary_method, expected_args):
19+
"""Test that calling method sets expected values."""
20+
from sgtk.platform.qt import QtGui
21+
22+
publish2 = self.app.import_module("tk_multi_publish2")
23+
widget = publish2.summary_overlay.SummaryOverlay(QtGui.QWidget())
24+
with (
25+
mock.patch.object(widget, "show"),
26+
mock.patch.object(QtGui, "QPixmap"),
27+
mock.patch.object(widget.ui.icon, "setPixmap"),
28+
mock.patch.object(widget.ui.label, "setText"),
29+
mock.patch.object(widget.ui.info, "setText"),
30+
mock.patch.object(widget.ui.publish_again, "setText"),
31+
mock.patch.object(widget.ui.publish_again, "setVisible"),
32+
):
33+
patched_methods_expected_args = zip(
34+
[
35+
QtGui.QPixmap,
36+
widget.ui.label.setText,
37+
widget.ui.info.setText,
38+
widget.ui.publish_again.setText,
39+
widget.ui.publish_again.setVisible,
40+
],
41+
expected_args,
42+
)
43+
44+
getattr(self.app.summary_hook, summary_method)(widget)
45+
46+
assert widget.ui.icon.setPixmap.called
47+
for patched_method, expected_arg in patched_methods_expected_args:
48+
patched_method.assert_called_with(expected_arg)
49+
50+
def test_no_item_error(self):
51+
self.check_values_match_v2_10_7(
52+
"no_items_error",
53+
[
54+
":/tk_multi_publish2/publish_failed.png",
55+
"Could not find any\nitems to publish.",
56+
"For more details, <b><u>click here</u></b>.",
57+
"",
58+
False,
59+
],
60+
)
61+
62+
def test_success(self):
63+
self.check_values_match_v2_10_7(
64+
"success",
65+
[
66+
":/tk_multi_publish2/publish_complete.png",
67+
"Publish\nComplete",
68+
"For more details, <b><u>click here</u></b>.",
69+
"To publish again, <b><u>click here</u></b>.",
70+
True,
71+
],
72+
)
73+
74+
def test_fail(self):
75+
self.check_values_match_v2_10_7(
76+
"fail",
77+
[
78+
":/tk_multi_publish2/publish_failed.png",
79+
"Publish\nFailed!",
80+
"For more details, <b><u>click here</u></b>.",
81+
"",
82+
False,
83+
],
84+
)
85+
86+
def test_loading(self):
87+
self.check_values_match_v2_10_7(
88+
"loading",
89+
[
90+
":/tk_multi_publish2/overlay_loading.png",
91+
"Loading and processing",
92+
"Hold tight while we analyze your data",
93+
"",
94+
False,
95+
],
96+
)

0 commit comments

Comments
 (0)