-
Notifications
You must be signed in to change notification settings - Fork 73
/
app.py
221 lines (191 loc) · 7.98 KB
/
app.py
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# 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.
"""
Multi Work Files 2.
Provides File Open/Save functionality for Work Files
"""
import os
import sgtk
class MultiWorkFiles(sgtk.platform.Application):
def init_app(self):
"""
Called as the application is being initialized
"""
self._tk_multi_workfiles = self.import_module("tk_multi_workfiles")
self.__is_pyside_unstable = None
if not self.engine.has_ui:
self.logger.debug(
"The engine reports that there is no UI. Workfiles2 will not continue initializing."
)
return
if self.get_setting("show_change_context"):
# This will only show the context change dialog and not register the save of open dialogs.
self.engine.register_command(
"Change Context...",
self.show_context_change_dlg,
{
"short_name": "change_context",
# dark themed icon for engines that recognize this format
"icons": {
"dark": {
"png": os.path.join(
os.path.dirname(__file__),
"resources",
"file_open_menu_icon.png",
)
}
},
},
)
if self.get_setting("show_file_open"):
# This show the open and save dialogs and not the context change dialog.
# register the file open command
self.engine.register_command(
"File Open...",
self.show_file_open_dlg,
{
"short_name": "file_open",
# dark themed icon for engines that recognize this format
"icons": {
"dark": {
"png": os.path.join(
os.path.dirname(__file__),
"resources",
"file_open_menu_icon.png",
)
}
},
},
)
if self.get_setting("show_file_save"):
# register the file save command
self.engine.register_command(
"File Save...",
self.show_file_save_dlg,
{
"short_name": "file_save",
# dark themed icon for engines that recognize this format
"icons": {
"dark": {
"png": os.path.join(
os.path.dirname(__file__),
"resources",
"file_save_menu_icon.png",
)
}
},
},
)
# Process auto startup options - but only on certain supported platforms
# because of the way QT inits and connects to different host applications
# differently, in conjunction with the 'boot' process in different tools,
# the behaviour can be very different.
#
# currently, we have done QA on the following engines:
SUPPORTED_ENGINES = ["tk-nuke", "tk-maya", "tk-3dsmax"]
if not hasattr(sgtk, "_tk_multi_workfiles2_launch_at_startup"):
# this is the very first time we have run this application
sgtk._tk_multi_workfiles2_launch_at_startup = True
if self.get_setting("launch_at_startup"):
# show the file manager UI
if self.engine.name in SUPPORTED_ENGINES:
# use a single-shot timer to show the open dialog to allow everything to
# finish being set up first:
from sgtk.platform.qt import QtCore
QtCore.QTimer.singleShot(200, self.show_file_open_dlg)
else:
self.log_warning(
"Sorry, the launch at startup option is currently not supported "
"in this engine! You can currently only use it with the following "
"engines: %s" % ", ".join(SUPPORTED_ENGINES)
)
def destroy_app(self):
"""
Clean up app
"""
self.log_debug("Destroying tk-multi-workfiles2")
def show_file_open_dlg(self, use_modal_dialog=False):
"""
Launch the main File Open UI
"""
self._tk_multi_workfiles.WorkFiles.show_file_open_dlg(use_modal_dialog)
def show_context_change_dlg(self, use_modal_dialog=False):
"""
Launch the main File Open UI
"""
self._tk_multi_workfiles.WorkFiles.show_context_change_dlg(use_modal_dialog)
def show_file_save_dlg(self, use_modal_dialog=False):
"""
Launch the main File Save UI
"""
self._tk_multi_workfiles.WorkFiles.show_file_save_dlg(use_modal_dialog)
@property
def context_change_allowed(self):
"""
Specifies that context changes are supported by the app.
"""
return True
@property
def use_debug_dialog(self):
"""
Flag indicating if the dialogs should be invoked in debug mode. In debug
mode the dialog will be modal and leaked PySide objects will be reported
after the dialog is closed.
:returns: True if the debug_dialog setting is True, False otherwise.
"""
return self.get_setting("debug_dialog", False)
@property
def shotgun(self):
"""
Subclassing of the shotgun property on the app base class.
This is a temporary arrangement to be able to time some of the shotgun calls.
"""
# get the real shotgun from the application base class
app_shotgun = sgtk.platform.Application.shotgun.fget(self)
# return a wrapper back which produces debug logging
return DebugWrapperShotgun(app_shotgun, self.log_debug)
@property
def warning_color(self):
"""
Color used to display errors in the UI.
:returns: An RGBA tuple of int (0-255).
"""
color = sgtk.platform.qt.QtGui.QColor(self.style_constants["SG_ALERT_COLOR"])
return color.red(), color.green(), color.blue()
class DebugWrapperShotgun(object):
def __init__(self, sg_instance, log_fn):
self._sg = sg_instance
self._log_fn = log_fn
self.config = sg_instance.config
def find(self, *args, **kwargs):
self._log_fn("PTR API find start: %s %s" % (args, kwargs))
data = self._sg.find(*args, **kwargs)
self._log_fn("PTR API find end")
return data
def find_one(self, *args, **kwargs):
self._log_fn("PTR API find_one start: %s %s" % (args, kwargs))
data = self._sg.find_one(*args, **kwargs)
self._log_fn("PTR API find_one end")
return data
def create(self, *args, **kwargs):
self._log_fn("PTR API create start: %s %s" % (args, kwargs))
data = self._sg.create(*args, **kwargs)
self._log_fn("PTR API create end")
return data
def update(self, *args, **kwargs):
self._log_fn("PTR API update start: %s %s" % (args, kwargs))
data = self._sg.update(*args, **kwargs)
self._log_fn("PTR API update end")
return data
def insert(self, *args, **kwargs):
self._log_fn("PTR API insert start: %s %s" % (args, kwargs))
data = self._sg.insert(*args, **kwargs)
self._log_fn("PTR API insert end")
return data