forked from animanathome/tk-katana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.py
executable file
·111 lines (92 loc) · 3.61 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
103
104
105
106
107
108
109
110
111
#
# Copyright (c) 2013 Shotgun Software, Inc
# ----------------------------------------------------
#
"""
A Katana engine for Tank.
"""
import os
import sys
import ctypes
import shutil
import logging
import traceback
import tank
from Katana import Callbacks
class KatanaEngine(tank.platform.Engine):
def init_engine(self):
self.log_debug("%s: Initializing..." % self)
self.katana_log=logging.getLogger("Shotgun Katana Engine")
def _define_qt_base(self):
"""
Override to return the PyQt4 modules as provided by Katana.
:return: Dictionary containing the qt core & gui modules as well as the
class to use for the base of all dialogs.
"""
# proxy class used when QT does not exist on the system.
# this will raise an exception when any QT code tries to use it
class QTProxy(object):
def __getattr__(self, name):
raise tank.TankError("Looks like you are trying to run an App that uses a QT "
"based UI, however the Katana engine could not find a PyQt "
"installation!")
base = {"qt_core": QTProxy(), "qt_gui": QTProxy(), "dialog_base": None}
try:
from PyQt4 import QtCore, QtGui
import PyQt4
# hot patch the library to make it work with pyside code
QtCore.Signal = QtCore.pyqtSignal
QtCore.Slot = QtCore.pyqtSlot
QtCore.Property = QtCore.pyqtProperty
base["qt_core"] = QtCore
base["qt_gui"] = QtGui
base["dialog_base"] = QtGui.QDialog
self.log_debug("Successfully initialized PyQt '%s' located in %s."
% (QtCore.PYQT_VERSION_STR, PyQt4.__file__))
except ImportError:
pass
except Exception, e:
import traceback
self.log_warning("Error setting up PyQt. PyQt based UI support "
"will not be available: %s" % e)
self.log_debug(traceback.format_exc())
return base
def add_katana_menu(self, objectHash=None):
menu_name = "Shotgun"
if self.get_setting("use_sgtk_as_menu_name", False):
menu_name = "Sgtk"
tk_katana = self.import_module("tk_katana")
self.katana_log.info("Start creating shotgun menu.")
try:
self._menu_generator = tk_katana.MenuGenerator(self, menu_name)
self._menu_generator.create_menu()
except:
traceback.print_exc()
def update_katana_menu(self):
'''
Refresh the Katana menu for the current context.
'''
self.katana_log.info("Updating shotgun menu.")
self._menu_generator.populate_menu()
def post_app_init(self):
Callbacks.addCallback(Callbacks.Type.onStartupComplete, self.add_katana_menu)
def destroy_engine(self):
self.log_debug("%s: Destroying..." % self)
def _display_message(self, msg):
self.log_info(msg)
def launch_command(self, cmd_id):
callback = self._callback_map.get(cmd_id)
if callback is None:
self.log_error("No callback found for id: %s" % cmd_id)
return
callback()
def log_debug(self, msg):
if self.get_setting("debug_logging", False):
print "Shotgun Debug: %s" % msg
def log_info(self, msg):
print "Shotgun: %s" % msg
def log_error(self, msg):
self._display_message(msg)
print "Shotgun Error: %s" % msg
def log_warning(self, msg):
print str(msg)