diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0dc4fa4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/__init__.cpython-312.pyc +__pycache__/nodes.cpython-312.pyc diff --git a/nodes.py b/nodes.py index 62c1518..d6b8492 100644 --- a/nodes.py +++ b/nodes.py @@ -108,51 +108,6 @@ class isImageEmpty: return (is_empty,) # Return a tuple as required by ComfyUI - -import random - -class GetRandomDimensions: - def __init__(self): - self.is_changed_enabled = True - - @classmethod - def INPUT_TYPES(s): - return { - "required": { - "min_width": ("INT", {"default": 768, "step": 16, "display": "number"}), - "min_height": ("INT", {"default": 768, "step": 16, "display": "number"}), - "max_width": ("INT", {"default": 1280, "step": 16, "display": "number"}), - "max_height": ("INT", {"default": 1280, "step": 16, "display": "number"}), - "randomize": ("BOOLEAN", {"default": False}), - } - } - - RETURN_TYPES = ("INT", "INT") - RETURN_NAMES = ("width", "height",) - FUNCTION = "execute" - CATEGORY = "image" - OUTPUT_NODE = True - - def execute(self, min_width, min_height, max_width, max_height, randomize ): - def get_random_dimensions(min_val, max_val): - min_div_16 = min_val // 16 - max_div_16 = max_val // 16 - if min_div_16 > max_div_16: - raise ValueError("No numbers in the specified range are divisible by 16.") - return random.randint(min_div_16, max_div_16) * 16 - - if randomize: - width = get_random_dimensions(min_width, max_width) - height = get_random_dimensions(min_height, max_height) - else: - width, height = max_width, max_height - - # Setting the resolution string - text = f"{width}x{height}" - #return width, height - return {"ui": {"text": text}, - "result": (width, height, text)} - # wildcard trick is taken from pythongossss's class AnyType(str): def __ne__(self, __value: object) -> bool: diff --git a/web/js/getRandomDimensions.js b/web/js/getRandomDimensions.js index 0e3cc01..7c7d290 100644 --- a/web/js/getRandomDimensions.js +++ b/web/js/getRandomDimensions.js @@ -53,30 +53,31 @@ function addNewColors() { // Function to enhance nodes with text display -function addTextDisplay(nodeType) { - const onNodeCreated = nodeType.prototype.onNodeCreated; - nodeType.prototype.onNodeCreated = function () { - const r = onNodeCreated?.apply(this, arguments); - const w = ComfyWidgets["STRING"](this, "display", ["STRING", { multiline: true, placeholder: " " }], app).widget; - w.inputEl.readOnly = true; - w.inputEl.style.opacity = 0.7; - w.inputEl.style.cursor = "auto"; - return r; - }; +//IMPORTANT: This function is disabled because it is somehow breaking Note nodes. Needs further investigation. +// function addTextDisplay(nodeType) { +// const onNodeCreated = nodeType.prototype.onNodeCreated; +// nodeType.prototype.onNodeCreated = function () { +// const r = onNodeCreated?.apply(this, arguments); +// const w = ComfyWidgets["STRING"](this, "display", ["STRING", { multiline: true, placeholder: " " }], app).widget; +// w.inputEl.readOnly = true; +// w.inputEl.style.opacity = 0.7; +// w.inputEl.style.cursor = "auto"; +// return r; +// }; - const onExecuted = nodeType.prototype.onExecuted; - nodeType.prototype.onExecuted = function (message) { - onExecuted?.apply(this, arguments); +// const onExecuted = nodeType.prototype.onExecuted; +// nodeType.prototype.onExecuted = function (message) { +// onExecuted?.apply(this, arguments); - for (const widget of this.widgets) { - if (widget.type === "customtext" && widget.name === "display" && widget.inputEl.readOnly === true) { - widget.value = message.text.join(''); - } - } +// for (const widget of this.widgets) { +// if (widget.type === "customtext" && widget.name === "display" && widget.inputEl.readOnly === true) { +// widget.value = message.text.join(''); +// } +// } - this.onResize?.(this.size); - }; -} +// this.onResize?.(this.size); +// }; +// } app.registerExtension({ name: "rka.GetRandomDimensions", @@ -97,10 +98,10 @@ app.registerExtension({ }); // Call the function to add new colors //addNewColors(); - }, + }/*, async beforeRegisterNodeDef(nodeType, nodeData, app) { if (["GetRandomDimensions"].includes(nodeData.name)) { addTextDisplay(nodeType); } - }, + },*/ });