diff --git a/nodes/d2_nodes.py b/nodes/d2_nodes.py index fb83bf6..d86fce3 100644 --- a/nodes/d2_nodes.py +++ b/nodes/d2_nodes.py @@ -1,7 +1,6 @@ import torch import math import os -import glob import json import hashlib import re @@ -101,24 +100,18 @@ class D2_FolderImageQueue: CATEGORY = "D2" ###### - def run(self, folder = "", extension="*.*", start_at=0, batch_count=1): - files = D2_FolderImageQueue.get_files(folder, extension) + def run(self, folder = "", extension="*.*", start_at=0, auto_queue=True, image_count=""): + files = util.get_files(folder, extension) image_path = files[start_at - 1] return { "result": (image_path,), - "ui": {"message":(image_path, start_at,)} + "ui": { + "image_count": (len(files),), + "start_at": (start_at,), + } } - @classmethod - def get_files(cls, folder, extension): - search_pattern = os.path.join(folder, extension) - file_list = glob.glob(search_pattern) - # ソートして絶対パスに変換 - file_list = sorted(file_list, key=lambda x: os.path.basename(x)) - file_list = [os.path.abspath(file) for file in file_list] - return file_list - """ 対象画像枚数を取得 diff --git a/nodes/d2_xy_nodes.py b/nodes/d2_xy_nodes.py index e1706fc..41c2bd2 100644 --- a/nodes/d2_xy_nodes.py +++ b/nodes/d2_xy_nodes.py @@ -66,7 +66,6 @@ class D2_XYPlot: x_len = len(x_array) y_len = len(y_array) total = x_len * y_len - print("//////////// - ", index, " / ", total) # 採用する値 x_value = x_array[index % x_len] @@ -83,10 +82,6 @@ class D2_XYPlot: x_annotation = {"title":x_title, "values":x_array}, y_annotation = {"title":y_title, "values":y_array}, - print(x_value) - print(y_value) - print(trigger) - return { "result": (x_value, y_value, x_annotation, y_annotation, trigger,), "ui": { @@ -216,7 +211,6 @@ class D2_XYGridImage: """ D2 XY Checkpoint List -Checkpointのフルパスを取得できる Checkpoint List """ class D2_XYCheckpointList: @@ -225,26 +219,57 @@ class D2_XYCheckpointList: ckpt_input = ["None"] +folder_paths.get_filename_list("checkpoints") inputs = { "required": { + "separator": (util.SEPARATOR,), "ckpt_count": ("INT", {"default": 3, "min": 0, "max": 50, "step": 1}), } } - for i in range(1, 50): inputs["required"][f"ckpt_name_{i}"] = (ckpt_input,) return inputs - RETURN_TYPES = ("LIST","STRING",) - RETURN_NAMES = ("list","list_str") + RETURN_TYPES = ("STRING", "LIST") + RETURN_NAMES = ("STRING", "LIST") FUNCTION = "run" CATEGORY = "D2/XY Plot" - def run(self, ckpt_count, **kwargs): + def run(self, separator, ckpt_count, **kwargs): ckpt_list = [kwargs.get(f"ckpt_name_{i}") for i in range(1, ckpt_count + 1)] - ckpt_list_str = "\n".join(ckpt_list) + ckpt_list_str = util.list_to_text(ckpt_list, separator) return (ckpt_list, ckpt_list_str,) +""" + +D2 XY Lora List + +""" +class D2_XYLoraList: + @classmethod + def INPUT_TYPES(cls): + lora_input = ["None"] +folder_paths.get_filename_list("loras") + inputs = { + "required": { + "separator": (util.SEPARATOR,), + "lora_count": ("INT", {"default": 3, "min": 0, "max": 50, "step": 1}), + } + } + for i in range(1, 50): + inputs["required"][f"lora_name_{i}"] = (lora_input,) + + return inputs + + RETURN_TYPES = ("STRING", "LIST") + RETURN_NAMES = ("STRING", "LIST") + FUNCTION = "run" + CATEGORY = "D2/XY Plot" + + def run(self, separator, lora_count, **kwargs): + lora_list = [kwargs.get(f"lora_name_{i}") for i in range(1, lora_count + 1)] + lora_list_str = util.list_to_text(lora_list, separator) + return (lora_list, lora_list_str,) + + """ D2 XYPromptSR @@ -287,7 +312,7 @@ class D2_XYListToString: return { "required": { "LIST": ("LIST",), - "separator": (["Line break", ",", ";"],), + "separator": (util.SEPARATOR,), } } @@ -297,20 +322,53 @@ class D2_XYListToString: CATEGORY = "D2/XY Plot" def run(self, LIST, separator): - separator = "\n" if separator == "Line break" else separator - output = separator.join(LIST) - return (output,) + output = util.list_to_text(LIST, separator) + return { + "result": (output,), + } +""" + +D2 XY Folder Images +フォルダ内画像を渡す + +""" +class D2_XYFolderImages: + @classmethod + def INPUT_TYPES(cls): + return { + "required":{ + "folder": ("STRING", {"default": ""}), + "extension": ("STRING", {"default": "*.*"}), + "separator": (util.SEPARATOR,), + }, + } + + RETURN_TYPES = ("STRING", "LIST",) + RETURN_NAMES = ("STRING", "LIST",) + FUNCTION = "run" + CATEGORY = "D2/XY Plot" + + ###### + def run(self, folder, extension, separator): + files = util.get_files(folder, extension) + output = util.list_to_text(files, separator) + return { + "result": (output, files,), + } + NODE_CLASS_MAPPINGS = { "D2 XY Plot": D2_XYPlot, "D2 XY Grid Image": D2_XYGridImage, "D2 XY Checkpoint List": D2_XYCheckpointList, + "D2 XY Lora List": D2_XYLoraList, "D2 XY Prompt SR": D2_XYPromptSR, "D2 XY List To String": D2_XYListToString, + "D2 XY Folder Images": D2_XYFolderImages, } diff --git a/nodes/modules/util.py b/nodes/modules/util.py index 12a2bae..200d616 100644 --- a/nodes/modules/util.py +++ b/nodes/modules/util.py @@ -1,6 +1,7 @@ import os import yaml import math +import glob import shutil from PIL import Image import numpy as np @@ -12,7 +13,7 @@ from comfy.cli_args import args MAX_RESOLUTION = 16384 - +SEPARATOR = ["Line break", ",", ";"] """ 入出力をANYにするもの @@ -21,6 +22,13 @@ class AnyType(str): def __ne__(self, __value: object) -> bool: return False +""" +リストを文字結合する +""" +def list_to_text(list, separator): + separator = "\n" if separator == "Line break" else separator + return separator.join(list) + """ 設定ファイルを読み込む @@ -50,6 +58,16 @@ def get_config_path(filename): config_path = get_root_path() / 'config' return config_path / filename +""" +ファイルリスト取得 +""" +def get_files(folder, extension): + search_pattern = os.path.join(folder, extension) + file_list = glob.glob(search_pattern) + # ソートして絶対パスに変換 + file_list = sorted(file_list, key=lambda x: os.path.basename(x)) + file_list = [os.path.abspath(file) for file in file_list] + return file_list """ diff --git a/web/D2_CheckpointList.js b/web/D2_CheckpointList.js index 625a459..6bfaff5 100644 --- a/web/D2_CheckpointList.js +++ b/web/D2_CheckpointList.js @@ -3,10 +3,10 @@ import { findWidgetByName, handleWidgetsVisibility } from "./utils.js"; app.registerExtension({ - name: "Comfy.D2.D2_CheckpointList", + name: "Comfy.D2.D2_XYCheckpointList", nodeCreated(node) { - if (node.constructor.title == "D2 Checkpoint List"){ + if (node.constructor.title == "D2 XY Checkpoint List"){ if (node.widgets){ const countWidget = findWidgetByName(node, "ckpt_count"); let widgetValue = countWidget.value; diff --git a/web/D2_LoraList.js b/web/D2_LoraList.js new file mode 100644 index 0000000..4ed74a5 --- /dev/null +++ b/web/D2_LoraList.js @@ -0,0 +1,30 @@ +import { app } from "/scripts/app.js"; +import { findWidgetByName, handleWidgetsVisibility } from "./utils.js"; + + +app.registerExtension({ + name: "Comfy.D2.D2_XYLoraList", + + nodeCreated(node) { + if (node.constructor.title == "D2 XY Lora List"){ + if (node.widgets){ + const countWidget = findWidgetByName(node, "lora_count"); + let widgetValue = countWidget.value; + handleWidgetsVisibility(node, widgetValue, ["lora_name"]) + + // lora_count.value の再定義 + Object.defineProperty(countWidget, 'value', { + get() { + return widgetValue; + }, + set(newVal) { + if (newVal !== widgetValue) { + widgetValue = newVal; + handleWidgetsVisibility(node, newVal, ["lora_name"]) + } + } + }); + } + } + } +});