-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathengine.py
More file actions
255 lines (207 loc) · 8.61 KB
/
Copy pathengine.py
File metadata and controls
255 lines (207 loc) · 8.61 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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# Copyright (c) 2021 Autodesk, Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the ShotGrid 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 ShotGrid Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Autodesk, Inc.
import os
import sys
import sgtk
import rv.qtutils
import rv.commands
from sgtk.platform import Engine, constants
class RVEngine(Engine):
"""
Flow Production Tracking engine for RV.
"""
MAX_THREADS = 4
#####################################################################################
# Metrics
def get_metrics_properties(self):
"""
Returns a dictionary with properties to use when emitting a metric event for
this engine.
"""
properties = super().get_metrics_properties()
properties["Host App Build Type"] = (
"Debug" if rv.commands.isDebug() else "Release"
)
properties["Host App Variant"] = str(rv.commands.getReleaseVariant())
return properties
#####################################################################################
# Properties
@property
def host_info(self):
"""
Returns information about the application hosting this engine.
"""
return {
"name": "RV",
"version": ".".join([str(x) for x in rv.commands.getVersion()]),
}
@property
def default_menu_name(self):
"""
The name of the top-level menu created by the engine.
:returns: str
"""
# XXX Set "Flow Production Tracking" as the default top level menu,
# so that we don't create another empty menu. Eventually we'll want
# somewhere to store "user apps" but we're not ready for that yet anyway.
return "Flow Production Tracking"
@property
def toolkit_rv_mode_name(self):
"""
The name of the RV Mode that bootstrapped PTR and started
the engine.
:returns: str
"""
return os.environ.get("TK_RV_MODE_NAME")
@property
def bg_task_manager(self):
"""
An engine-level background task manager instance that can be
shared across apps.
:returns: task_manager.BackgroundTaskManager
"""
return self._bg_task_manager
#####################################################################################
# Engine Initialization and Destruction
def pre_app_init(self):
"""
Runs before apps have been initialized.
"""
# Get Qt module regardless of version
from sgtk.platform.qt import QtGui, QtCore
# Here we're going to set the hyperlink text color to white
# since the default is a dark blue that is pretty much unreadable
# in a dark color environment like RV. It would be great if we
# could style this in qss and only affect toolkit apps, but that's
# no possible. As a result, we're modifying the QApplication-level
# palette, which is also going to affect RV itself. This is generally
# a BAD IDEA, but in this one case it is the best compromise solution
# available.
palette = QtGui.QApplication.palette()
link_color = QtGui.QColor(255, 255, 255)
palette.setColor(QtGui.QPalette.Link, link_color)
palette.setColor(QtGui.QPalette.LinkVisited, link_color)
palette.setColor(QtGui.QPalette.Button, QtGui.QColor(37, 38, 41))
QtGui.QApplication.setPalette(palette)
# We can't use import_framework here because the engine.py
# wasn't imported via import_module itself. As a result, we
# forgo the convenience and grab the framework ourselves and
# import the submodules we need directly.
shotgun_utils = self.frameworks["tk-framework-shotgunutils"]
shotgun_globals = shotgun_utils.import_module("shotgun_globals")
task_manager = shotgun_utils.import_module("task_manager")
# We need a QObject to act as a parent for the task manager.
# This will keep them and their threads from being garbage
# collected prematurely by Qt.
self.__task_parent = QtCore.QObject()
# We will provide a task manager that apps can share.
self._bg_task_manager = task_manager.BackgroundTaskManager(
parent=self.__task_parent,
start_processing=True,
max_threads=RVEngine.MAX_THREADS,
)
shotgun_globals.register_bg_task_manager(self._bg_task_manager)
# The "qss_watcher" setting causes us to monitor the engine's
# style.qss file and re-apply it on the fly when it changes
# on disk. This is very useful for development work,
if self.get_setting("qss_watcher", False):
self._qss_watcher = QtCore.QFileSystemWatcher(
[os.path.join(self.disk_location, constants.BUNDLE_STYLESHEET_FILE)],
)
self._qss_watcher.fileChanged.connect(self.reload_qss)
# The assumption here is that the default case has us presenting a
# Flow Production Tracking menu and loading it with at least Cutz Support
# and maybe an expected Flow Production Tracking browser or two. _ui_
# enabled turns the menu on. For shell access, setenv TK_RV_NO_UI NCC-1701
# this is basically what tk-maya does so following along.
self._ui_enabled = os.environ.get("TK_RV_NO_UI") or True
def post_app_init(self):
"""
Runs after all apps have been initialized. If running in a GUI
session of RV, the "PTR Review" menu will be created and populated
with any app commands that have been registered with the engine.
"""
if self._ui_enabled:
tk_rv = self.import_module("tk_rv")
self._menu_generator = tk_rv.MenuGenerator(self)
self._menu_generator.create_menu()
def destroy_engine(self):
"""
Tears down the engine and any menu items it has created.
"""
self.log_debug("%r: Destroying tk-rv engine." % self)
if self._ui_enabled:
self._menu_generator.destroy_menu()
self.bg_task_manager.shut_down()
#####################################################################################
# Logging
def log_debug(self, msg):
if self.get_setting("debug_logging", True):
msg = "DEBUG: tk-rv - %s" % msg
print(msg, file=sys.stderr)
def log_info(self, msg):
msg = "INFO: tk-rv - %s" % msg
print(msg, file=sys.stderr)
def log_warning(self, msg):
msg = "WARNING: tk-rv - %s" % msg
print(msg, file=sys.stderr)
def log_error(self, msg):
msg = "ERROR: tk-rv - %s" % msg
print(msg, file=sys.stderr)
#####################################################################################
# General Utilities
def has_ui(self):
"""
Whether RV is running in UI mode or not.
"""
return self._ui_enabled
def get_dialog_parent(self):
"""
The parent widget to use when creating top-level widgets for use
in RV.
"""
return rv.qtutils.sessionWindow()
def get_gl_parent(self):
"""
The RV session's GLView object.
"""
return rv.qtutils.sessionGLView()
def get_top_toolbar(self):
"""
RV's top toolbar widget.
"""
return rv.qtutils.sessionTopToolBar()
def get_bottom_toolbar(self):
"""
RV's bottom toolbar widget.
"""
return rv.qtutils.sessionBottomToolBar()
#####################################################################################
# Styling
def _create_dialog(self, *args, **kwargs):
"""
Overrides and extends the default _create_dialog implementation
from sgtk.platform.engine.Engine. Dialogs are created as is typical,
and then have the tk-rv engine-specific style.qss file applies to
them.
"""
dialog = super()._create_dialog(*args, **kwargs)
self._apply_external_styleshet(self, dialog)
return dialog
def reload_qss(self):
"""
Causes the style.qss file that comes with the tk-rv engine to
be re-applied to all dialogs that the engine has previously
launched.
"""
self.log_warning("Reloading engine QSS...")
for dialog in self.created_qt_dialogs:
self._apply_external_styleshet(self, dialog)
dialog.update()