-
Notifications
You must be signed in to change notification settings - Fork 3
/
W_hotbox.py
1533 lines (1144 loc) · 47.2 KB
/
W_hotbox.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ----------------------------------------------------------------------------------------------------------
# Wouter Gilsing
version = "1.9"
releaseDate = "March 28 2021"
# - modules
import nuke
from W_hotboxManager import getHotBoxLocation
# Choose between PySide and PySide2 based on Nuke version
if nuke.NUKE_VERSION_MAJOR < 11:
from PySide import QtCore, QtGui, QtGui as QtWidgets
else:
from PySide2 import QtGui, QtCore, QtWidgets
import os
import subprocess
import platform
import traceback
import colorsys
import W_hotboxManager
preferencesNode = nuke.toNode("preferences")
operatingSystem = platform.system()
class Hotbox(QtWidgets.QWidget):
"""
The main class for the hotbox
"""
def __init__(self, subMenuMode=False, path="", name="", position=""):
super(Hotbox, self).__init__()
self.active = True
self.activeButton = None
self.triggerMode = preferencesNode.knob("hotboxTriggerDropdown").getValue()
self.setWindowFlags(
QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint
)
self.setAttribute(QtCore.Qt.WA_NoSystemBackground)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
# enable transparency on Linux
if (
operatingSystem not in ["Darwin", "Windows"]
and nuke.NUKE_VERSION_MAJOR < 11
):
self.setAttribute(QtCore.Qt.WA_PaintOnScreen)
masterLayout = QtWidgets.QVBoxLayout()
self.setLayout(masterLayout)
# - context
self.selection = nuke.selectedNodes()
# check whether selection in group
self.groupRoot = "root"
if self.selection:
nodeRoot = self.selection[0].fullName()
if nodeRoot.count("."):
self.groupRoot = ".".join([self.groupRoot] + nodeRoot.split(".")[:-1])
# - main hotbox
if not subMenuMode:
self.mode = "Single"
if len(self.selection) > 1:
if len(list(set([node.Class() for node in nuke.selectedNodes()]))) > 1:
self.mode = "Multiple"
# Layouts
centerLayout = QtWidgets.QHBoxLayout()
centerLayout.addStretch()
centerLayout.addWidget(
HotboxButton("Reveal in %s" % getFileBrowser(), "revealInBrowser()")
)
centerLayout.addSpacing(25)
centerLayout.addWidget(HotboxCenter())
centerLayout.addSpacing(25)
centerLayout.addWidget(
HotboxButton("Hotbox Manager", "showHotboxManager()")
)
centerLayout.addStretch()
self.topLayout = NodeButtons()
self.bottomLayout = NodeButtons("bottom")
spacing = 12
# - submenu mode
else:
allItems = [
path + "/" + i
for i in sorted(os.listdir(path))
if i[0] not in [".", "_"]
]
centerItems = allItems[:2]
lists = [[], []]
for index, item in enumerate(allItems[2:]):
if int((index % 4) // 2):
lists[index % 2].append(item)
else:
lists[index % 2].insert(0, item)
# Stretch layout
centerLayout = QtWidgets.QHBoxLayout()
centerLayout.addStretch()
for index, item in enumerate(centerItems):
centerLayout.addWidget(HotboxButton(item))
if index == 0:
centerLayout.addWidget(HotboxCenter(False, path))
if len(centerItems) == 1:
centerLayout.addSpacing(105)
centerLayout.addStretch()
self.topLayout = NodeButtons("SubMenuTop", lists[0])
self.bottomLayout = NodeButtons("SubMenuBottom", lists[1])
spacing = 0
# - Equalize layouts to make sure the center layout is the center of the hotbox
difference = self.topLayout.count() - self.bottomLayout.count()
if difference != 0:
extraLayout = QtWidgets.QVBoxLayout()
for i in range(abs(difference)):
extraLayout.addSpacing(35)
if difference > 0:
self.bottomLayout.addLayout(extraLayout)
else:
self.topLayout.insertLayout(0, extraLayout)
masterLayout.addLayout(self.topLayout)
masterLayout.addSpacing(spacing)
masterLayout.addLayout(centerLayout)
masterLayout.addSpacing(spacing)
masterLayout.addLayout(self.bottomLayout)
# position
self.adjustSize()
self.spwanPosition = QtGui.QCursor().pos() - QtCore.QPoint(
(self.width() // 2), (self.height() // 2)
)
# set last position if a fresh instance of the hotbox is launched
if position == "" and not subMenuMode:
global lastPosition
lastPosition = self.spwanPosition
if subMenuMode:
self.move(self.spwanPosition)
else:
self.move(lastPosition)
# make sure the widgets closes when it loses focus
self.installEventFilter(self)
def closeHotbox(self, hotkey=False):
# if the execute on close function is turned on, the hotbox will execute the selected button upon close
if hotkey:
if preferencesNode.knob("hotboxExecuteOnClose").value():
if self.activeButton != None:
self.activeButton.invokeButton()
self.activeButton = None
self.active = False
self.close()
def keyReleaseEvent(self, event):
if event.isAutoRepeat():
return False
if event.text() == shortcut:
global lastPosition
lastPosition = ""
# if set to single tap, leave the hotbox open after launching, else close it.
if not self.triggerMode:
self.closeHotbox(hotkey=True)
return True
def keyPressEvent(self, event):
if event.text() == shortcut:
if event.isAutoRepeat():
return False
# if launch mode is set to 'Single Tap' close the hotbox.
if self.triggerMode:
self.closeHotbox(hotkey=True)
else:
return False
def eventFilter(self, object, event):
if event.type() in [QtCore.QEvent.WindowDeactivate, QtCore.QEvent.FocusOut]:
self.closeHotbox()
return True
return False
# - Button field
class NodeButtons(QtWidgets.QVBoxLayout):
"""
Create QLayout filled with buttons
"""
def __init__(self, mode="", allItems=""):
super(NodeButtons, self).__init__()
selectedNodes = nuke.selectedNodes()
# - submenu
if "submenu" in mode.lower():
self.rowMaxAmount = 3
mirrored = "top" not in mode.lower()
# - main hotbox
else:
mirrored = True
mode = mode == "bottom"
if preferencesNode.knob("hotboxMirroredLayout").value():
mode = 1 - mode
mirrored = 1 - mirrored
self.path = getHotBoxLocation()
self.allRepositories = list(
set([self.path] + [i[1] for i in extraRepositories])
)
self.rowMaxAmount = int(preferencesNode.knob("hotboxRowAmountAll").value())
self.folderList = []
# - noncontextual
if mode:
self.folderList += [
repository + "All" for repository in self.allRepositories
]
# - contextual
else:
mirrored = 1 - mirrored
self.rowMaxAmount = int(
preferencesNode.knob("hotboxRowAmountSelection").value()
)
# - rules
# collect all folders storing buttons for applicable rules
ignoreClasses = False
tag = "# IGNORE CLASSES: "
allRulePaths = []
for repository in self.allRepositories:
rulesFolder = repository + "Rules"
if not os.path.exists(rulesFolder):
continue
rules = [
"/".join([rulesFolder, rule])
for rule in os.listdir(rulesFolder)
if rule[0] not in ["_", "."] and rule[-1] != "_"
]
# validate rules
for rule in rules:
ruleFile = rule + "/_rule.py"
if os.path.exists(ruleFile):
if self.validateRule(ruleFile):
allRulePaths.append(rule)
# read ruleFile to check if ignoreClasses was enabled.
if not ignoreClasses:
for line in open(ruleFile).readlines():
# no point in checking boyond the header
if not line.startswith("#"):
break
# if proper tag is found, check its value
if line.startswith(tag):
ignoreClasses = bool(
int(
line.split(tag)[-1].replace(
"\n", ""
)
)
)
break
# - classes
# collect all folders storing buttons for applicable classes
if not ignoreClasses:
allClassPaths = []
nodeClasses = list(set([node.Class() for node in selectedNodes]))
# if nothing selected
if len(nodeClasses) == 0:
nodeClasses = ["No Selection"]
# if selection
else:
# check if group, if so take the name of the group, as well as the class
groupNodes = []
if "Group" in nodeClasses:
for node in selectedNodes:
if node.Class() == "Group":
groupName = node.name()
while groupName[-1] in [str(i) for i in range(10)]:
groupName = groupName[:-1]
if (
groupName not in groupNodes
and groupName != "Group"
):
groupNodes.append(groupName)
if len(groupNodes) > 0:
groupNodes = [
nodeClass
for nodeClass in nodeClasses
if nodeClass != "Group"
] + groupNodes
if len(nodeClasses) > 1:
nodeClasses = [nodeClasses]
if len(groupNodes) > 1:
groupNodes = [groupNodes]
nodeClasses = nodeClasses + groupNodes
# Check which defined class combinations on disk are applicable to the current selection.
for repository in self.allRepositories:
for nodeClass in nodeClasses:
if isinstance(nodeClass, list):
for managerNodeClasses in [
i
for i in os.listdir(repository + "Multiple")
if i[0] not in ["_", "."]
]:
managerNodeClassesList = managerNodeClasses.split(
"-"
)
match = list(
set(nodeClass).intersection(
managerNodeClassesList
)
)
if len(match) >= len(nodeClass):
allClassPaths.append(
repository
+ "Multiple/"
+ managerNodeClasses
)
else:
allClassPaths.append(repository + "Single/" + nodeClass)
allClassPaths = list(set(allClassPaths))
allClassPaths = [
path for path in allClassPaths if os.path.exists(path)
]
# - combine classes and rules
if ignoreClasses:
self.folderList = allRulePaths
else:
self.folderList = allClassPaths + allRulePaths
if preferencesNode.knob("hotboxRuleClassOrder").getValue():
self.folderList.reverse()
# - files on disk representing items
allItems = []
for folder in self.folderList:
for file in sorted(os.listdir(folder)):
if file[0] not in [".", "_"] and len(file) in [3, 6]:
allItems.append("/".join([folder, file]))
# - devide in rows based on the row maximum
allRows = []
row = []
for item in allItems:
if preferencesNode.knob("hotboxButtonSpawnMode").value():
if len(row) % 2:
row.append(item)
else:
row.insert(0, item)
else:
row.append(item)
# when a row reaches its full capacity, add the row to the allRows list
# and start a new one. Increase rowcapacity to get a triangular shape
if len(row) == self.rowMaxAmount:
allRows.append(row)
row = []
self.rowMaxAmount += preferencesNode.knob("hotboxRowStepSize").value()
# if the last row is not completely full, add it to the allRows list anyway
if len(row) != 0:
allRows.append(row)
if not mirrored:
allRows.reverse()
# nodeHotboxLayout
for row in allRows:
self.rowLayout = QtWidgets.QHBoxLayout()
self.rowLayout.addStretch()
for button in row:
buttonObject = HotboxButton(button)
self.rowLayout.addWidget(buttonObject)
self.rowLayout.addStretch()
self.addLayout(self.rowLayout)
self.rowAmount = len(allRows)
def validateRule(self, ruleFile):
"""
Run the rule, return True or False.
"""
error = False
# read from file
ruleString = open(ruleFile).read()
# quick sanity check
if not "ret=" in ruleString.replace(" ", ""):
error = "RuleError: rule must contain variable named 'ret'"
else:
# prepend the rulestring with a nuke import statement and make it return False by default
prefix = "import nuke\nret = False\n"
ruleString = prefix + ruleString
# run rule
try:
scope = {}
exec(ruleString, scope, scope)
if "ret" in scope.keys():
result = bool(scope["ret"])
except:
error = traceback.format_exc()
# run error
if error:
printError(
error, buttonName=os.path.basename(os.path.dirname(ruleFile)), rule=True
)
result = False
# return the result of the rule
return result
class HotboxCenter(QtWidgets.QLabel):
"""
Center button of the hotbox.
If the 'color nodes' is set to True in the preferences panel, the button will take over the color and
name of the current selection. If not, the button will be the same color as the other buttons will
be in their selected state. The text will be read from the _name.json file in the folder.
"""
def __init__(self, node=True, name=""):
super(HotboxCenter, self).__init__()
self.node = node
nodeColor = "#525252"
textColor = "#eeeeee"
selectedNodes = nuke.selectedNodes()
if node:
# if no node selected
if len(selectedNodes) == 0:
name = "W_hotbox"
nodeColorRGB = interface2rgb(640034559)
# if node(s) selected
else:
name = nuke.selectedNode().name()
nodeColorRGB = interface2rgb(getTileColor())
if preferencesNode.knob("hotboxColorCenter").value():
nodeColor = rgb2hex(nodeColorRGB)
nodeColorHSV = colorsys.rgb_to_hsv(
nodeColorRGB[0], nodeColorRGB[1], nodeColorRGB[2]
)
if nodeColorHSV[2] > 0.7 and nodeColorHSV[1] < 0.4:
textColor = "#262626"
width = 115
height = 60
if (len(set([i.Class() for i in selectedNodes]))) > 1:
name = "Selection"
else:
name = open(name + "/_name.json").read()
nodeColor = getSelectionColor()
width = 105
height = 35
self.setText(name)
self.setAlignment(QtCore.Qt.AlignCenter)
self.setFixedWidth(width)
self.setFixedHeight(height)
# resize font based on length of name
fontSize = int(max(5, (13 - (max(0, (len(name) - 11)) / 2))))
font = QtGui.QFont(preferencesNode.knob("UIFont").value(), fontSize)
self.setFont(font)
self.setStyleSheet(
"""
border: 1px solid black;
color:%s;
background:%s"""
% (textColor, nodeColor)
)
self.setSelectionStatus(True)
def setSelectionStatus(self, selected=False):
"""
Define the style of the button for different states
"""
if not self.node:
self.selected = selected
def enterEvent(self, event):
"""
Change color of the button when the mouse starts hovering over it
"""
if not self.node:
self.setSelectionStatus(True)
return True
def leaveEvent(self, event):
"""
Change color of the button when the mouse starts hovering over it
"""
if not self.node:
self.setSelectionStatus()
return True
def mouseReleaseEvent(self, event):
""" """
if not self.node:
showHotbox(True, resetPosition=False)
return True
# - Buttons
class HotboxButton(QtWidgets.QLabel):
"""
Button class
"""
def __init__(self, name, function=None):
super(HotboxButton, self).__init__()
self.menuButton = False
self.filePath = name
self.bgColor = "#525252"
self.borderColor = "#000000"
# set the border color to grey for buttons from an additional repository
for index, i in enumerate(extraRepositories):
if name.startswith(i[1]):
self.borderColor = "#959595"
break
if function != None:
self.function = function
else:
# - Button linked to folder
if os.path.isdir(self.filePath):
self.menuButton = True
name = open(self.filePath + "/_name.json").read()
self.function = 'showHotboxSubMenu(r"%s","%s")' % (self.filePath, name)
self.bgColor = "#333333"
# - Button linked to file
else:
self.openFile = open(name).readlines()
header = []
for index, line in enumerate(self.openFile):
if not line.startswith("#"):
self.function = "".join(self.openFile[index:])
break
header.append(line)
tags = ["# %s: " % tag for tag in ["NAME", "TEXTCOLOR", "COLOR"]]
tagResults = []
for tag in tags:
tagResult = None
for line in header:
if line.startswith(tag):
tagResult = line.split(tag)[-1].replace("\n", "")
break
tagResults.append(tagResult)
name, textColor, color = tagResults
if textColor and name:
name = '<font color = "%s">%s</font>' % (textColor, name)
if color:
self.bgColor = color
self.setAlignment(QtCore.Qt.AlignCenter)
self.setMouseTracking(True)
self.setFixedWidth(105)
self.setFixedHeight(35)
fontSize = preferencesNode.knob("hotboxFontSize").value()
font = QtGui.QFont(
preferencesNode.knob("UIFont").value(), fontSize, QtGui.QFont.Bold
)
self.setFont(font)
self.setWordWrap(True)
self.setTextFormat(QtCore.Qt.RichText)
self.setText(name)
self.setAlignment(QtCore.Qt.AlignCenter)
self.selected = False
self.setSelectionStatus()
def invokeButton(self):
"""
Execute script attached to button
"""
with nuke.toNode(hotboxInstance.groupRoot):
try:
scope = globals().copy()
exec(self.function, scope, scope)
except:
printError(traceback.format_exc(), self.filePath, self.text())
# if 'close on click' is ticked, close the hotbox
if not self.menuButton:
if (
preferencesNode.knob("hotboxCloseOnClick").value()
and preferencesNode.knob("hotboxTriggerDropdown").getValue()
):
hotboxInstance.closeHotbox()
def setSelectionStatus(self, selected=False):
"""
Define the style of the button for different states
"""
# if button becomes selected
if selected:
self.setStyleSheet(
"""
border: 1px solid black;
background:%s;
color:#eeeeee;
"""
% getSelectionColor()
)
# if button becomes unselected
else:
self.setStyleSheet(
"""
border: 1px solid %s;
background:%s;
color:#eeeeee;
"""
% (self.borderColor, self.bgColor)
)
if preferencesNode.knob("hotboxExecuteOnClose").value():
global hotboxInstance
if hotboxInstance != None:
hotboxInstance.activeButton = None
# if launch mode set to Press and Hold and the button is a menu button,
# dont open a submenu upon shortcut release
if (
not self.menuButton
and not preferencesNode.knob("hotboxTriggerDropdown").getValue()
):
if selected:
hotboxInstance.activeButton = self
self.selected = selected
def enterEvent(self, event):
"""
Change color of the button when the mouse starts hovering over it
"""
self.setSelectionStatus(True)
return True
def leaveEvent(self, event):
"""
Change color of the button when the mouse stops hovering over it
"""
self.setSelectionStatus()
return True
def mouseReleaseEvent(self, event):
"""
Execute the buttons' self.function (str)
"""
if self.selected:
nuke.Undo().name(self.text())
nuke.Undo().begin()
self.invokeButton()
nuke.Undo().end()
return True
# ----------------------------------------------------------------------------------------------------------
# Preferences
# ----------------------------------------------------------------------------------------------------------
def addToPreferences(knobObject, tooltip=None):
"""
Add a knob to the preference panel.
Save current preferences to the prefencesfile in the .nuke folder.
"""
if knobObject.name() not in preferencesNode.knobs().keys():
if tooltip != None:
knobObject.setTooltip(tooltip)
preferencesNode.addKnob(knobObject)
savePreferencesToFile()
return preferencesNode.knob(knobObject.name())
def savePreferencesToFile():
"""
Save current preferences to the prefencesfile in the .nuke folder.
Pythonic alternative to the 'ok' button of the preferences panel.
"""
nukeFolder = os.path.expanduser("~") + "/.nuke/"
preferencesFile = nukeFolder + "preferences{}.{}.nk".format(
nuke.NUKE_VERSION_MAJOR, nuke.NUKE_VERSION_MINOR
)
preferencesNode = nuke.toNode("preferences")
customPrefences = preferencesNode.writeKnobs(
nuke.WRITE_USER_KNOB_DEFS
| nuke.WRITE_NON_DEFAULT_ONLY
| nuke.TO_SCRIPT
| nuke.TO_VALUE
)
customPrefences = customPrefences.replace("\n", "\n ")
preferencesCode = (
"Preferences {\n inputs 0\n name Preferences%s\n}" % customPrefences
)
# write to file
with open(preferencesFile, "wb") as f:
f.write(preferencesCode.encode("utf-8"))
def deletePreferences():
"""
Delete all the W_hotbox related items in the properties panel.
"""
firstLaunch = True
for i in preferencesNode.knobs().keys():
if "hotbox" in i:
preferencesNode.removeKnob(preferencesNode.knob(i))
firstLaunch = False
# remove TabKnob
try:
preferencesNode.removeKnob(preferencesNode.knob("hotboxLabel"))
except:
pass
if not firstLaunch:
savePreferencesToFile()
def addPreferences():
"""
Add knobs to the preferences needed for this module to work properly.
"""
addToPreferences(nuke.Tab_Knob("hotboxLabel", "W_hotbox"))
addToPreferences(nuke.Text_Knob("hotboxGeneralLabel", "<b>General</b>"))
# version knob to check whether the hotbox was updated
knob = nuke.String_Knob("hotboxVersion", "version")
knob.setValue(version)
addToPreferences(knob)
preferencesNode.knob("hotboxVersion").setVisible(False)
# location knob
knob = nuke.File_Knob("hotboxLocation", "Hotbox location")
tooltip = "The folder on disk the Hotbox uses to store the Hotbox buttons. Make sure this path links to the folder containing the 'All','Single' and 'Multiple' folders."
locationKnobAdded = addToPreferences(knob, tooltip)
# icons knob
knob = nuke.File_Knob("hotboxIconLocation", "Icons location")
knob.setValue(homeFolder + "/icons/W_hotbox")
tooltip = "The folder on disk the where the Hotbox related icons are stored. Make sure this path links to the folder containing the PNG files."
addToPreferences(knob, tooltip)
# open manager button
knob = nuke.PyScript_Knob(
"hotboxOpenManager",
"open hotbox manager",
"W_hotboxManager.showHotboxManager()",
)
knob.setFlag(nuke.STARTLINE)
tooltip = "Open the Hotbox Manager."
addToPreferences(knob, tooltip)
# open in file system button knob
knob = nuke.PyScript_Knob(
"hotboxOpenFolder", "open hotbox folder", "W_hotbox.revealInBrowser(True)"
)
tooltip = "Open the folder containing the files that store the Hotbox buttons. It's advised not to mess around in this folder unless you understand what you're doing."
addToPreferences(knob, tooltip)
# delete preferences button knob
knob = nuke.PyScript_Knob(
"hotboxDeletePreferences", "delete preferences", "W_hotbox.deletePreferences()"
)
tooltip = "Delete all the Hotbox related knobs from the Preferences Panel. After clicking this button the Preferences Panel should be closed by clicking the 'cancel' button."
addToPreferences(knob, tooltip)
# Launch Label knob
addToPreferences(nuke.Text_Knob("hotboxLaunchLabel", "<b>Launch</b>"))
# shortcut knob
knob = nuke.String_Knob("hotboxShortcut", "Shortcut")
knob.setValue("`")
tooltip = (
"The key that triggers the Hotbox. Should be set to a single key without any modifier keys. "
"Spacebar can be defined as 'space'. Nuke needs be restarted in order for the changes to take effect."
)
addToPreferences(knob, tooltip)
global shortcut
shortcut = preferencesNode.knob("hotboxShortcut").value()
# reset shortcut knob
knob = nuke.PyScript_Knob("hotboxResetShortcut", "set", "W_hotbox.resetMenuItems()")
knob.clearFlag(nuke.STARTLINE)
tooltip = "Apply new shortcut."
addToPreferences(knob, tooltip)
# trigger mode knob
knob = nuke.Enumeration_Knob(
"hotboxTriggerDropdown", "Launch mode", ["Press and Hold", "Single Tap"]
)
tooltip = (
"The way the hotbox is launched. When set to 'Press and Hold' the Hotbox will appear whenever the shortcut is pressed and disappear as soon as the user releases the key. "
"When set to 'Single Tap' the shortcut will toggle the Hotbox on and off."
)
addToPreferences(knob, tooltip)
# close on click
knob = nuke.Boolean_Knob("hotboxCloseOnClick", "Close on button click")
knob.setValue(False)
knob.clearFlag(nuke.STARTLINE)
tooltip = "Close the Hotbox whenever a button is clicked (excluding submenus obviously). This option will only take effect when the launch mode is set to 'Single Tap'."
addToPreferences(knob, tooltip)
# execute on close
knob = nuke.Boolean_Knob("hotboxExecuteOnClose", "Execute button without click")
knob.setValue(False)
knob.clearFlag(nuke.STARTLINE)
tooltip = "Execute the button underneath the cursor whenever the Hotbox is closed."
addToPreferences(knob, tooltip)
# Rule/Class order
knob = nuke.Enumeration_Knob(
"hotboxRuleClassOrder", "Order", ["Class - Rule", "Rule - Class"]
)
tooltip = "The order in which the buttons will be loaded."
addToPreferences(knob, tooltip)
# Manager startup default
knob = nuke.Enumeration_Knob(
"hotboxOpenManagerOptions",
"Manager startup default",
["Contextual", "All", "Rules", "Contextual/All", "Contextual/Rules"],
)
knob.clearFlag(nuke.STARTLINE)
tooltip = (
"The section of the Manager that will be opened on startup.\n"
"\n<b>Contextual</b> Open the 'Single' or 'Multiple' section, depending on selection."
"\n<b>All</b> Open the 'All' section."
"\n<b>Rules</b> Open the 'Rules' section."
"\n<b>Contextual/All</b> Contextual if the selection matches a button in the 'Single' or 'Multiple' section, otherwise the 'All' section will be opened."
"\n<b>Contextual/Rules</b> Contextual if the selection matches a button in the 'Single' or 'Multiple' section, otherwise the 'Rules' section will be opened."
)
addToPreferences(knob, tooltip)
# Appearence knob
addToPreferences(nuke.Text_Knob("hotboxAppearanceLabel", "<b>Appearance</b>"))
# color dropdown knob
knob = nuke.Boolean_Knob("hotboxMirroredLayout", "Mirrored")
tooltip = "By default the contextual buttons will appear at the top of the hotbox and the non contextual buttons at the bottom."
addToPreferences(knob, tooltip)
# color dropdown knob
knob = nuke.Enumeration_Knob(
"hotboxColorDropdown", "Color scheme", ["Maya", "Nuke", "Custom"]
)