-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathsummary_overlay.py
More file actions
167 lines (132 loc) · 5.18 KB
/
Copy pathsummary_overlay.py
File metadata and controls
167 lines (132 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# Copyright (c) 2015 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun 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 Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.
from sgtk.platform.qt import QtCore, QtGui
import sgtk
from .ui.summary_overlay import Ui_SummaryOverlay
logger = sgtk.platform.get_logger(__name__)
class SummaryOverlay(QtGui.QWidget):
"""
An overlay which sits on top of the details and treeview
in the main UI. Used to present progress and status,
e.g. "loading items" or "publish failed!"
"""
# signal emitted when the info label is clicked by the user
info_clicked = QtCore.Signal()
# signal emitted when the publish again is clicked by the user
publish_again_clicked = QtCore.Signal()
def __init__(self, parent):
"""
:param parent: The model parent.
:type parent: :class:`~PySide.QtGui.QObject`
"""
super().__init__(parent)
self._bundle = sgtk.platform.current_bundle()
self._summary_hook = self._bundle.summary_hook
# set up the UI
self.ui = Ui_SummaryOverlay()
self.ui.setupUi(self)
# hook up a listener to the parent window so this widget
# follows along when the parent window changes size
filter = ResizeEventFilter(parent)
filter.resized.connect(self._on_parent_resized)
parent.installEventFilter(filter)
self.hide()
self.ui.info.clicked.connect(self.info_clicked.emit)
self.ui.publish_again.clicked.connect(self.publish_again_clicked.emit)
def show_summary(
self,
icon_path: str,
label_text: str,
info_text: str,
publish_again_text: str = "",
):
"""Show summary with given messaging and icon.
:param icon_path: Path/value used directly to construct icon's QPixmap.
:param label_text: Main label text to display
:param info_text: Information text for the info button/label
:param publish_again_text: Text to show the publish again button with.
If empty (default) the button will be hidden.
"""
self.ui.icon.setPixmap(QtGui.QPixmap(icon_path))
self.ui.label.setText(label_text)
self.ui.info.setText(info_text)
self.ui.publish_again.setText(publish_again_text or "")
self.ui.publish_again.setVisible(bool(publish_again_text))
self.show()
def show_no_items_error(self):
"""
Shows a special message when there is no items collected under an alternate
UI operation determined by the 'enable_manual_load' application option.
"""
self._summary_hook.no_items_error(self)
def show_success(self):
"""
Shows standard "publish completed successfully!" prompt
"""
self._summary_hook.success(self)
def show_fail(self):
"""
Shows standard "publish failed!" prompt
"""
self._summary_hook.fail(self)
def show_loading(self):
"""
Shows standard "loading stuff" prompt
"""
self._summary_hook.loading(self)
def show(self):
"""
Subclassed show method
"""
super().show()
self._on_parent_resized()
def _on_parent_resized(self):
"""
Special slot hooked up to the event filter.
When associated widget is resized this slot is being called.
"""
self.resize(self.parentWidget().size())
class ResizeEventFilter(QtCore.QObject):
"""
Utility and helper.
Event filter which emits a resized signal whenever
the monitored widget resizes.
You use it like this:
# create the filter object. Typically, it's
# it's easiest to parent it to the object that is
# being monitored (in this case self.ui.thumbnail)
filter = ResizeEventFilter(self.ui.thumbnail)
# now set up a signal/slot connection so that the
# __on_thumb_resized slot gets called every time
# the widget is resized
filter.resized.connect(self.__on_thumb_resized)
# finally, install the event filter into the QT
# event system
self.ui.thumbnail.installEventFilter(filter)
"""
resized = QtCore.Signal()
def eventFilter(self, obj, event):
"""
Event filter implementation.
For information, see the QT docs:
http://doc.qt.io/qt-4.8/qobject.html#eventFilter
This will emit the resized signal (in this class)
whenever the linked up object is being resized.
:param obj: The object that is being watched for events
:param event: Event object that the object has emitted
:returns: Always returns False to indicate that no events
should ever be discarded by the filter.
"""
# peek at the message
if event.type() == QtCore.QEvent.Resize:
# re-broadcast any resize events
self.resized.emit()
# pass it on!
return False