1
1
#----------------------------------------------------------------------------------------------------------
2
2
# Wouter Gilsing
3
3
# woutergilsing@hotmail.com
4
- # 21 August 2016
5
- # v1.0
4
+ # 28 August 2016
5
+ # v1.1
6
6
#----------------------------------------------------------------------------------------------------------
7
7
8
8
import nuke
16
16
import colorsys
17
17
18
18
#----------------------------------------------------------------------------------------------------------
19
+ #
20
+ # USER SETTINGS TO MAKE THE HOTBOX FUNCTION PROPERLY IN A STUDIO ENVIRONMENT
21
+ #
22
+ #----------------------------------------------------------------------------------------------------------
23
+ '''
24
+ When enabled, users are able to change the location of the Hotbox Manager icons. In a studio environment,
25
+ this can be unwanted. Change to False to hide the knob.
26
+ '''
27
+
28
+ enableChangeableIconLocation = True
29
+
30
+ '''
31
+ For a studio environment it can be useful to be able to setup multiple repositories to load buttons from,
32
+ rather than having only one. Think of a show specific set of buttons, or facility wide, or both.
33
+ Make sure to point the path to the folder containing the 'All','Multiple' and 'Single' folder, and to end the
34
+ filepath with a '/'. Also, make sure to always use '/' rather than '\\ '. All repositories should be named
35
+ uniquely.
36
+ '''
37
+
38
+ extraRepositories = []
39
+ #extraRepositories.append(['NAME','/path/to/extra/repository/W_hotbox/'])
40
+
41
+ '''
42
+ For example, this will add two extra repositories:
43
+
44
+ extraRepositories.append(['SHOW','server/shows/nuke/repository/W_hotbox/'])
45
+ extraRepositories.append(['FACILITY','server/tools/nuke/repository/W_hotbox/'])
46
+ '''
47
+
48
+ #----------------------------------------------------------------------------------------------------------
49
+
50
+ #----------------------------------------------------------------------------------------------------------
51
+
19
52
20
53
class hotbox (QtGui .QWidget ):
21
54
'''
@@ -203,50 +236,59 @@ def __init__(self, mode, allItems = ''):
203
236
if self .path [- 1 ] != '/' :
204
237
self .path = self .path + '/'
205
238
239
+ self .allRepositories = list (set ([self .path ]+ [i [1 ].replace ('\\ ' ,'/' ) for i in extraRepositories ]))
240
+
206
241
self .rowMaxAmount = int (preferencesNode .knob ('hotboxRowAmountAll' ).value ())
207
242
243
+ self .folderList = []
244
+
245
+
208
246
if mode == 'All' :
209
247
210
- self .folderList = [self .path + mode + '/' ]
248
+ for repository in self .allRepositories :
249
+ self .folderList .append (repository + mode + '/' )
211
250
212
251
else :
213
252
mirrored = False
214
253
self .rowMaxAmount = int (preferencesNode .knob ('hotboxRowAmountSelection' ).value ())
215
254
216
-
217
-
218
255
if mode == 'Single' :
219
256
220
257
if len (selectedNodes ) == 0 :
221
258
nodeClass = 'No Selection'
222
259
223
260
else :
224
261
nodeClass = selectedNodes [0 ].Class ()
225
-
226
- self .folderList = [self .path + mode + '/' + nodeClass ]
227
-
262
+
263
+ for repository in self .allRepositories :
264
+ self .folderList .append (repository + mode + '/' + nodeClass )
265
+
228
266
#check if group, if so take the name of the group, as well as the class
229
267
230
268
if nodeClass == 'Group' :
231
269
nodeClass = selectedNodes [0 ].name ()
232
270
while nodeClass [- 1 ] in [str (i ) for i in range (10 )]:
233
271
nodeClass = nodeClass [:- 1 ]
234
- self .folderList .append (self .path + mode + '/' + nodeClass )
272
+ for repository in self .allRepositories :
273
+ self .folderList .append (repository + mode + '/' + nodeClass )
235
274
236
275
else :
237
276
#scan the 'multiple' folder for folders containing all the currently selected classes.
238
277
nodeClasses = sorted (list (set ([i .Class () for i in selectedNodes ])))
239
-
240
- self .folderList = []
241
- for i in sorted (os .listdir (self .path + mode )):
242
- if i [0 ] not in ['.' ,'_' ]:
243
- folderClasses = sorted (i .split ('-' ))
244
- if nodeClasses == sorted (list (set (nodeClasses ).intersection (folderClasses ))):
245
- self .folderList .append (self .path + mode + '/' + i )
246
-
278
+
279
+ for repository in self .allRepositories :
280
+ try :
281
+ for i in sorted (os .listdir (repository + mode )):
282
+ if i [0 ] not in ['.' ,'_' ]:
283
+ folderClasses = sorted (i .split ('-' ))
284
+ if nodeClasses == sorted (list (set (nodeClasses ).intersection (folderClasses ))):
285
+ self .folderList .append (repository + mode + '/' + i )
286
+ except :
287
+ pass
288
+
247
289
allItems = []
248
290
249
- for folder in self .folderList :
291
+ for folder in list ( set ( self .folderList )) :
250
292
#check if path exists
251
293
if os .path .exists (folder ):
252
294
for i in sorted (os .listdir (folder )):
@@ -419,6 +461,14 @@ def __init__(self, name, function = None):
419
461
self .filePath = name
420
462
self .bgColor = '#525252'
421
463
464
+ self .borderColor = '#000000'
465
+
466
+ #set the border color to grey for buttons from an additional repository
467
+ for index ,i in enumerate (extraRepositories ):
468
+ if name .startswith (i [1 ]):
469
+ self .borderColor = '#959595'
470
+ break
471
+
422
472
if function != None :
423
473
self .function = function
424
474
@@ -484,13 +534,12 @@ def setSelectionStatus(self, selected = False):
484
534
background:%s;
485
535
color:#eeeeee;
486
536
""" % getSelectionColor ())
487
-
488
537
else :
489
538
self .setStyleSheet ("""
490
- border: 1px solid black ;
539
+ border: 1px solid %s ;
491
540
background:%s;
492
541
color:#eeeeee;
493
- """ % self .bgColor )
542
+ """ % ( self .borderColor , self . bgColor ) )
494
543
495
544
self .selected = selected
496
545
@@ -527,38 +576,38 @@ def mouseReleaseEvent(self,event):
527
576
#----------------------------------------------------------------------------------------------------------
528
577
529
578
def addToPreferences (knobObject ):
530
- '''
531
- Add a knob to the preference panel.
532
- Save current preferences to the prefencesfile in the .nuke folder.
533
- '''
534
- preferencesNode = nuke .toNode ('preferences' )
579
+ '''
580
+ Add a knob to the preference panel.
581
+ Save current preferences to the prefencesfile in the .nuke folder.
582
+ '''
583
+ preferencesNode = nuke .toNode ('preferences' )
535
584
536
- if knobObject .name () not in preferencesNode .knobs ().keys ():
585
+ if knobObject .name () not in preferencesNode .knobs ().keys ():
537
586
538
- preferencesNode .addKnob (knobObject )
539
- savePreferencesToFile ()
540
- return preferencesNode .knob (knobObject .name ())
587
+ preferencesNode .addKnob (knobObject )
588
+ savePreferencesToFile ()
589
+ return preferencesNode .knob (knobObject .name ())
541
590
542
591
def savePreferencesToFile ():
543
- '''
544
- Save current preferences to the prefencesfile in the .nuke folder.
545
- Pythonic alternative to the 'ok' button of the preferences panel.
546
- '''
592
+ '''
593
+ Save current preferences to the prefencesfile in the .nuke folder.
594
+ Pythonic alternative to the 'ok' button of the preferences panel.
595
+ '''
547
596
548
- nukeFolder = os .path .expanduser ('~' ) + '/.nuke/'
549
- preferencesFile = nukeFolder + 'preferences%i.%i.nk' % (nuke .NUKE_VERSION_MAJOR ,nuke .NUKE_VERSION_MINOR )
597
+ nukeFolder = os .path .expanduser ('~' ) + '/.nuke/'
598
+ preferencesFile = nukeFolder + 'preferences%i.%i.nk' % (nuke .NUKE_VERSION_MAJOR ,nuke .NUKE_VERSION_MINOR )
550
599
551
- preferencesNode = nuke .toNode ('preferences' )
600
+ preferencesNode = nuke .toNode ('preferences' )
552
601
553
- customPrefences = preferencesNode .writeKnobs ( nuke .WRITE_USER_KNOB_DEFS | nuke .WRITE_NON_DEFAULT_ONLY | nuke .TO_SCRIPT | nuke .TO_VALUE )
554
- customPrefences = customPrefences .replace ('\n ' ,'\n ' )
602
+ customPrefences = preferencesNode .writeKnobs ( nuke .WRITE_USER_KNOB_DEFS | nuke .WRITE_NON_DEFAULT_ONLY | nuke .TO_SCRIPT | nuke .TO_VALUE )
603
+ customPrefences = customPrefences .replace ('\n ' ,'\n ' )
555
604
556
- preferencesCode = 'Preferences {\n inputs 0\n name Preferences%s\n }' % customPrefences
605
+ preferencesCode = 'Preferences {\n inputs 0\n name Preferences%s\n }' % customPrefences
557
606
558
- # write to file
559
- openPreferencesFile = open ( preferencesFile , 'w' )
560
- openPreferencesFile .write ( preferencesCode )
561
- openPreferencesFile .close ()
607
+ # write to file
608
+ openPreferencesFile = open ( preferencesFile , 'w' )
609
+ openPreferencesFile .write ( preferencesCode )
610
+ openPreferencesFile .close ()
562
611
563
612
def deletePreferences ():
564
613
'''
@@ -568,7 +617,7 @@ def deletePreferences():
568
617
allText = ''
569
618
with open ('%s/.nuke/preferences%s.nk' % (os .getenv ('HOME' ),nuke .NUKE_VERSION_STRING .split ('v' )[0 ]), 'r' ) as f :
570
619
for i in f .readlines ():
571
- if 'hotbox' not in i :
620
+ if 'hotbox' not in i and 'iconLocation' not in i :
572
621
allText = allText + i
573
622
574
623
with open ('%s/.nuke/preferences%s.nk' % (os .getenv ('HOME' ),nuke .NUKE_VERSION_STRING .split ('v' )[0 ]), 'w' ) as f :
@@ -665,6 +714,10 @@ def addPreferences():
665
714
except :
666
715
pass
667
716
717
+ #hide the iconLocation knob if defined so at the top of the script (line 28)
718
+ preferencesNode .knob ('iconLocation' ).setVisible (True )
719
+ if not enableChangeableIconLocation :
720
+ preferencesNode .knob ('iconLocation' ).setVisible (False )
668
721
#----------------------------------------------------------------------------------------------------------
669
722
#Color
670
723
#----------------------------------------------------------------------------------------------------------
@@ -804,4 +857,8 @@ def getFileBrowser():
804
857
nuke .menu ('Nuke' ).addCommand ('Edit/W_hotbox/Clear/Clear Everything' , 'W_hotboxManager.clearHotboxManager()' )
805
858
nuke .menu ('Nuke' ).addCommand ('Edit/W_hotbox/Clear/Clear Section/Single' , 'W_hotboxManager.clearHotboxManager(["Single"])' )
806
859
nuke .menu ('Nuke' ).addCommand ('Edit/W_hotbox/Clear/Clear Section/Multiple' , 'W_hotboxManager.clearHotboxManager(["Multiple"])' )
807
- nuke .menu ('Nuke' ).addCommand ('Edit/W_hotbox/Clear/Clear Section/All' , 'W_hotboxManager.clearHotboxManager(["All"])' )
860
+ nuke .menu ('Nuke' ).addCommand ('Edit/W_hotbox/Clear/Clear Section/All' , 'W_hotboxManager.clearHotboxManager(["All"])' )
861
+
862
+ if len (extraRepositories ) > 0 :
863
+ for i in extraRepositories :
864
+ nuke .menu ('Nuke' ).addCommand ('Edit/W_hotbox/Special/Open Hotbox Manager - %s' % i [0 ], 'W_hotboxManager.showHotboxManager(path="%s")' % i [1 ])
0 commit comments