Skip to content

Commit

Permalink
added more tests for ada.nuke.node. fixed some bugs from the testing.…
Browse files Browse the repository at this point in the history
… added some new util functions has_ada_tab, can_cast and monkey_patch decorator.
  • Loading branch information
masterkeech committed Jul 21, 2019
1 parent 6225d19 commit eb28449
Show file tree
Hide file tree
Showing 6 changed files with 386 additions and 262 deletions.
2 changes: 1 addition & 1 deletion src/ada/nuke/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ada.core.common import getLog


class Engine:
class Engine(object):
"""
Engine is the core class for executing Ada in Nuke. When passing a template in from the cli the static method
fuel is called to inject the user specified template into nuke then all the nodes will be gathered and executed
Expand Down
10 changes: 5 additions & 5 deletions src/ada/nuke/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
KnobOutput = namedtuple("Output", "knob alias default_value")

ADA_KNOBS = [
"knobs_to_bake_knobs",
"knobs_to_knobs_to_bake",
"knobs_to_set_knobs",
"knobs_to_knobs_to_set",
"bake_knobs",
"knobs_to_bake",
"set_knobs",
"knobs_to_set",
"execute_knobs",
"knobs_to_execute",
"execute_code",
"code_to_execute",
"queue_order",
"do_not_knobs_to_bake",
"do_not_bake",
"knobs_to_serialise",
"ada",
]
Expand Down
111 changes: 111 additions & 0 deletions src/ada/nuke/gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import nuke
import nukescripts.panels


from .utils import deserialise_knobs_to_serialise, get_class_name

__all__ = ["AddKnobsToAda"]


class AddKnobsToAda(nukescripts.panels.PythonPanel):

def __init__(self, node):
if nuke.GUI:
raise RuntimeError("unable to create AddKnobsToAda in gui mode")

nukescripts.PythonPanel.__init__(self, "com.ada.AliasCreator")
# CREATE KNOBS
self.node = node
self.class_name = get_class_name(node)
self.knobs = dict()
self.alias_knobs = list()

self.node_name = nuke.Text_Knob("node", "Node:", node.name())
self.addKnob(self.node_name)

def create_knobs(self):
knobs = extract_knobs(self.node)
if not knobs:
nuke.message("No knobs can be set on this node")
return False

self.node_name = nuke.Text_Knob("node ", "Node: ", self.node.name())

for knob in knobs:

ada_knob = deserialise_knobs_to_serialise(
self.node["knobs_to_serialise"], prune=knob.name()
)

this_knob_name = knob.name()

knob_name = nuke.Text_Knob(
"{} ".format(this_knob_name), "Knob: ", this_knob_name
)

knob_is_input = this_knob_name in INPUT_NODES.get(self.class_name, [])
knob_is_output = this_knob_name in OUTPUT_NODES.get(self.class_name, [])

self.addKnob(knob_name)
if knob_is_input:
new_knob_name = "input_{}".format(this_knob_name)
data_knob = nuke.String_Knob(new_knob_name, "Input: ")
if ada_knob:
data_knob.setValue(ada_knob.alias)
self.alias_knobs.append(data_knob)

elif knob_is_output:
new_knob_name = "output_{}".format(this_knob_name)
data_knob = nuke.String_Knob(new_knob_name, "Output: ")
if ada_knob:
data_knob.setValue(ada_knob.alias)
self.alias_knobs.append(data_knob)
else:
new_knob_name = "alias_{} ".format(this_knob_name)
data_knob = nuke.String_Knob(new_knob_name, "Alias: ")
if ada_knob:
data_knob.setValue(ada_knob.alias)
self.alias_knobs.append(data_knob)

try:
self.addKnob(data_knob)

except RuntimeError:
getLog().warning("Ada: Unable to add knob alias, input or output!")

default_knob = "default_{} ".format(knob.name())

try:
value = knob.evaluate()
except AttributeError:
value = knob.value()

default_value = nuke.String_Knob(
default_knob, "Default Value: ", str(value)
)
default_value.clearFlag(nuke.STARTLINE)

self.knobs[new_knob_name] = (default_value, knob.name())

self.addKnob(default_value)

return True


def extract_knobs(node):
knobs = []
knob_names = []
for knob in range(node.numKnobs()):
knob = node.knob(knob)
knob_name = knob.name()
if (
knob.visible()
and knob_name != ""
and knob.enabled()
and knob_name not in knob_names
and knob_name not in IGNORE_KNOBS
):
knobs.append(knob)
knob_names.append(knob_name)

return knobs
Loading

0 comments on commit eb28449

Please sign in to comment.