This repository was archived by the owner on Aug 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmod_SetLabel.py
221 lines (144 loc) · 5.45 KB
/
mod_SetLabel.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
# ------------------------------------------------------------------------------
# Module Import
# ------------------------------------------------------------------------------
import nuke, nukescripts
import platform
from Qt import QtWidgets, QtGui, QtCore
#------------------------------------------------------------------------------
#-Header
#------------------------------------------------------------------------------
__VERSION__ = '2.0'
__OS__ = platform.system()
__AUTHOR__ = "Tianlun Jiang"
__WEBSITE__ = "jiangovfx.com"
__COPYRIGHT__ = "copyright (c) %s - %s" % (__AUTHOR__, __WEBSITE__)
__TITLE__ = "SetLabel v%s" % __VERSION__
def _version_():
ver="""
version 2.0
- Add preset buttons for frames and knob values
- Add Node Context support
version 1.0
- Basically working, when run(), prompt a frameless popup with line edit field
- replace with Qt
"""
# ------------------------------------------------------------------------------
# Global Variables
# ------------------------------------------------------------------------------
KNOB_IGNORE = set(['layer', 'invert_mask', 'help',
'dope_sheet', 'hide_input', 'xpos',
'crop', 'channels', 'note_font_color',
'onCreate', 'quality', 'updateUI',
'knobChanged', 'note_font', 'tile_color',
'bookmark', 'selected', 'autolabel',
'process_mask', 'label', 'onDestroy',
'inject', 'indicators', 'icon',
'channel', 'maskFrom', 'maskChannelMask',
'enable', 'maskChannelInput', 'Mask',
'ypos', 'postage_stamp_frame', 'postage_stamp',
'lifetimeStart', 'maskChannel', 'panel',
'lifetimeEnd', 'maskFromFlag',
'name', 'cached', 'fringe',
'mask', 'note_font_size', 'filter',
'useLifetime', 'gl_color'])
KNOB_IGNORE_KEYWORDS = ['_panelDropped', 'enable', 'unpremult', 'clamp']
# ------------------------------------------------------------------------------
# Core Class
# ------------------------------------------------------------------------------
class Core_SetLabel(QtWidgets.QDialog):
def __init__(self):
super(Core_SetLabel,self).__init__()
self.lineInput = QtWidgets.QLineEdit()
self.lineInput.setAlignment(QtCore.Qt.AlignCenter)
self.lineInput.returnPressed.connect(self.onPressed)
self.title = QtWidgets.QLabel("<b>Set Label</b>")
self.title.setAlignment(QtCore.Qt.AlignHCenter)
self.btn_frame = QtWidgets.QPushButton("Current Frame")
self.btn_frame.clicked.connect(self.onPreset)
self.knoblist = QtWidgets.QComboBox()
self.knoblist.setEditable(True)
self.btn_knob = QtWidgets.QPushButton("Knob Value")
self.btn_knob.clicked.connect(self.onPreset)
self.layout = QtWidgets.QVBoxLayout()
self.layout_knobs = QtWidgets.QHBoxLayout()
self.layout.addWidget(self.title)
self.layout.addWidget(self.lineInput)
self.layout.addWidget(self.btn_frame)
self.layout_knobs.addWidget(self.knoblist)
self.layout_knobs.addWidget(self.btn_knob)
self.layout.addLayout(self.layout_knobs)
self.setLayout(self.layout)
self.resize(200,50)
self.setWindowTitle("Set Label")
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.Popup)
# self.setDefault()
def onPressed(self):
"""change label with enter-key is pressed"""
newLabel = self.lineInput.text()
for n in self.sel_nodes:
n['label'].setValue(newLabel)
self.close()
def onPreset(self):
"""When preset button is pressed"""
_sender = self.sender()
if _sender is self.btn_frame:
for n in self.sel_nodes:
n['label'].setValue('x%s' % nuke.frame())
elif _sender is self.btn_knob:
sel_knob = self.knoblist.currentText()
n = self.sel_nodes[0]
n['label'].setValue('[value %s]' % sel_knob)
self.close()
def setDefault(self):
"""get the existing label of selected nodes"""
context = get_dag()
with context:
self.sel_nodes = nuke.selectedNodes()
if self.sel_nodes != []:
self.lineInput.show()
self.title.setText("<b>Set Label</b>")
self.lineInput.setText(self.sel_nodes[0]['label'].value())
n = self.sel_nodes[0]
knobs = filterKnobs(n.knobs())
self.knoblist.clear()
self.knoblist.addItems(knobs)
else:
self.lineInput.hide()
self.title.setText("<b>Error:<br>No Node Selected</b>")
def run(self):
"""rerun instance"""
self.setDefault()
self.move(QtGui.QCursor.pos()+QtCore.QPoint(-100,-12))
self.raise_()
self.lineInput.setFocus()
self.lineInput.selectAll()
self.show()
# ------------------------------------------------------------------------------
# Supporting Fucntions
# ------------------------------------------------------------------------------
def filterKnobs(knobs):
"""filter knobs for labels
@knobs: (list) list of knobs
return: (list) filtered list of knobs
"""
ls_ignored = list( set(knobs)-KNOB_IGNORE )
ls_filtered = []
for k in ls_ignored:
count = 0
for f in KNOB_IGNORE_KEYWORDS:
if f not in k: count += 1
if count == len(KNOB_IGNORE_KEYWORDS): ls_filtered.append(k)
return sorted(ls_filtered)
def get_dag():
"""For DAG context when selecting nodes"""
app = QtWidgets.QApplication
pos = QtGui.QCursor.pos()
widget = app.widgetAt(pos)
#print dir(widget)
context = widget.parent().windowTitle().split('Node Graph')[0].strip()
print(context)
return nuke.root() if context == '' else nuke.toNode(context)
# ------------------------------------------------------------------------------
# Instancing
# ------------------------------------------------------------------------------
SetLabel = Core_SetLabel()