+ DictAddString

This commit is contained in:
Lex Darlog (DRL)
2026-04-20 23:42:02 -03:00
parent 331cf9f166
commit 644ffe0b00
+59
View File
@@ -64,6 +64,58 @@ class DictAddAny(_BaseNode):
result = _new_dict_with_updated_key(dict, name, value)
return _io.NodeOutput(result)
# ----------------------------------------------------------
class DictAddString(_BaseNode):
"""Add/update a string to a Format-Dict."""
_schema = _io.Schema(
node_id=f'DictAddString{_pack_id}',
display_name='Add String to Dict',
category=_category_dict,
description=_format_docstring(_cleandoc(__doc__)),
inputs=[
_io.String.Input(
'name',
tooltip=(
"Name (key) of the string inserted into the dict. "
"It must comprise only of latin letters, digits and underscores + it can't start with a digit."
),
),
_io.Boolean.Input(
'cleanup',
tooltip=(
"When enabled, each line in the sub-string is stripped "
"from any spaces at its start and end."
),
default=True,
label_on='leading/trailing spaces',
label_off='no',
),
_io.String.Input(
'string',
tooltip="The actual string to add into the dict.",
multiline=True,
),
_DICT_INPUT_OPTIONAL,
],
outputs=[_DICT_OUTPUT],
)
@classmethod
def execute(cls,
name: str, cleanup: bool, string: str,
dict: _O[_FormatDict] = None,
) -> _io.NodeOutput:
"""Update/append a string to the dict."""
string = '' if string is None else str(string)
if cleanup:
string = '\n'.join(
x.strip() for x in string.splitlines()
)
result= _new_dict_with_updated_key(dict, name, string)
return _io.NodeOutput(result)
# ==========================================================
# Deprecated nodes with old IDs (for backwards compatibility)
@@ -74,3 +126,10 @@ class DictAddAnyOld1(DictAddAny):
DictAddAny._schema,
'StringConstructorDictAddAny'
)
class DictAddStringOld1(DictAddString):
_schema = _schema_old_name(
DictAddString._schema,
'StringConstructorDictAddString'
)