From 7f06540c0cd3ea583d8652bacef0db604c5f0131 Mon Sep 17 00:00:00 2001 From: dbr Date: Tue, 16 Oct 2012 17:58:37 +1030 Subject: [PATCH] nuke: Trigger loadCDLFromFile when changing cccid 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 #277 --- share/nuke/ocionuke/cdl.py | 58 +++++++++++-------- src/core/CDLTransform.cpp | 2 +- .../OCIOCDLTransform/OCIOCDLTransform.cpp | 10 +--- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/share/nuke/ocionuke/cdl.py b/share/nuke/ocionuke/cdl.py index 9ed76aec91..4b086ca5ed 100644 --- a/share/nuke/ocionuke/cdl.py +++ b/share/nuke/ocionuke/cdl.py @@ -2,7 +2,6 @@ """ import nuke -import nukescripts import PyOpenColorIO as OCIO import xml.etree.ElementTree as ET @@ -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): diff --git a/src/core/CDLTransform.cpp b/src/core/CDLTransform.cpp index 0e321ff29a..3a197b7433 100644 --- a/src/core/CDLTransform.cpp +++ b/src/core/CDLTransform.cpp @@ -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()); diff --git a/src/nuke/OCIOCDLTransform/OCIOCDLTransform.cpp b/src/nuke/OCIOCDLTransform/OCIOCDLTransform.cpp index 51ec86630e..df7ee0f6b7 100644 --- a/src/nuke/OCIOCDLTransform/OCIOCDLTransform.cpp +++ b/src/nuke/OCIOCDLTransform/OCIOCDLTransform.cpp @@ -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(); @@ -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") {