enums: v3 + validators
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
# encoding: utf-8
|
||||
"""
|
||||
Pre-defined combo-inputs for Node-v3, shared between nodes.
|
||||
"""
|
||||
|
||||
from comfy_api.latest import io as _io
|
||||
|
||||
from .enums import *
|
||||
from .docstring_formatter import format_object_docstring as _format_object_docstring
|
||||
|
||||
|
||||
res_priority_in = _io.Combo.Input(
|
||||
'priority', options=RoundingPriority.all_values(),
|
||||
default=RoundingPriority.ORIGINAL,
|
||||
tooltip=_format_object_docstring(RoundingPriority),
|
||||
)
|
||||
res_priority_out = _io.Combo.Output(
|
||||
# In v3 schema, IDs must be unique between BOTH lists: inputs and outputs, so uppercase ID + `display_name`:
|
||||
'PRIORITY', display_name='priority', options=RoundingPriority.all_values(),
|
||||
)
|
||||
|
||||
crop_pad_strategy_in = _io.Combo.Input(
|
||||
'strategy', options=UpscaledCropPadStrategy.all_values(),
|
||||
default=UpscaledCropPadStrategy.PAD, tooltip=_format_object_docstring(UpscaledCropPadStrategy)
|
||||
)
|
||||
crop_pad_strategy_out = _io.Combo.Output(
|
||||
'STRATEGY', display_name='strategy', options=UpscaledCropPadStrategy.all_values(),
|
||||
)
|
||||
@@ -1,10 +1,8 @@
|
||||
# encoding: utf-8
|
||||
"""
|
||||
Internal enums.
|
||||
Internal enums: option choices, shared between nodes.
|
||||
"""
|
||||
|
||||
import typing as _t
|
||||
|
||||
try:
|
||||
from enum import StrEnum as _StrEnum
|
||||
except ImportError:
|
||||
@@ -13,9 +11,13 @@ except ImportError:
|
||||
|
||||
class __BaseEnum(_StrEnum):
|
||||
@classmethod
|
||||
def all_values(cls) -> _t.Tuple[str, ...]:
|
||||
def all_values(cls) -> tuple[str, ...]:
|
||||
return tuple(x.value for x in cls)
|
||||
|
||||
@classmethod
|
||||
def validate(cls, value) -> str:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class RoundingPriority(__BaseEnum):
|
||||
"""
|
||||
@@ -35,6 +37,16 @@ class RoundingPriority(__BaseEnum):
|
||||
ORIGINAL = 'original'
|
||||
UPSCALED = 'upscaled'
|
||||
|
||||
@classmethod
|
||||
def validate(cls, value) -> str:
|
||||
if value not in _res_priority_values_set:
|
||||
raise ValueError(f"Invalid value for resolution priority: {value!r}\nExpected one of: {_res_priority_values!r}")
|
||||
return str(value)
|
||||
|
||||
|
||||
_res_priority_values = RoundingPriority.all_values()
|
||||
_res_priority_values_set = set(RoundingPriority.all_values())
|
||||
|
||||
|
||||
class UpscaledCropPadStrategy(__BaseEnum):
|
||||
"""
|
||||
@@ -55,3 +67,13 @@ class UpscaledCropPadStrategy(__BaseEnum):
|
||||
CROP = 'crop only'
|
||||
NEAREST = 'nearest'
|
||||
EXACT_UPSCALE = 'exact-upscale'
|
||||
|
||||
@classmethod
|
||||
def validate(cls, value) -> str:
|
||||
if value not in _up_strategy_values_set:
|
||||
raise ValueError(f"Invalid value for upscale strategy: {value!r}\nExpected one of: {_up_strategy_values!r}")
|
||||
return str(value)
|
||||
|
||||
|
||||
_up_strategy_values = UpscaledCropPadStrategy.all_values()
|
||||
_up_strategy_values_set = set(UpscaledCropPadStrategy.all_values())
|
||||
|
||||
Reference in New Issue
Block a user