def __init__(self): super(IconPanel, self).__init__('Universal Icons', 'com.thorium.IconPanel') self.external_icons = self.find_file_icons() self.internal_icons = INTERNAL_ICONS self.batch = 30 # We'll have two tabs up on top, one for External icons and one for # internal Icons # Inside each tab will be a bunch of subtabs, each containing about 30 # icons. # # We accomplish this nested tabbing by starting and ending tab groups. # The top level tab group contains the External and Internal tabs, # then within each tab we'll start and end another tab group. self.addKnob(nuke.BeginTabGroup_Knob()) # Build our external icons self.addKnob(nuke.Tab_Knob('external_icons', 'External Icons')) self.build_icon_list(self.external_icons, html_style=False, alpha_title=True) # Build our internal icons self.addKnob(nuke.Tab_Knob('internal_icons', 'Internal Icons')) self.build_icon_list(self.internal_icons, html_style=True) self.addKnob(nuke.EndTabGroup_Knob())
def addKnob(self, knob): if type(knob) == nuke.BeginTabGroup_Knob: self.__openTabGroups += 1 elif type(knob) == nuke.EndTabGroup_Knob: self.__openTabGroups -= 1 elif type(knob) == nuke.Tab_Knob and self.__openTabGroups <= 0: self.addKnob(nuke.BeginTabGroup_Knob()) self.__node.addKnob(knob) knob.setFlag(nuke.NO_UNDO | nuke.NO_ANIMATION)
def build_icon_list(self, icon_list, html_style=True, alpha_title=False): """Builds the panel list of icons""" # Start our tab group self.addKnob(nuke.BeginTabGroup_Knob()) # Add all of our child icon knobs and tabs for i, icon in enumerate(icon_list): # Every time we hit the batch limit, we'll be creating a new tab counter = i % self.batch if counter == 0: tab_name = icon[:2].title() if alpha_title else str(i) tab = nuke.Tab_Knob(tab_name, tab_name) self.addKnob(tab) icon_knob = self.build_icon_knob(icon, html_style) self.addKnob(icon_knob) # End our tab group self.addKnob(nuke.EndTabGroup_Knob())
def create_knobs(data, tab=None): """Create knobs by data Depending on the type of each dict value and creates the correct Knob. Mapped types: bool: nuke.Boolean_Knob int: nuke.Int_Knob float: nuke.Double_Knob list: nuke.Enumeration_Knob six.string_types: nuke.String_Knob dict: If it's a nested dict (all values are dict), will turn into A tabs group. Or just a knobs group. Args: data (dict): collection of attributes and their value tab (string, optional): Knobs' tab name Returns: list: A list of `nuke.Knob` objects """ def nice_naming(key): """Convert camelCase name into UI Display Name""" words = re.findall('[A-Z][^A-Z]*', key[0].upper() + key[1:]) return " ".join(words) # Turn key-value pairs into knobs knobs = list() if tab: knobs.append(nuke.Tab_Knob(tab)) for key, value in data.items(): # Knob name if isinstance(key, tuple): name, nice = key else: name, nice = key, nice_naming(key) # Create knob by value type if isinstance(value, Knobby): knobby = value knob = knobby.create(name, nice) elif isinstance(value, float): knob = nuke.Double_Knob(name, nice) knob.setValue(value) elif isinstance(value, bool): knob = nuke.Boolean_Knob(name, nice) knob.setValue(value) knob.setFlag(nuke.STARTLINE) elif isinstance(value, int): knob = nuke.Int_Knob(name, nice) knob.setValue(value) elif isinstance(value, six.string_types): knob = nuke.String_Knob(name, nice) knob.setValue(value) elif isinstance(value, list): knob = nuke.Enumeration_Knob(name, nice, value) elif isinstance(value, dict): if all(isinstance(v, dict) for v in value.values()): # Create a group of tabs begain = nuke.BeginTabGroup_Knob() end = nuke.EndTabGroup_Knob() begain.setName(name) end.setName(name + "_End") knobs.append(begain) for k, v in value.items(): knobs += create_knobs(v, tab=k) knobs.append(end) else: # Create a group of knobs knobs.append(nuke.Tab_Knob(name, nice, nuke.TABBEGINGROUP)) knobs += create_knobs(value) knobs.append(nuke.Tab_Knob(name, nice, nuke.TABENDGROUP)) continue else: raise TypeError("Unsupported type: %r" % type(value)) knobs.append(knob) return knobs
def __init__(self, n): nukescripts.PythonPanel.__init__(self, 'shuffle channels') self.n = n self.channels = self.n.channels() # Layers list builder self.layers = [] for i in range(len(self.channels)): chanName = self.channels[i].split('.')[0] if chanName not in self.layers and 'rgba' not in chanName: self.layers.append(chanName) # UI self.tabGroup = nuke.BeginTabGroup_Knob('tabGroup', '') self.addKnob(self.tabGroup) # Layers Tab self.layersTab = nuke.Tab_Knob('layersTab', 'channels') self.addKnob(self.layersTab) availableNodes = '%s (%s node)' % (self.n.name(), self.n.Class()) self.selectedNodeName = nuke.Text_Knob('selectedNodeName', 'selected node: ', availableNodes) self.addKnob(self.selectedNodeName) self.separator = nuke.Text_Knob('separator', '') self.addKnob(self.separator) self.presets = nuke.Enumeration_Knob('presets', '', [' ']) self.addKnob(self.presets) self.listLayers = [] for i in range(len(self.layers)): layer = nuke.Boolean_Knob('layer'+str(i), str(self.layers[i])) layer.setValue(True) layer.setEnabled(False) self.addKnob(layer) layer.setFlag(4096) self.listLayers.append(layer) # Prefs Tab self.prefsTab = nuke.Tab_Knob('prefsTab', 'preferences') self.addKnob(self.prefsTab) self.text1 = nuke.Text_Knob('texte_separation', 'generate') self.addKnob(self.text1) self.autocrop = nuke.Boolean_Knob('autocrop', 'Autocrop') self.addKnob(self.autocrop) self.autocrop.setFlag(4096) self.postage = nuke.Boolean_Knob('postage', 'Postage stamp') self.addKnob(self.postage) self.postage.setFlag(4096) self.remove = nuke.Boolean_Knob('remove', 'Remove node') self.addKnob(self.remove) self.remove.setFlag(4096) self.grade = nuke.Boolean_Knob('grade', 'Grade node') self.addKnob(self.grade) self.grade.setFlag(4096) self.noShuffLabel = nuke.Boolean_Knob('noShuffLabel', 'remove label from Shuffles') self.noShuffLabel.setValue(True) self.noShuffLabel.setFlag(4096) self.noShuffLabel.setVisible(False) self.addKnob(self.noShuffLabel) self.bdrop = nuke.Boolean_Knob('bdrop', 'Backdrop') self.addKnob(self.bdrop) self.bdrop.setFlag(4096) self.bdropColor = nuke.ColorChip_Knob('bdropColor', 'backDrop color') self.addKnob(self.bdropColor) self.bdropColor.setDefaultValue([926365441]) self.text = nuke.Text_Knob('texte_separation', 'separation between nodes') self.addKnob(self.text) self.separation = nuke.Double_Knob('separation', '') self.addKnob(self.separation) self.separation.setFlag(4096) self.separation.setRange(100, 400) self.separation.setDefaultValue([200]) self.shuffLayersColor = nuke.ColorChip_Knob('shuffLayersColor', 'Shuffle color') self.addKnob(self.shuffLayersColor) prefNode = nuke.toNode('preferences')['NodeColour05Color'].value() self.shuffLayersColor.setDefaultValue([prefNode]) self.EndTab = nuke.EndTabGroup_Knob('endTabGroup', '') self.addKnob(self.EndTab)
def __init__(self, n): nukescripts.PythonPanel.__init__(self, 'shuffle channels') self.n = n self.channels = self.n.channels() #def builder(self): ###layers list builder self.layers = [] for i in range ( len ( self.channels ) ): if self.channels[i].split('.')[0] not in self.layers : self.layers.append ( self.channels[i].split('.')[0] ) #UI###################################################################################################################### self.tabGroup = nuke.BeginTabGroup_Knob ('tabGroup', '') self.addKnob (self.tabGroup) ##layersTab self.layersTab = nuke.Tab_Knob ('layersTab', 'layers') self.addKnob (self.layersTab) self.selectedNodeName = nuke.Text_Knob ( 'selectedNodeName', 'selected node: ', '%s, %s node' %( self.n.name(), self.n.Class() ) ) self.addKnob (self.selectedNodeName) self.separator = nuke.Text_Knob ( 'separator', '') self.addKnob (self.separator) self.presets = nuke.Enumeration_Knob ('presets', '', [' ']) self.addKnob (self.presets) self.savePreset = nuke.PyScript_Knob ('savePreset', 'save preset', 'shuffleChannels.savePreset()') #self.addKnob (self.savePreset) self.removePreset = nuke.PyScript_Knob ('deletePreset', 'delete preset', 'shuffleChannels.deletePreset()') #self.addKnob (self.removePreset) for i in range ( len ( self.layers ) ): exec "self.layer%s = ''" %( i ) exec "self.layer%s = nuke.Boolean_Knob ('layer%s', '%s')" %( i, i, self.layers[i] ) exec "self.addKnob (self.layer%s)" %i exec "self.layer%s.setFlag(4096)" %i #self.selectAllLayers = nuke.PyScript_Knob ('selectAllLayers', 'select all layers', "shuffleChannels.selectAll()") #self.addKnob (self.selectAllLayers) #self.selectAllLayers.setFlag(4096) #self.deselectAllLayers = nuke.PyScript_Knob ('deselectAllLayers', 'deselect all layers', "shuffleChannels.deselectAll()") #self.addKnob (self.deselectAllLayers) ##channelsTab #self.channelsTab = nuke.Tab_Knob ('channelsTab', 'channels') #self.addKnob (self.channelsTab) #for i in range ( len ( self.channels ) ): #exec "self.channel%s = ''" %( i ) #exec "self.channel%s = nuke.Boolean_Knob ('channel%s', '%s')" %( i, i, self.channels[i] ) #exec "self.addKnob (self.channel%s)" %i #exec "self.channel%s.setFlag(4096)" %i ##prefsTab self.prefsTab = nuke.Tab_Knob ('prefsTab', 'preferences') self.addKnob (self.prefsTab) self.unPremult = nuke.Boolean_Knob ('unPremult', 'add unpremult / premult nodes') self.addKnob (self.unPremult) self.unPremult.setFlag (4096) self.remove = nuke.Boolean_Knob ('remove', 'add remove node') self.addKnob (self.remove) self.remove.setFlag(4096) self.grade = nuke.Boolean_Knob ('grade', 'add grade node') self.addKnob (self.grade) self.grade.setFlag(4096) self.merge = nuke.Boolean_Knob ('merge', 'add merge node') self.addKnob (self.merge) self.merge.setFlag(4096) self.operation = nuke.Enumeration_Knob ('operation', ' | operation', [ 'atop', 'average', 'color-burn', 'color-dodge', 'conjoint-over', 'copy', 'difference', 'disjoint-over', 'divide', 'exclusion', 'from', 'geometric', 'hard-light', 'hypot', 'in', 'mask', 'matte', 'max', 'min', 'minus', 'multiply', 'out', 'over', 'overlay', 'plus', 'screen', 'soft-light', 'stencil', 'under', 'xor']) self.addKnob (self.operation) self.operation.clearFlag(4096) self.operation.setValue('plus') self.copyAlpha = nuke.Boolean_Knob ('copyAlpha', 'add copyAlpha node') self.addKnob (self.copyAlpha) self.copyAlpha.setFlag(4096) self.noShuffLabel = nuke.Boolean_Knob ('noShuffLabel', 'remove label from Shuffles') self.addKnob (self.noShuffLabel) self.noShuffLabel.setFlag(4096) self.separation = nuke.Double_Knob ('separation', 'separation between nodes') self.addKnob (self.separation) self.separation.setFlag(4096) self.separation.setRange (100, 400) self.separation.setDefaultValue ([200]) self.shuffLayersColor = nuke.ColorChip_Knob ('shuffLayersColor', 'Shuffle color') self.addKnob (self.shuffLayersColor) self.shuffLayersColor.setDefaultValue([nuke.toNode('preferences')['NodeColour05Color'].value()]) self.shuffLayersColor.setFlag(4096) self.bdrop = nuke.Boolean_Knob ('bdrop', 'add backDrop') self.addKnob (self.bdrop) self.bdrop.setFlag(4096) self.bdropColor = nuke.ColorChip_Knob ('bdropColor', 'backDrop color') self.addKnob (self.bdropColor) self.bdropColor.setDefaultValue([926365441]) self.separation01 = nuke.Text_Knob ('separation01', '') self.addKnob (self.separation01) self.EndTab = nuke.EndTabGroup_Knob ('endTabGroup', '') self.addKnob ( self.EndTab )
def create_knobs(data, tab): """Create knobs by data Depending on the type of each dict value and creates the correct Knob. Mapped types: bool: nuke.Boolean_Knob int: nuke.Int_Knob float: nuke.Double_Knob list: nuke.Enumeration_Knob string_types: nuke.String_Knob dict: If it's a nested dict (all values are dict), will turn into A tabs group. Or just a knobs group. Args: data (dict): collection of attributes and their value prefix (str): knob name prefix Returns: list: A list of `nuke.Knob` objects """ # Turn key-value pairs into knobs knobs = list() prefix = tab + ":" for key, value in data.items(): # Knob name if isinstance(key, tuple): name, nice = key else: name, nice = key, nice_naming(key) name = prefix + name # Create knob by value type if isinstance(value, Knobby): knobby = value knob = knobby.create(name, nice) elif isinstance(value, float): knob = nuke.Double_Knob(name, nice) knob.setValue(value) elif isinstance(value, bool): knob = nuke.Boolean_Knob(name, nice) knob.setValue(value) knob.setFlag(nuke.STARTLINE) elif isinstance(value, int): knob = nuke.Int_Knob(name, nice) knob.setValue(value) elif isinstance(value, string_types): knob = nuke.String_Knob(name, nice) knob.setValue(value) elif isinstance(value, list): knob = nuke.Enumeration_Knob(name, nice, value) elif isinstance(value, dict): if all(isinstance(v, dict) for v in value.values()): # Create a group of tabs begin = nuke.BeginTabGroup_Knob(name) end = nuke.EndTabGroup_Knob() begin.setName(name) begin.setLabel(nice) end.setName(name) knobs.append(begin) for k, v in value.items(): tab_name = "%s:%s" % (name, k) knobs.append(nuke.Tab_Knob(tab_name, k)) knobs += create_knobs(v, tab=tab_name) knobs.append(end) else: # Create a group of knobs knobs.append(nuke.Tab_Knob(name, nice, nuke.TABBEGINGROUP)) knobs += create_knobs(value, tab=name) knobs.append(nuke.Tab_Knob(name, nice, nuke.TABENDGROUP)) continue else: raise TypeError("Unsupported type: %r" % type(value)) knobs.append(knob) return knobs