Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
389b2c96c9 |
@@ -0,0 +1,19 @@
|
||||
# Changelog
|
||||
|
||||
## [1.0.1] - 2025-09-23
|
||||
|
||||
### Fixed
|
||||
- **Index-Label Correspondence**: Fixed the issue where index and label were not properly matched in the dropdown menu
|
||||
- **Dropdown Order**: Corrected the dropdown menu to display labels in their original input order instead of alphabetical order
|
||||
- **Workflow Migration**: Resolved the issue where label states and counts were lost during workflow migration between machines
|
||||
|
||||
### Technical Improvements
|
||||
- Modified `write_labels_to_file` function in `__init__.py` to preserve original input order
|
||||
- Improved filtering logic to only remove empty and whitespace-only strings
|
||||
- Enhanced data integrity during workflow serialization/deserialization
|
||||
|
||||
## [1.0.0] - Initial Release
|
||||
- Basic Switch Any node functionality
|
||||
- Dynamic label input system
|
||||
- UI refresh button integration
|
||||
- JSON-based label persistence
|
||||
@@ -10,10 +10,13 @@ This is a custom node for ComfyUI that provides a dynamic "Switch" for routing p
|
||||
|
||||
## Features
|
||||
|
||||
- **Clean Initial State**: New nodes start completely empty with no preset data, ready for custom configuration.
|
||||
- **Dynamic Label Inputs**: Start with a single label input. As you fill them in, new empty inputs appear automatically after a refresh.
|
||||
- **UI Refresh Button**: A **"Save & Refresh UI"** button is included directly on the node. This saves your current labels and reloads the ComfyUI interface in one click, updating the dropdown menu and input fields instantly.
|
||||
- **No Data Input**: This node is purely for routing and does not take any data inputs. It only outputs the selected `index` (INT) and `label` (STRING).
|
||||
- **Persistent Labels**: Your list of labels is saved in a JSON file within the node's directory, so they persist across ComfyUI sessions.
|
||||
- **Order Preservation**: Labels maintain their original input order in the dropdown menu, ensuring consistent index-label correspondence.
|
||||
- **Workflow Migration**: All label states are fully preserved when migrating workflows between different machines.
|
||||
|
||||
## How to Use
|
||||
|
||||
@@ -21,13 +24,14 @@ This is a custom node for ComfyUI that provides a dynamic "Switch" for routing p
|
||||
2. **Define Labels**:
|
||||
- Initially, you will see one input field, `label_1`. Enter a name for your first route (e.g., "SDXL").
|
||||
- To add more labels, you can fill in the next available input field (`label_2`, etc.).
|
||||
- **Note**: Labels are processed in the exact order they are entered, maintaining index-label correspondence.
|
||||
3. **Save and Refresh**:
|
||||
- Click the **"Save & Refresh UI"** button on the node.
|
||||
- Click the **"Save & Refresh UI**" button on the node.
|
||||
- The page will automatically reload.
|
||||
4. **Select a Label**:
|
||||
- After reloading, the `select_label` dropdown menu will be populated with all the labels you defined.
|
||||
- After reloading, the `select_label` dropdown menu will be populated with all the labels you defined, displayed in their original input order.
|
||||
- The node will now show all your saved labels plus one new empty input field for the next one.
|
||||
5. **Get Output**: The node will output the 1-based `index` and the `label` string of your selection from the dropdown menu.
|
||||
5. **Get Output**: The node will output the 1-based `index` and the `label` string of your selection from the dropdown menu. The index corresponds exactly to the input order.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -45,6 +49,7 @@ This is a custom node for ComfyUI that provides a dynamic "Switch" for routing p
|
||||
|
||||
## 功能特性
|
||||
|
||||
- **干净的初始状态**: 新节点完全为空,不包含预设数据,可进行自定义配置。
|
||||
- **动态标签输入**: 从一个标签输入框开始。当您填写后,刷新界面即可自动出现新的空输入框。
|
||||
- **UI 刷新按钮**: 节点上直接集成了一个 **"Save & Refresh UI"** 按钮。一键即可保存当前所有标签并重新加载 ComfyUI 界面,即时更新下拉菜单和输入框。
|
||||
- **无数据输入**: 这是一个纯粹的路由节点,不接收任何数据输入。它只输出所选的 `index` (整数) 和 `label` (字符串)。
|
||||
@@ -68,4 +73,18 @@ This is a custom node for ComfyUI that provides a dynamic "Switch" for routing p
|
||||
|
||||
1. 克隆或下载此仓库。
|
||||
2. 将 `ComfyUI_Switch` 文件夹放入 `ComfyUI/custom_nodes/` 目录下。
|
||||
3. 重启 ComfyUI。
|
||||
3. 重启 ComfyUI。
|
||||
|
||||
---
|
||||
|
||||
## 更新日志
|
||||
|
||||
### 修复的问题
|
||||
- ✅ **index-label对应关系**: 修复了标签索引与显示名称不对应的问题
|
||||
- ✅ **下拉框排序**: 修复了下拉菜单中标签按字母排序而非输入顺序的问题
|
||||
- ✅ **工作流迁移**: 修复了工作流迁移时标签数量和状态丢失的问题
|
||||
|
||||
### 技术改进
|
||||
- 优化了标签处理逻辑,保持原始输入顺序
|
||||
- 改进了空字符串和空白字符串的过滤机制
|
||||
- 增强了工作流迁移时的数据完整性
|
||||
+6
-7
@@ -25,12 +25,12 @@ def read_labels_from_file():
|
||||
def write_labels_to_file(labels):
|
||||
"""将给定的标签列表保存到JSON文件中。"""
|
||||
try:
|
||||
# 过滤空字符串,排序并去重
|
||||
unique_labels = sorted(list(set(label for label in labels if label)))
|
||||
# 过滤空字符串和空白字符串,保持原始顺序和重复项
|
||||
filtered_labels = [label for label in labels if label and str(label).strip()]
|
||||
existing_labels = read_labels_from_file()
|
||||
if unique_labels != existing_labels:
|
||||
if filtered_labels != existing_labels:
|
||||
with open(LABELS_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(unique_labels, f, indent=2)
|
||||
json.dump(filtered_labels, f, indent=2)
|
||||
except IOError as e:
|
||||
print(f"[Switch Any] ERROR: Could not write labels to file: {e}")
|
||||
|
||||
@@ -55,9 +55,8 @@ class SwitchAny:
|
||||
"optional": {}
|
||||
}
|
||||
|
||||
num_to_show = min(len(saved_labels) + 1, MAX_INPUTS)
|
||||
|
||||
for i in range(1, num_to_show + 1):
|
||||
# 总是显示MAX_INPUTS个输入框,确保工作流迁移时状态完整
|
||||
for i in range(1, MAX_INPUTS + 1):
|
||||
default_value = saved_labels[i-1] if i <= len(saved_labels) else ""
|
||||
inputs["optional"][f"label_{i}"] = ("STRING", {
|
||||
"default": default_value,
|
||||
|
||||
Binary file not shown.
+9
-1
@@ -1 +1,9 @@
|
||||
# Minimal requirements for this node (none required by default)
|
||||
# Requirements for ComfyUI Switch Any Node
|
||||
# This node requires ComfyUI to be installed first
|
||||
|
||||
# Core dependencies (usually included with ComfyUI)
|
||||
# No additional packages required for basic functionality
|
||||
|
||||
# Optional: For development and testing
|
||||
# pytest>=7.0.0
|
||||
# black>=22.0.0
|
||||
Reference in New Issue
Block a user