From 51bc089334ecf6c58af7161a4a6d16575e91b76d Mon Sep 17 00:00:00 2001 From: rgthree Date: Sun, 22 Jun 2025 22:49:44 -0400 Subject: [PATCH] Switch Power Puter and Power Primitive to use BOOLEAN, not BOOL. Fixes #520 --- README.md | 4 ++-- py/power_primitive.py | 5 +++++ py/power_puter.py | 5 ++++- pyproject.toml | 2 +- src_web/comfyui/power_primitive.ts | 8 ++++++-- src_web/comfyui/power_puter.ts | 24 +++++++++++++++++------- src_web/comfyui/tests/power_puter.ts | 6 +++--- web/comfyui/power_primitive.js | 7 +++++-- web/comfyui/power_puter.js | 13 +++++-------- 9 files changed, 48 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 40e2fc6..d23987d 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ Note, you can right-click on a bunch of the rgthree-comfy nodes and select `🛟 ## Power Primitive -> A single node that can output primitives (STRING, INT, FLOAT, BOOL). If connecting an input, it will cast/convert the primitive input to the desired output. +> A single node that can output primitives (STRING, INT, FLOAT, BOOLEAN). If connecting an input, it will cast/convert the primitive input to the desired output. >
> â„šī¸ More Information > @@ -192,7 +192,7 @@ Note, you can right-click on a bunch of the rgthree-comfy nodes and select `🛟 >
> â„šī¸ More Information > -> - Evaluate almost any kind of input and more, and choose your output from INT, FLOAT, STRING, or BOOL. +> - Evaluate almost any kind of input and more, and choose your output from INT, FLOAT, STRING, or BOOLEAN. > - Connect some nodes and do simply math operations like `a + b` or `ceil(1 / 2)`. > - Or do more advanced things, like input an image, and get the width like `a.shape[2]`. > - Even more powerful, you can target nodes in the prompt that's sent to the backend. For instance; if you have a Power Lora Loader node at id #5, and want to get a comma-delimited list of the enabled loras, you could enter: diff --git a/py/power_primitive.py b/py/power_primitive.py index 09f7b4d..c8deea1 100644 --- a/py/power_primitive.py +++ b/py/power_primitive.py @@ -43,6 +43,11 @@ output_to_type = { 'cast': lambda x: int(cast_to_float(x)), 'null': 0, }, + 'BOOLEAN': { + 'cast': cast_to_bool, + 'null': False, + }, + # This can be removed soon, there was a bug where this should have been BOOLEAN 'BOOL': { 'cast': cast_to_bool, 'null': False, diff --git a/py/power_puter.py b/py/power_puter.py index c47fa37..e494dd2 100644 --- a/py/power_puter.py +++ b/py/power_puter.py @@ -230,7 +230,10 @@ class RgthreePowerPuter: value = int(value) elif output == 'FLOAT': value = float(value) - elif output == 'BOOL': + # Accidentally defined "BOOL" when should have been "BOOLEAN." + # TODO: Can prob get rid of BOOl after a bit when UIs would be updated from sending + # BOOL incorrectly. + elif output in ('BOOL', 'BOOLEAN'): value = bool(value) elif output == 'STRING': if isinstance(value, (dict, list)): diff --git a/pyproject.toml b/pyproject.toml index 5c229af..4434d06 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "rgthree-comfy" description = "Making ComfyUI more comfortable." -version = "1.0.2506222201" +version = "1.0.2506222249" license = { file = "LICENSE" } dependencies = [] diff --git a/src_web/comfyui/power_primitive.ts b/src_web/comfyui/power_primitive.ts index c3f0ef6..f4d7dd3 100644 --- a/src_web/comfyui/power_primitive.ts +++ b/src_web/comfyui/power_primitive.ts @@ -24,7 +24,7 @@ const PRIMITIVES = { // "STRING (multiline)": "STRING", INT: "INT", FLOAT: "FLOAT", - BOOL: "BOOL", + BOOLEAN: "BOOLEAN", }; class RgthreePowerPrimitive extends RgthreeBaseServerNode { @@ -65,6 +65,10 @@ class RgthreePowerPrimitive extends RgthreeBaseServerNode { */ override configure(info: ISerialisedNode): void { super.configure(info); + // Update BOOL to BOOLEAN due to a bug using BOOL instead of BOOLEAN. + if (this.outputTypeWidget.value === 'BOOL') { + this.outputTypeWidget.value = 'BOOLEAN'; + } setTimeout(() => { this.setTypedData(); }); @@ -157,7 +161,7 @@ class RgthreePowerPrimitive extends RgthreeBaseServerNode { value = Number(value); value = value == null || isNaN(value) ? 0 : value; newWidget.value = value; - } else if (type === "BOOL") { + } else if (type === "BOOLEAN") { newWidget = this.addWidget("toggle", name, !!(value ?? true), undefined, { on: "true", off: "false", diff --git a/src_web/comfyui/power_puter.ts b/src_web/comfyui/power_puter.ts index 83c6af4..8b2df61 100644 --- a/src_web/comfyui/power_puter.ts +++ b/src_web/comfyui/power_puter.ts @@ -7,6 +7,7 @@ import type { } from "@comfyorg/litegraph"; import type {ComfyNodeDef} from "typings/comfy.js"; import type {CanvasMouseEvent} from "@comfyorg/litegraph/dist/types/events.js"; +import type {ISerialisedNode} from "@comfyorg/litegraph/dist/types/serialisation.js"; import {app} from "scripts/app.js"; import {RgthreeBaseServerNode} from "./base_node.js"; @@ -26,7 +27,7 @@ import {rgthree} from "./rgthree.js"; const ALPHABET = "abcdefghijklmnopqrstuv".split(""); -const OUTPUT_TYPES = ["STRING", "INT", "FLOAT", "BOOL", "*"]; +const OUTPUT_TYPES = ["STRING", "INT", "FLOAT", "BOOLEAN", "*"]; class RgthreePowerPuter extends RgthreeBaseServerNode { static override title = NodeTypesString.POWER_PUTER; @@ -44,6 +45,16 @@ class RgthreePowerPuter extends RgthreeBaseServerNode { this.addInitialWidgets(); } + // /** + // * We need to patch in the configure to fix a bug where Power Puter was using BOOL instead of + // * BOOLEAN. + // */ + // override configure(info: ISerialisedNode): void { + // super.configure(info); + // // Update BOOL to BOOLEAN due to a bug using BOOL instead of BOOLEAN. + // this.outputTypeWidget + // } + static override setUp(comfyClass: LGraphNodeConstructor, nodeData: ComfyNodeDef) { RgthreeBaseServerNode.registerForOverride(comfyClass, nodeData, NODE_CLASS); } @@ -112,7 +123,7 @@ class RgthreePowerPuter extends RgthreeBaseServerNode {
  • Evaluate almost any kind of input and more, and choose your output from INT, FLOAT, - STRING, or BOOL. + STRING, or BOOLEAN.

  • Connect some nodes and do simply math operations like a + b or @@ -196,11 +207,10 @@ class OutputsWidget extends RgthreeBaseWidget { set value(v: OutputsWidgetValue) { // Handle a string being passed in, as the original Power Puter output widget was a string. - if (typeof v === "string") { - this._value.outputs = [v]; - } else { - this._value.outputs = [...v.outputs]; - } + let outputs = typeof v === "string" ? [v] : [...v.outputs]; + // Handle a case where the initial version used "BOOL" instead of "BOOLEAN" incorrectly. + outputs = outputs.map(o => o === 'BOOL' ? 'BOOLEAN' : o) + this._value.outputs = outputs; } get value(): OutputsWidgetValue { diff --git a/src_web/comfyui/tests/power_puter.ts b/src_web/comfyui/tests/power_puter.ts index 6caa6cb..dc81505 100644 --- a/src_web/comfyui/tests/power_puter.ts +++ b/src_web/comfyui/tests/power_puter.ts @@ -35,9 +35,9 @@ describe("TestPowerPuter", async () => { // FLOAT ["1", "1.0", "FLOAT"], ["1.3 + 2.8", "4.1", "FLOAT"], - // BOOL - ["1", "True", "BOOL"], - ["1 - 1", "False", "BOOL"], + // BOOLEAN + ["1", "True", "BOOLEAN"], + ["1 - 1", "False", "BOOLEAN"], ]; for (const data of checks) { setPowerPuterValue(powerPuter, data[0], data[2]); diff --git a/web/comfyui/power_primitive.js b/web/comfyui/power_primitive.js index f0aa4b5..eb55e8e 100644 --- a/web/comfyui/power_primitive.js +++ b/web/comfyui/power_primitive.js @@ -8,7 +8,7 @@ const PRIMITIVES = { STRING: "STRING", INT: "INT", FLOAT: "FLOAT", - BOOL: "BOOL", + BOOLEAN: "BOOLEAN", }; class RgthreePowerPrimitive extends RgthreeBaseServerNode { constructor(title = NODE_CLASS.title) { @@ -26,6 +26,9 @@ class RgthreePowerPrimitive extends RgthreeBaseServerNode { } configure(info) { super.configure(info); + if (this.outputTypeWidget.value === 'BOOL') { + this.outputTypeWidget.value = 'BOOLEAN'; + } setTimeout(() => { this.setTypedData(); }); @@ -95,7 +98,7 @@ class RgthreePowerPrimitive extends RgthreeBaseServerNode { value = value == null || isNaN(value) ? 0 : value; newWidget.value = value; } - else if (type === "BOOL") { + else if (type === "BOOLEAN") { newWidget = this.addWidget("toggle", name, !!(value !== null && value !== void 0 ? value : true), undefined, { on: "true", off: "false", diff --git a/web/comfyui/power_puter.js b/web/comfyui/power_puter.js index b3fd556..2412733 100644 --- a/web/comfyui/power_puter.js +++ b/web/comfyui/power_puter.js @@ -8,7 +8,7 @@ import { RgthreeBaseWidget } from "./utils_widgets.js"; import { drawPlusIcon, drawRoundedRectangle, drawWidgetButton, isLowQuality, measureText, } from "./utils_canvas.js"; import { rgthree } from "./rgthree.js"; const ALPHABET = "abcdefghijklmnopqrstuv".split(""); -const OUTPUT_TYPES = ["STRING", "INT", "FLOAT", "BOOL", "*"]; +const OUTPUT_TYPES = ["STRING", "INT", "FLOAT", "BOOLEAN", "*"]; class RgthreePowerPuter extends RgthreeBaseServerNode { constructor(title = NODE_CLASS.title) { super(title); @@ -72,7 +72,7 @@ class RgthreePowerPuter extends RgthreeBaseServerNode {

    • Evaluate almost any kind of input and more, and choose your output from INT, FLOAT, - STRING, or BOOL. + STRING, or BOOLEAN.

    • Connect some nodes and do simply math operations like a + b or @@ -127,12 +127,9 @@ class OutputsWidget extends RgthreeBaseWidget { this.node = node; } set value(v) { - if (typeof v === "string") { - this._value.outputs = [v]; - } - else { - this._value.outputs = [...v.outputs]; - } + let outputs = typeof v === "string" ? [v] : [...v.outputs]; + outputs = outputs.map(o => o === 'BOOL' ? 'BOOLEAN' : o); + this._value.outputs = outputs; } get value() { return this._value;