You probably want to use a PythonPanel
, rather than the old-style Panel
, which is basically a TCL wrapper. That way, you can get callbacks when the knobs in the panel are changed.
Here's a basic example:
import os
import nuke
import nukescripts.panels
class ProjectManager(nukescripts.panels.PythonPanel):
def __init__(self, rootDir='/Volumes/Production_02/000_jobs/projects'):
super(ProjectManager, self).__init__('ProjectManager', 'id.ProjectManager')
self.rootDir = rootDir
self.project = self.sequence = self.shot = None
projectDirs = [x for x in os.listdir(rootDir)
if os.path.isdir(os.path.join(rootDir, x))]
self.project = projectDirs[0]
self.projectEnum = nuke.Enumeration_Knob('project', 'project', projectDirs)
self.addKnob(self.projectEnum)
self.seqEnum = nuke.Enumeration_Knob('sequence', 'sequence', [])
self.addKnob(self.seqEnum)
self.shotEnum = nuke.Enumeration_Knob('shot', 'shot', [])
self.addKnob(self.shotEnum)
self._projectChanged()
def _projectChanged(self):
self.project = self.projectEnum.value()
projectDir = os.path.join(self.rootDir, self.project)
projectSeqDirs = [x for x in os.listdir(projectDir)
if os.path.isdir(os.path.join(projectDir, x))]
self.seqEnum.setValues(projectSeqDirs)
self._sequenceChanged()
def _sequenceChanged(self):
s = self.seqEnum.value()
if s:
self.sequence = s
seqDir = os.path.join(self.rootDir, self.project, s)
seqShotDirs = [x for x in os.listdir(seqDir)
if os.path.isdir(os.path.join(seqDir, x))]
else:
self.sequence = None
seqShotDirs = []
self.shotEnum.setValues(seqShotDirs)
self._shotChanged()
def knobChanged(self, knob):
if knob is self.projectEnum:
self._projectChanged()
elif knob is self.seqEnum:
self._sequenceChanged()
elif knob is self.shotEnum:
self.shot = self.shotEnum.value()
p = ProjectManager()
if p.showModalDialog():
print p.project, p.sequence, p.shot
Note that this example is only to demonstrate the basic design of a PythonPanel
subclass. It has a few small logic issues (in the context of Nuke), and is written to be as clear as possible, rather than as efficient or idiomatic as possible.
Anyway, hopefully this gives you an idea of how to go about building what you're after.