-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwindow.py
116 lines (91 loc) · 3.01 KB
/
window.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
__author__ = 'Danny Wynne'
from mlib.core import qt
from mlib.core.qt import QtGui, QtCore, uic
import maya.mel as mel
import os
from . import utils as explorer_utils
reload(explorer_utils)
baseclass = qt.loadUiFile("window")
class MayaQtExplorer(baseclass):
def __init__(self, parent=qt.getMayaWindow()):
super(MayaQtExplorer, self).__init__(parent)
self.maya_window = parent
self.setUnmanagedWidgets([self.gvars_list, self.info_te, self.current_widget_path])
#hide unused widgets for now
self.label_5.hide()
self.info_te.hide()
self.gvars = explorer_utils.get_ui_gvars()
self.gvars = [" - ".join(x) for x in self.gvars]
self.gvars_list.clear()
self.gvars_list.addItems(self.gvars)
self.info_te.setText("")
self.gvars_list.itemDoubleClicked.connect(self.gvar_double_clicked)
self.parent_list.itemDoubleClicked.connect(self.ui_path_list_double_clicked)
self.child_list.itemDoubleClicked.connect(self.ui_path_list_double_clicked)
self.search_gvars.textChanged.connect(self.search_changed)
self.parent_list.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.band = QtGui.QRubberBand(QtGui.QRubberBand.Rectangle, qt.getMayaWindow())
def search_changed(self):
search = str(self.search_gvars.text()).lower()
if len(search) < 3:
self.gvars_list.clear()
self.gvars_list.addItems(self.gvars)
return
_tmp_gvars = []
for g in self.gvars:
if g.lower().find(search) > -1:
_tmp_gvars.append(g)
self.gvars_list.clear()
self.gvars_list.addItems(_tmp_gvars)
def ui_path_list_double_clicked(self, *args):
ui_path = args[0].text()
try:
widget = qt.pathToWidget(ui_path.partition(" - ")[2])
if widget is None:
raise TypeError
except:
return
self.set_current_widget(widget)
def gvar_double_clicked(self, *args):
gvar = args[0].text()
try:
tmp = mel.eval('string $temp = %s;'%gvar.partition(" - ")[0])
widget = qt.pathToWidget(tmp)
except:
print "probably not a QObject"
return
self.set_current_widget(widget)
def set_current_widget(self, widget):
self.child_list.clear()
self.parent_list.clear()
if not widget:
return
ui_path = qt.widgetToPath(widget)
widget_type = type(widget).__name__
self.current_widget_path.setText(widget_type + " - " + ui_path)
children = widget.children()
for c in children:
c_type = type(c).__name__
ui_path = qt.widgetToPath(c)
self.child_list.addItem(c_type + " - " + ui_path)
parent = widget.parent()
parent_type = type(parent).__name__
self.parent_list.addItem(parent_type + " - " + qt.widgetToPath(parent))
self.rubber_band_widget(widget)
def closeEvent(self, event):
if self.getSettingsManaged():
self.saveSettings()
self.band.hide()
def rubber_band_widget(self, widget):
try:
self.band.hide();
except:
pass
if not hasattr(widget, 'frameGeometry'):
return
geometry = widget.frameGeometry()
offset = widget.mapTo(self.band.parent(), geometry.topLeft())
geometry.moveTo(offset)
self.band.setGeometry(geometry)
if not geometry.isNull():
self.band.show()