-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcReadHotBox.py
266 lines (197 loc) · 8.16 KB
/
mcReadHotBox.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
# Created by: Mei Chu
# Last updated: October 23, 2018
# Version: 0.1.5
import nuke
try:
from PySide.QtGui import *
from PySide.QtCore import *
except Exception:
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
# Global variable for the size of the labels and search box inside the panel
fixed_width = 150
fixed_height = 30
# Global control variables for the panel
row_per_col = 10
x_offset = 40
y_offset = 40
def set_default_colour(hotbox, search_box):
if search_box.text() in hotbox.text():
hotbox.setStyleSheet('background:rgb(55, 55, 55);color:white')
else:
hotbox.setStyleSheet('background:transparent;color:gray')
class Panel(QDialog):
def __init__(self, hotbox_count, col_count, row_count, parent=None):
super(Panel, self).__init__(parent)
# self.installEventFilter(self)
# Bring in global variables as needed
self.hotbox_count = hotbox_count
self.col_count = col_count
self.row_count = row_count
# Set the look of panel
self.setObjectName('widget_panel')
self.layout = QGridLayout()
self.layout.setVerticalSpacing(5)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.Window)
self.setFocusPolicy(Qt.StrongFocus)
# self.setAttribute(Qt.WA_TranslucentBackground)
# Add search box at the start
self.search_box = SearchBox(self)
self.layout.addWidget(self.search_box, 0, 0)
# Set variable for the selected node
self.mc_read = nuke.selectedNode()
# Determine the amount of channels available at selected node
self.read_data = []
for channel in self.mc_read.channels():
main_channel = channel.split('.')[0]
if main_channel not in self.read_data:
self.read_data.append(main_channel)
self.mc_read_length = len(self.read_data)
# Counting the channels and adding it as a label widget
while self.hotbox_count < self.mc_read_length:
self.hotbox_name = self.read_data[self.hotbox_count]
rgba_list = ['rgba.red', 'rgba.green', 'rgba.blue', 'rgba.alpha']
self.label = ActionLabel(self.hotbox_name, self, self.search_box)
if self.hotbox_name in rgba_list:
self.layout.addWidget(self.label, self.row_count, 0)
else:
# Every time 10 hot boxes appear, move to the next column
if (self.hotbox_count + 1) % row_per_col == 0:
self.col_count += 1
self.row_count = 0
self.layout.addWidget(self.label, self.row_count, self.col_count)
self.hotbox_count += 1
self.row_count += 1
self.setLayout(self.layout)
# Functions that will move the panel around based on cursor position
self.monitor_res = self.get_resolution()
self.cursor_position = self.get_mouse_position()
self.move_panel()
# Set search box as the main focus
self.search_box.setFocus()
def get_mouse_position(self):
# Move panel to beside current mouse position
x_pos = QCursor.pos().x()
y_pos = QCursor.pos().y()
return tuple([x_pos, y_pos])
def get_resolution(self):
rect = QCoreApplication.instance().desktop().availableGeometry(QCursor.pos())
width = rect.width()
height = rect.height()
return tuple([width, height])
def move_panel(self):
x_cursor = self.cursor_position[0]
y_cursor = self.cursor_position[1]
x_monitor = self.monitor_res[0]
y_monitor = self.monitor_res[1]
y_panel_size = int(self.row_count * fixed_height)
x_panel_size = (self.col_count + 1) * fixed_width
# Move panel if cursor's Y position plus panel size goes off the edge
if (y_cursor + y_panel_size) > y_monitor:
y_pos = y_cursor - y_panel_size - y_offset
else:
y_pos = y_cursor
# Move panel if cursor's X position plus panel size goes off the edge
if (x_cursor + x_panel_size) > x_monitor:
x_pos = x_cursor - x_panel_size - x_offset
else:
x_pos = x_cursor
self.move(QPoint(x_pos, y_pos))
def changeEvent(self, event):
# print event.type()
if event.type() == QEvent.ActivationChange:
if self.isActiveWindow():
pass
else:
self.close()
class ActionLabel(QLabel):
def __init__(self, hotbox_name, panel, search_box):
super(ActionLabel, self).__init__()
# Bring in global variable as needed
self.hotbox_name = hotbox_name
self.panel = panel
self.search_box = search_box
# Set the look of label
self.setAlignment(Qt.AlignCenter)
self.setMouseTracking(True)
self.setFixedWidth(fixed_width)
self.setFixedHeight(fixed_height)
# Set variables for the selected node
self.mc_read = nuke.selectedNode()
# Set text to the label
self.setText(self.hotbox_name)
self.setObjectName(self.hotbox_name)
self.default_colour()
def default_colour(self):
# Set default label scheme for rgb
set_default_colour(self, self.search_box)
def enterEvent(self, event):
# Set colour of label when selected
self.setStyleSheet('background:orange;color:white')
def leaveEvent(self, event):
# Set colour of label back to default scheme
self.default_colour()
def mousePressEvent(self, event):
modifiers = QApplication.keyboardModifiers()
if modifiers == Qt.ShiftModifier:
shuffle_node = nuke.nodes.Shuffle(label=self.hotbox_name, inputs=[self.mc_read])
shuffle_node['in'].setValue(self.hotbox_name)
elif modifiers == Qt.ControlModifier:
grade_node = nuke.nodes.Grade(label=self.hotbox_name, inputs=[self.mc_read])
grade_node['channels'].setValue(self.hotbox_name)
else:
try:
viewer = nuke.activeViewer().node()['channels']
viewer.setValue(self.text())
except Exception:
pass
self.panel.close()
class SearchBox(QLineEdit):
def __init__(self, panel):
super(SearchBox, self).__init__()
# Bring in global variables as needed
self.panel = panel
# Set the look of the line edit
self.setObjectName('search_box')
self.setAlignment(Qt.AlignCenter)
self.setMouseTracking(True)
self.setFixedWidth(fixed_width)
self.setFixedHeight(fixed_height)
self.setText('')
# Set text change signal
self.textChanged.connect(self.text_changed)
try:
self.setPlaceholderText('Search...')
except Exception:
pass
def text_changed(self):
for index in range(self.panel.layout.count()):
name = self.panel.layout.itemAt(index).widget().objectName()
selected_label = self.panel.layout.itemAt(index).widget()
if self.text() != '':
self.change_colour(name, selected_label)
else:
self.change_colour(name, selected_label)
# Using this would hide/show the buttons instead
# if self.text() not in name and 'search_box' not in name:
# self.panel.layout.itemAt(index).widget().hide()
#
# else:
# self.panel.layout.itemAt(index).widget().show()
def change_colour(self, name, selected_label):
if self.text() in name and 'search_box' not in name:
set_default_colour(selected_label, self)
elif 'search_box' in name:
selected_label.setStyleSheet('')
else:
selected_label.setStyleSheet('background:transparent;color:gray')
def load_hotbox():
# Only show one the panel if one node is selected
if len(nuke.selectedNodes()) == 1:
# Global variables at start
hotbox_count = 0
col_count = 0
row_count = 1
panel = Panel(hotbox_count, col_count, row_count, parent=QApplication.activeWindow())
panel.show()