-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.py
102 lines (81 loc) · 2.95 KB
/
engine.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
"""
An RV engine for Tank.
"""
import os
import tank
import inspect
import logging
from tank.platform import Engine
from tank import TankError
class RVEngine(Engine):
def init_engine(self):
self.log_debug("%s: Initializing..." % self)
self.toolkit_rv_mode_name = os.environ["TK_RV_MODE_NAME"]
if self.context.project is None:
# must have at least a project in the context to even start!
raise tank.TankError("The engine needs at least a project in the context "
"in order to start! Your context: %s" % self.context)
# default menu name is Shotgun but this can be overriden
# in the configuration to be Sgtk in case of conflicts
self._menu_name = "Shotgun"
if self.get_setting("use_sgtk_as_menu_name", False):
self._menu_name = "SGTK"
self._ui_enabled = True
def _get_dialog_parent(self):
"""
Get the QWidget parent for all dialogs created through
show_dialog & show_modal.
"""
# Find a parent for the dialog - this should be the RV mainWindow()
from tank.platform.qt import QtGui
import shiboken
ptr = None
for w in QtGui.qApp.topLevelWidgets():
if w.inherits("QMainWindow"):
ptr = shiboken.getCppPointer(w)
if ptr:
return shiboken.wrapInstance(long(ptr[0]), QtGui.QMainWindow)
return None
def pre_app_init(self):
# This probably shouldn't be here but it helps the Toolkit tools to look
# right but has the side effect of changing RV's look and feel.
self._initialize_dark_look_and_feel()
def post_app_init(self):
"""
Called when all apps have initialized
"""
self.setup_menu()
def setup_menu(self):
"""
Sets up SGTK menu.
"""
if self.has_ui:
tk_rv = self.import_module("tk_rv")
self._menu_generator = tk_rv.MenuGenerator(self, self._menu_name)
self._menu_generator.create_menu()
def destroy_engine(self):
self.log_debug("%s: Destroying..." % self)
if self._ui_enabled:
self._menu_generator.destroy_menu()
@property
def has_ui(self):
"""
Should always be true.
No terminal mode for RV and no interactive mode that doesn't have ui running.
"""
return self._ui_enabled
##########################################################################################
# logging interfaces
def log_debug(self, msg):
if self.get_setting("debug_logging", False):
msg = "DEBUG: Shotgun - %s" % msg
print msg
def log_info(self, msg):
msg = "INFO: Shotgun - %s" % msg
print msg
def log_warning(self, msg):
msg = "WARNING: Shotgun - %s" % msg
print msg
def log_error(self, msg):
msg = "ERROR: Shotgun - %s" % msg
print msg