Skip to content

Commit

Permalink
nuke: Trigger loadCDLFromFile when changing cccid
Browse files Browse the repository at this point in the history
core: Better error when loading bad cccid

Adds single-quotes around cccid, to be consistent with other errors,
and avoid confusion when loading a blank cccid:

The specified cccid '' could not be found in file '/tmp/test.ccc'.

nuke: delay import of nukescripts in ocionuke.cdl

nukescripts.PythonPanel isn't defined until menu.py time, so which
causes errors if ocionuke.cdl is imported in a non-GUI session

Fixes part of AcademySoftwareFoundation#277
  • Loading branch information
dbr authored and Sean Looper committed Sep 10, 2013
1 parent 30a23db commit 7f06540
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
58 changes: 33 additions & 25 deletions share/nuke/ocionuke/cdl.py
Expand Up @@ -2,7 +2,6 @@
"""

import nuke
import nukescripts
import PyOpenColorIO as OCIO
import xml.etree.ElementTree as ET

Expand Down Expand Up @@ -101,35 +100,44 @@ def _cdltransforms_to_xml(allcc):
return ET.tostring(root)


class SelectCCCIDPanel(nukescripts.PythonPanel):
"""Allows the user to select from a list of CDLTransform
objects
"""
def SelectCCCIDPanel(*args, **kwargs):
# Wrap class definition in a function, so nukescripts.PythonPanel
# is only accessed when ``SelectCCCIDPanel()`` is called,
# https://github.com/imageworks/OpenColorIO/issues/277

def __init__(self, allcdl):
super(SelectCCCIDPanel, self).__init__()
self.available = {}
for cur in allcdl:
self.available[cur.getID()] = cur
import nukescripts

self.addKnob(nuke.Enumeration_Knob("cccid", "cccid", self.available.keys()))
self.addKnob(nuke.Text_Knob("divider"))
self.addKnob(nuke.Color_Knob("slope"))
self.addKnob(nuke.Color_Knob("offset"))
self.addKnob(nuke.Color_Knob("power"))
self.addKnob(nuke.Double_Knob("saturation"))
class _SelectCCCIDPanel(nukescripts.PythonPanel):
"""Allows the user to select from a list of CDLTransform
objects
"""

def selected(self):
return self.available[self.knobs()['cccid'].value()]
def __init__(self, allcdl):
super(_SelectCCCIDPanel, self).__init__()
self.available = {}
for cur in allcdl:
self.available[cur.getID()] = cur

def knobChanged(self, knob):
"""When the user selects a cccid, a grade-preview knobs are set.
self.addKnob(nuke.Enumeration_Knob("cccid", "cccid", self.available.keys()))
self.addKnob(nuke.Text_Knob("divider"))
self.addKnob(nuke.Color_Knob("slope"))
self.addKnob(nuke.Color_Knob("offset"))
self.addKnob(nuke.Color_Knob("power"))
self.addKnob(nuke.Double_Knob("saturation"))

This method is triggered when any knob is changed, which has the
useful side-effect of preventing changing the preview values, while
keeping them selectable for copy-and-paste.
"""
_cdltransform_to_node(self.selected(), self.knobs())
def selected(self):
return self.available[self.knobs()['cccid'].value()]

def knobChanged(self, knob):
"""When the user selects a cccid, a grade-preview knobs are set.
This method is triggered when any knob is changed, which has the
useful side-effect of preventing changing the preview values, while
keeping them selectable for copy-and-paste.
"""
_cdltransform_to_node(self.selected(), self.knobs())

return _SelectCCCIDPanel(*args, **kwargs)


def export_as_cc(node = None, filename = None):
Expand Down
2 changes: 1 addition & 1 deletion src/core/CDLTransform.cpp
Expand Up @@ -454,7 +454,7 @@ OCIO_NAMESPACE_ENTER
{
std::ostringstream os;
os << "Error loading ccc xml. ";
os << "The specified cccid " << cccid << " ";
os << "The specified cccid '" << cccid << "' ";
os << "could not be found in file '";
os << src << "'.";
throw Exception(os.str().c_str());
Expand Down
10 changes: 1 addition & 9 deletions src/nuke/OCIOCDLTransform/OCIOCDLTransform.cpp
Expand Up @@ -160,7 +160,7 @@ int OCIOCDLTransform::knob_changed(DD::Image::Knob* k)
// return true if you want to continue to receive changes for this knob
std::string knobname = k->name();

if(knobname == "read_from_file")
if(knobname == "read_from_file" || knobname == "file" || knobname == "cccid")
{
refreshKnobEnabledState();

Expand All @@ -170,14 +170,6 @@ int OCIOCDLTransform::knob_changed(DD::Image::Knob* k)
}
return true;
}
else if(knobname == "file")
{
if(m_readFromFile)
{
loadCDLFromFile();
}
return true;
}

else if(knobname == "reload")
{
Expand Down

0 comments on commit 7f06540

Please sign in to comment.