Added FindValueFromFile
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
|
||||
import os
|
||||
|
||||
class Text:
|
||||
|
||||
@@ -42,12 +42,61 @@ class String:
|
||||
def string(STRING):
|
||||
return STRING,
|
||||
|
||||
class FindValueFromFile:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
|
||||
return {"required": {
|
||||
"key": ("STRING", {"default": '', "multiline": False}),
|
||||
"input_path": ("STRING", {"default": '', "multiline": False})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING", "BOOLEAN")
|
||||
RETURN_NAMES = ("Value STRING", "Value received BOOL")
|
||||
|
||||
FUNCTION = "find_value_from_file"
|
||||
CATEGORY = "LevelPixel/IO"
|
||||
|
||||
def find_value_from_file(self, key, input_path=None):
|
||||
valueString = ""
|
||||
boolResult = True
|
||||
log = []
|
||||
log.append("")
|
||||
try:
|
||||
with open(os.path.normpath(input_path), 'r', encoding='utf-8') as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
|
||||
if "-->" in line:
|
||||
keyLine, valueLine = line.split("-->", 1)
|
||||
if keyLine.strip() == key:
|
||||
valueString = valueLine.strip()
|
||||
break
|
||||
except FileNotFoundError:
|
||||
log[0] = log[0] + f"Error: File not found at {input_path}"
|
||||
boolResult = False
|
||||
except Exception as e:
|
||||
log[0] = log[0] + f"Error: {e}"
|
||||
boolResult = False
|
||||
|
||||
if valueString == "":
|
||||
boolResult = False
|
||||
|
||||
return {"ui": {"text": valueString, "log": log,}, "result": (valueString, boolResult,)}
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"Text|LP": Text,
|
||||
"String|LP": String,
|
||||
"FindValueFromFile|LP": FindValueFromFile,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"Text|LP": "Text [LP]",
|
||||
"String|LP": "String [LP]",
|
||||
"FindValueFromFile|LP": "Find Value From File [LP]",
|
||||
}
|
||||
@@ -205,3 +205,37 @@ app.registerExtension({
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
app.registerExtension({
|
||||
name: "levelpixel.FindValueFromFile",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
levelpixel.addStatusTagHandler(nodeType);
|
||||
|
||||
if (nodeData.name === "FindValueFromFile|LP") {
|
||||
const onExecuted = nodeType.prototype.onExecuted;
|
||||
nodeType.prototype.onExecuted = function (message) {
|
||||
const r = onExecuted?.apply?.(this, arguments);
|
||||
|
||||
const pos = this.widgets.findIndex((w) => w.name === "log");
|
||||
if (pos !== -1) {
|
||||
for (let i = pos; i < this.widgets.length; i++) {
|
||||
this.widgets[i].onRemove?.();
|
||||
}
|
||||
this.widgets.length = pos;
|
||||
}
|
||||
|
||||
for (const list of message.log) {
|
||||
const w = ComfyWidgets["STRING"](this, "log", ["STRING", { multiline: true }], app).widget;
|
||||
w.inputEl.readOnly = true;
|
||||
w.inputEl.style.opacity = 0.6;
|
||||
w.value = list;
|
||||
}
|
||||
|
||||
this.onResize?.(this.size);
|
||||
|
||||
return r;
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user