mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 00:44:52 +01:00
Nuke: abstracting function for correct knob type value
This commit is contained in:
parent
44655d2515
commit
e33c06f95e
2 changed files with 28 additions and 19 deletions
|
|
@ -26,7 +26,8 @@ from .pipeline import (
|
|||
update_container,
|
||||
)
|
||||
from .lib import (
|
||||
maintained_selection
|
||||
maintained_selection,
|
||||
convert_knob_value_to_correct_type
|
||||
)
|
||||
|
||||
from .utils import (
|
||||
|
|
@ -58,6 +59,7 @@ __all__ = (
|
|||
"update_container",
|
||||
|
||||
"maintained_selection",
|
||||
"convert_knob_value_to_correct_type",
|
||||
|
||||
"colorspace_exists_on_node",
|
||||
"get_colorspace_list"
|
||||
|
|
|
|||
|
|
@ -1528,28 +1528,35 @@ def set_node_knobs_from_settings(node, knob_settings, **kwargs):
|
|||
if not knob_value:
|
||||
continue
|
||||
|
||||
# first convert string types to string
|
||||
# just to ditch unicode
|
||||
if isinstance(knob_value, six.text_type):
|
||||
knob_value = str(knob_value)
|
||||
|
||||
# set correctly knob types
|
||||
if knob_type == "bool":
|
||||
knob_value = bool(knob_value)
|
||||
elif knob_type == "decimal_number":
|
||||
knob_value = float(knob_value)
|
||||
elif knob_type == "number":
|
||||
knob_value = int(knob_value)
|
||||
elif knob_type == "text":
|
||||
knob_value = knob_value
|
||||
elif knob_type == "color_gui":
|
||||
knob_value = color_gui_to_int(knob_value)
|
||||
elif knob_type in ["2d_vector", "3d_vector", "color"]:
|
||||
knob_value = [float(v) for v in knob_value]
|
||||
knob_value = convert_knob_value_to_correct_type(
|
||||
knob_type, knob_value)
|
||||
|
||||
node[knob_name].setValue(knob_value)
|
||||
|
||||
|
||||
def convert_knob_value_to_correct_type(knob_type, knob_value):
|
||||
# first convert string types to string
|
||||
# just to ditch unicode
|
||||
if isinstance(knob_value, six.text_type):
|
||||
knob_value = str(knob_value)
|
||||
|
||||
# set correctly knob types
|
||||
if knob_type == "bool":
|
||||
knob_value = bool(knob_value)
|
||||
elif knob_type == "decimal_number":
|
||||
knob_value = float(knob_value)
|
||||
elif knob_type == "number":
|
||||
knob_value = int(knob_value)
|
||||
elif knob_type == "text":
|
||||
knob_value = knob_value
|
||||
elif knob_type == "color_gui":
|
||||
knob_value = color_gui_to_int(knob_value)
|
||||
elif knob_type in ["2d_vector", "3d_vector", "color"]:
|
||||
knob_value = [float(v) for v in knob_value]
|
||||
|
||||
return knob_value
|
||||
|
||||
|
||||
def color_gui_to_int(color_gui):
|
||||
hex_value = (
|
||||
"0x{0:0>2x}{1:0>2x}{2:0>2x}{3:0>2x}").format(*color_gui)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue