Skip to content

Commit ff2bff3

Browse files
committed
Tidied
1 parent d926ae5 commit ff2bff3

3 files changed

Lines changed: 116 additions & 67 deletions

File tree

hooks/summary_hook.py

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,67 @@
1919
class SummaryHook(HookBaseClass):
2020
"""Hook that defines the summary overlay content and display details."""
2121

22+
FALLBACK_SETTINGS = {
23+
"no_item_error": {
24+
"icon_path": ":/tk_multi_publish2/publish_failed.png",
25+
# Hardcoding line break so the message displays on 2 lines.
26+
# Usage of label's own word wrap displays the message below on 3 lines.
27+
# NOTE: Can't manually break line when using <p></p>
28+
"label_text": "Could not find any\nitems to publish.",
29+
"info_text": "For more details, <b><u>click here</u></b>.",
30+
"publish_again_text": "",
31+
},
32+
"success": {
33+
"icon_path": ":/tk_multi_publish2/publish_complete.png",
34+
"label_text": "Publish\nComplete",
35+
"info_text": "For more details, <b><u>click here</u></b>.",
36+
"publish_again_text": "To publish again, <b><u>click here</u></b>.",
37+
},
38+
"fail": {
39+
"icon_path": ":/tk_multi_publish2/publish_failed.png",
40+
"label_text": "Publish\nFailed!",
41+
"info_text": "For more details, <b><u>click here</u></b>.",
42+
"publish_again_text": "",
43+
},
44+
"loading": {
45+
"icon_path": ":/tk_multi_publish2/overlay_loading.png",
46+
"label_text": "Loading and processing",
47+
"info_text": "Hold tight while we analyze your data",
48+
"publish_again_text": "",
49+
},
50+
}
51+
"""Fallback settings to use for `.show_using_settings`, uses v2.10.7 values."""
52+
2253
@property
2354
def settings(self) -> dict[str, Any]:
2455
"""Return the settings that are available for this hook."""
2556
return self.parent.get_setting("summary").get("settings") or {}
2657

27-
def no_items_error(self, summary_overlay) -> dict[str, Any]:
58+
def show_using_settings(self, key, summary_overlay) -> dict[str, Any]:
2859
"""Return UI values for the no items collected summary state."""
60+
settings = self.settings.get(key, {})
61+
fallback = self.FALLBACK_SETTINGS.get(key, {})
2962
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>.",
63+
settings.get("icon_path", fallback["icon_path"]),
64+
settings.get("label_text", fallback["label_text"]),
65+
settings.get("info_text", fallback["info_text"]),
66+
publish_again_text=settings.get(
67+
"publish_again_text", fallback["publish_again_text"]
68+
),
3669
)
3770

71+
def no_items_error(self, summary_overlay) -> dict[str, Any]:
72+
"""Return UI values for the no items collected summary state."""
73+
return self.show_using_settings("no_item_error", summary_overlay)
74+
3875
def success(self, summary_overlay) -> dict[str, Any]:
3976
"""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-
)
77+
return self.show_using_settings("success", summary_overlay)
4678

4779
def fail(self, summary_overlay) -> dict[str, Any]:
4880
"""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-
)
81+
return self.show_using_settings("fail", summary_overlay)
5482

5583
def loading(self, summary_overlay) -> dict[str, Any]:
5684
"""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-
)
85+
return self.show_using_settings("loading", summary_overlay)

info.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,33 @@ configuration:
3838
settings: {type: dict, allows_empty: True}
3939
default_value:
4040
hook: "{self}/summary_hook.py"
41-
settings: {}
41+
settings:
42+
no_item_error:
43+
icon_path: ":/tk_multi_publish2/publish_failed.png"
44+
label_text: |
45+
Could not find any
46+
items to publish.
47+
info_text: "For more details, <b><u>click here</u></b>."
48+
publish_again_text: ""
49+
success:
50+
icon_path: ":/tk_multi_publish2/publish_complete.png"
51+
label_text: |
52+
Publish
53+
Complete
54+
info_text: "For more details, <b><u>click here</u></b>."
55+
publish_again_text: "To publish again, <b><u>click here</u></b>."
56+
fail:
57+
icon_path: ":/tk_multi_publish2/publish_failed.png"
58+
label_text: |
59+
Publish
60+
Failed!
61+
info_text: "For more details, <b><u>click here</u></b>."
62+
publish_again_text: ""
63+
loading:
64+
icon_path: ":/tk_multi_publish2/overlay_loading.png"
65+
label_text: "Loading and processing"
66+
info_text: "Hold tight while we analyze your data"
67+
publish_again_text: ""
4268

4369
post_phase:
4470
type: hook
Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
# agreement to the ShotGrid Pipeline Toolkit Source Code License. All rights
99
# not expressly granted therein are reserved by Autodesk.
1010

11+
from contextlib import contextmanager
1112
from unittest import mock
1213

1314
from publish_api_test_base import PublishApiTestBase
1415
from tank_test.tank_test_base import setUpModule # noqa
1516

1617

17-
class TestSummaryHook(PublishApiTestBase):
18-
def check_values_match_v2_10_7(self, summary_method, expected_args):
18+
class TestSummaryOverlay(PublishApiTestBase):
19+
@contextmanager
20+
def check_values_match_v2_10_7(self, expected_args):
1921
"""Test that calling method sets expected values."""
2022
from sgtk.platform.qt import QtGui
2123

@@ -41,56 +43,53 @@ def check_values_match_v2_10_7(self, summary_method, expected_args):
4143
expected_args,
4244
)
4345

44-
getattr(self.app.summary_hook, summary_method)(widget)
46+
yield widget
4547

48+
assert widget.show.called
4649
assert widget.ui.icon.setPixmap.called
4750
for patched_method, expected_arg in patched_methods_expected_args:
4851
patched_method.assert_called_with(expected_arg)
4952

5053
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-
)
54+
v2_10_7_values = [
55+
":/tk_multi_publish2/publish_failed.png",
56+
"Could not find any\nitems to publish.",
57+
"For more details, <b><u>click here</u></b>.",
58+
"",
59+
False,
60+
]
61+
with self.check_values_match_v2_10_7(v2_10_7_values) as summary_overlay:
62+
summary_overlay.show_no_items_error()
6163

6264
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-
)
65+
v2_10_7_values = [
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+
with self.check_values_match_v2_10_7(v2_10_7_values) as summary_overlay:
73+
summary_overlay.show_success()
7374

7475
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-
)
76+
v2_10_7_values = [
77+
":/tk_multi_publish2/publish_failed.png",
78+
"Publish\nFailed!",
79+
"For more details, <b><u>click here</u></b>.",
80+
"",
81+
False,
82+
]
83+
with self.check_values_match_v2_10_7(v2_10_7_values) as summary_overlay:
84+
summary_overlay.show_fail()
8585

8686
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-
)
87+
v2_10_7_values = [
88+
":/tk_multi_publish2/overlay_loading.png",
89+
"Loading and processing",
90+
"Hold tight while we analyze your data",
91+
"",
92+
False,
93+
]
94+
with self.check_values_match_v2_10_7(v2_10_7_values) as summary_overlay:
95+
summary_overlay.show_loading()

0 commit comments

Comments
 (0)