getavalon / core

The safe post-production pipeline - https://getavalon.github.io/2.0
MIT License
218 stars 49 forks source link

Re-implement Nuke `imprint` #473

Closed davidlatwe closed 4 years ago

davidlatwe commented 4 years ago

This PR is the first step of refactoring #438, for resolving imprint which functionality was a bit rigid.

What's changed

About lib.imprint

Nuke has three categories of knobs, data-stored knob, layout knob and complex data knob, but let's put complex data knob aside for now.

On data-stored knob, imprint will create knob which fits to regular data types, like bool, int, float, str, list. For dict, it will become a group of knobs, or a group of tabs.

For example:

# Creating two group of knobs
node = nuke.createNode("NoOp")
data = {
    "group1": {
        "group1.var1": 5,
        "group1.var2": "hello",
        "group1.var3": ["a", "b"],
    },
    "group2": {
        "group2.var1": 6,
        "group2.var2": "world",
        "group2.var3": ["o", "p"],
    },
}
lib.imprint(node, data, tab="User")

Which you will get

image

And this:

data = {
    "tabGroup": {
        "tab1": {"count": 5},
        "tab2": {"isGood": True},
        "tab3": {"direction": ["Left", "Right"]},
    },
}
node = nuke.createNode("NoOp")
lib.imprint(node, data, tab="User")

Will looks like this

image

And if you wish to use other kind of knobs which is not mapped in lib.create_knob, you could use lib.Knobby, for example:

data = {
    # Using tuple as key for manual nice naming
    ("my_knob", "Nice Knob"): lib.Knobby("Text_Knob", "Non-editable text"),
    ("divider", ""): lib.Knobby("Text_Knob", ""),
    "MyFilePath": lib.Knobby("File_Knob", "/file/path"),
}
node = nuke.createNode("NoOp")
lib.imprint(node, data, tab="User")

And you have a file path knob

image


Hope this PR make sense to you, please let me know what you think. :relaxed:

mkolar commented 4 years ago

I like it. Certainly cleaner

davidlatwe commented 4 years ago

New minor changes

First two commits (7079c14, 9229fec) were the fixes to complete this PR. The rest were minor improvements.

It's good to be merged now, but I'll be out for travel starting tomorrow till next Thursday so if no other objections, merging this next weekend !

davidlatwe commented 4 years ago

Sorry, just spotted that updating container will create duplicated knobs if existed, commit dc82024 fixed that. And one more change is if given an invalid container node, TypeError will raised. (7715ebd)

That's it !!

jakubjezek001 commented 4 years ago

@davidlatwe this PR is awesome! Thanks for help ;)