-
Notifications
You must be signed in to change notification settings - Fork 0
/
propertywidget.py
331 lines (253 loc) · 9.83 KB
/
propertywidget.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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import os
import sys
from rv import rvtypes, commands
sys.path.append('/home/aberg/py26/lib/python2.6/site-packages')
from PyQt4 import QtGui
from PyQt4 import QtCore
PROP_FUNC_MAP = {
1: commands.getFloatProperty,
2: commands.getIntProperty,
8: commands.getStringProperty
}
PROP_FUNC_MAP_SET = {
1: commands.setFloatProperty,
2: commands.setIntProperty,
8: commands.setStringProperty
}
class PropItemWidget(QtGui.QWidget):
def __init__(self, name='', values=[]):
super(PropItemWidget, self).__init__()
layout = QtGui.QHBoxLayout()
self.name = name
self.setLayout(layout)
self.values = values
self.value_items = []
def on_update(self, *value):
print 'on update value:', self.name, value
class PropFloatWidget(PropItemWidget):
def __init__(self, name, values):
super(PropFloatWidget, self).__init__()
self.name = name
self.values = values
self.add_widgets(values)
def on_update(self, *value):
values = []
for item in self.value_items:
values.append(item.value())
PROP_FUNC_MAP_SET[1](self.name, values, False)
def add_widgets(self, values):
spin_rows_layout = QtGui.QVBoxLayout()
current_row_layout = QtGui.QHBoxLayout()
spin_rows_layout.addChildLayout(current_row_layout)
for index, val in enumerate(values):
if index % 4 == 0:
current_row_layout = QtGui.QHBoxLayout()
spin_rows_layout.addLayout(current_row_layout)
spin_box = QtGui.QDoubleSpinBox()
spin_box.setSingleStep(0.1)
spin_box.setMaximum(999999)
spin_box.setMinimum(-999999)
self.value_items.append(spin_box)
spin_box.setValue(val)
spin_box.valueChanged.connect(self.on_update)
current_row_layout.addWidget(spin_box)
self.layout().addLayout((spin_rows_layout))
class PropIntWidget(PropItemWidget):
def __init__(self, name, values):
super(PropIntWidget, self).__init__()
self.name = name
self.values = values
self.add_widgets(values)
def on_update(self, *value):
values = []
for item in self.value_items:
values.append(item.value())
PROP_FUNC_MAP_SET[2](self.name, values, True)
def add_widgets(self, values):
for val in values:
spin_box = QtGui.QSpinBox()
self.value_items.append(spin_box)
spin_box.valueChanged.connect(self.on_update)
spin_box.setValue(val)
self.layout().addWidget(spin_box)
class PropStringWidget(PropItemWidget):
def __init__(self, name, values):
super(PropStringWidget, self).__init__()
self.name = name
self.values = values
self.add_widgets(values)
def on_update(self, *value):
values = []
for item in self.value_items:
values.append(str(item.text()))
PROP_FUNC_MAP_SET[8](self.name, values, False)
def add_widgets(self, values):
for val in values:
line_edit = QtGui.QLineEdit()
self.value_items.append(line_edit)
line_edit.returnPressed.connect(self.on_update)
line_edit.setText(val)
self.layout().addWidget(line_edit)
PROP_WIDGET_ITEM_MAP = {
1: PropFloatWidget,
2: PropIntWidget,
8: PropStringWidget
}
class Property(object):
def __init__(self, name):
self.name = name
self.nice_name = '.'.join(name.split('.')[1:])
def get_info(self):
return commands.propertyInfo(self.name)
def get_type(self):
return self.get_info()['type']
def get_values(self):
prop_func = PROP_FUNC_MAP.get(self.get_type())
if not prop_func:
raise RuntimeError('Property not found %s' % self.get_type())
return prop_func(self.name, 0, 20000)
class Node(object):
def __init__(self, name):
self.name = name
self.nice_name = name
def get_properties(self):
return [Property(prop) for prop in commands.properties(self.name)]
def get_property(self, prop_name):
for prop in self.get_properties():
if not prop.name.endswith(prop_name):
continue
return prop
def get_type(self):
return commands.nodeType(self.name)
def get_attrs(self):
return commands.sourceAttributes(self.name, None)
class Source(object):
def __init__(self, name):
self.name = name
def get_group(self):
return Group(commands.nodeGroup(self.name))
class Group(object):
def __init__(self, name):
self.name = name
def get_media_name(self):
node = self.get_node('_source')
if not node:
return
prop = node.get_property('media.movie')
if not prop:
return
movie = prop.get_values()
return os.path.basename(movie[0])
def get_node(self, node_name):
for node in self.get_nodes():
if not node.name.endswith(node_name):
continue
return node
def get_nodes(self):
return [Node(node) for node in commands.nodesInGroup(self.name)]
class Model(object):
def __init__(self):
pass
@staticmethod
def get_sources():
return [Source(source) for source in commands.sourcesAtFrame(commands.frame())]
class PropertyWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(PropertyWidget, self).__init__(parent)
self.tree = QtGui.QTreeWidget()
self.tree.setHeaderLabels(['Node', 'Value'])
self.tree.setAlternatingRowColors(True)
update_button = QtGui.QPushButton('Update')
main_layout = QtGui.QVBoxLayout()
main_layout.addWidget(self.tree)
main_layout.addWidget(update_button)
self.setLayout(main_layout)
update_button.clicked.connect(self.on_update)
commands.bind("PropertyWidget", "global", "graph-node-inputs-changed", self.graph_event, "Doc String")
self.on_update()
def graph_event(self, event):
self.on_update()
def on_update(self):
self.tree.clear()
self.update_tree()
for index in range(self.tree.columnCount()):
self.tree.resizeColumnToContents(index)
def update_tree(self):
sources = Model.get_sources()
for source in sources:
group = source.get_group()
group_item = QtGui.QTreeWidgetItem([group.get_media_name()])
self.tree.addTopLevelItem(group_item)
group_item.setExpanded(True)
nodes = group.get_nodes()
for node in nodes:
node_item = QtGui.QTreeWidgetItem([node.nice_name])
group_item.addChild(node_item)
attrs = node.get_attrs()
if attrs:
attrs_item = QtGui.QTreeWidgetItem(['Source Attributes'])
for attr in attrs:
attr_item = QtGui.QTreeWidgetItem([attr[0], ', '.join(attr[1:])])
attrs_item.addChild(attr_item)
node_item.addChild(attrs_item)
properties = node.get_properties()
for prop in properties:
item_class = PROP_WIDGET_ITEM_MAP[prop.get_type()]
prop_item = QtGui.QTreeWidgetItem([prop.nice_name, ''])
prop_item_widget = item_class(prop.name, prop.get_values())
node_item.addChild(prop_item)
self.tree.setItemWidget(prop_item, 1, prop_item_widget)
# I can't figure out how to list the color nodes' properties
# so do it manually for now using #RVColor
#
for prop_find in prop.get_values():
if not prop_find == 'RVColor':
continue
for col_prop in ['exposure', 'gamma', 'saturation', 'contrast']:
prop_name = '#RVColor.color.' + col_prop
values = commands.getFloatProperty(prop_name, 0, 4)
col_item = QtGui.QTreeWidgetItem([col_prop, ''])
prop_item.addChild(col_item)
item_class = PROP_WIDGET_ITEM_MAP[1]
prop_item_widget = item_class(prop_name, values)
self.tree.setItemWidget(col_item, 1, prop_item_widget)
class DockWidget(QtGui.QDockWidget):
def __init__(self, parent=None):
super(DockWidget, self).__init__(parent)
self.setWindowTitle('Properties')
self.setWidget(PropertyWidget())
class PropertyMode(rvtypes.MinorMode):
"""
property explorer
"""
def show_properties(self, event):
# odd, need to keep a reference to the widget here or the
# signals wouldn't come through
if self.dock_wid is None:
self.dock_wid = DockWidget()
self.dock_wid.show()
main_win = self.get_main_window()
if not main_win:
return
main_win.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.dock_wid)
def get_main_window(self):
widgets = QtGui.QApplication.topLevelWidgets()
for wid in widgets:
if not isinstance(wid, QtGui.QMainWindow):
continue
return wid
def __init__(self):
rvtypes.MinorMode.__init__(self)
self.dock_wid = None
self.init("PropertyWidget",
None,
None,
[
("Tools",
[("Properties Panel", self.show_properties, None, None)]
)
]
)
def createMode():
"Required to initialize the module. RV will call this function to create your mode."
return PropertyMode()