Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
171 lines (133 loc) · 5.46 KB
/
Copy pathapp.py
File metadata and controls
171 lines (133 loc) · 5.46 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
168
169
170
171
# Copyright (c) 2021 Autodesk, 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 Autodesk, Inc.
from types import ModuleType
import sgtk
class SceneBreakdown2(sgtk.platform.Application):
"""
This is the :class:`sgtk.platform.Application` subclass that defines the top-level
Scene Breakdown2 interface.
"""
def init_app(self):
"""Called as the application is being initialized."""
tk_multi_breakdown2 = self.import_module("tk_multi_breakdown2")
self._flowam = tk_multi_breakdown2.flowam
# Store a reference to manager class to expose its functionality at the application level.
self._manager_class = tk_multi_breakdown2.BreakdownManager
# Keep track of the dialog and panel widgets for this app
self._current_dialog = None
self._current_panel = None
if self.get_setting("panel_mode"):
# App will open in as a panel window
app_callback = self.create_panel
app_type = "panel"
self._unique_panel_id = self.engine.register_panel(app_callback)
else:
# App will open in a dialog window
app_callback = self.create_dialog
app_type = "dialog"
self.engine.register_command(
"{}...".format(self.get_setting("display_name")),
app_callback,
{"type": app_type, "short_name": "breakdown"},
)
def show_dialog(self):
"""Show the Scene Breakdown 2 App dialog."""
tk_multi_breakdown2 = self.import_module("tk_multi_breakdown2")
return tk_multi_breakdown2.show_dialog(self)
def create_dialog(self):
"""
Show the app as a dialog.
Contrary to the create_panel() method, multiple calls to this method will result in
multiple windows appearing.
:returns: The widget associated with the dialog.
:rtype: AppDialog
"""
widget = self.show_dialog()
self._current_dialog = widget
return widget
def create_panel(self):
"""
Shows the app as a panel.
Note that since panels are singletons by nature, calling this more than once will only
result in one panel.
:returns: The widget associated with the panel.
:rtype: AppDialog
"""
tk_multi_breakdown2 = self.import_module("tk_multi_breakdown2")
try:
widget = self.engine.show_panel(
self._unique_panel_id,
self.get_setting("display_name"),
self,
tk_multi_breakdown2.AppDialog,
)
except AttributeError as e:
self.log_warning(
"Could not execute show_panel method - please upgrade "
"to latest core and engine! Falling back on show_dialog. "
"Error: %s" % e
)
widget = self.create_dialog()
self._current_panel = widget
return widget
def create_breakdown_manager(self):
"""
Create and return a BreakdownManager instance.
:returns: A BreakdownManager instance.
:rtype: BreakdownManager
"""
return self._manager_class(self)
def _log_metric_viewed_app(self):
"""Module local metric logging helper method for the "Logged In" metric."""
try:
from sgtk.util.metrics import EventMetric
EventMetric.log(
EventMetric.GROUP_TOOLKIT,
"Opened Breakdown2 App",
log_once=False,
bundle=self,
)
except:
# Ignore all errors, e.g. using a core that does not support metrics.
pass
def _on_dialog_close(self, dialog):
"""
Callback called by the panel dialog whenever it is about to close.
Clear the stored references to the dialog, if it is one of the app dialogs.
:param dialog: The dialog that is about to close.
:type dialog: QtGui.QDialog
"""
if dialog == self._current_dialog:
self.log_debug("Current dialog has been closed, clearing reference.")
self._current_dialog = None
elif dialog == self._current_panel:
self.log_debug("Current panel has been closed, clearing reference.")
self._current_panel = None
@property
def flowam_available(self) -> bool:
"""
Returns True if FlowAM integration is available in the running core.
:returns: True if FlowAM integration is available, False otherwise
:rtype: bool
"""
return (
getattr(self.context, "flow_project_id", None) is not None
and getattr(sgtk.platform.current_engine(), "flow_host", None) is not None
)
@property
def flowam(self) -> ModuleType:
"""
Access to the FlowAM integration module for this app. This module provides
drop-in replacements for the standard Shotgun-based Scene Breakdown models and actions,
backed by Flow Asset Management (FlowAM).
:returns: The FlowAM integration module for this app
:rtype: :mod:`tk_multi_breakdown2.flowam`
"""
return self._flowam