mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-13 23:12:35 +08:00
janitorial things
This commit is contained in:
parent
583c3d2270
commit
2528135dbe
@ -1,40 +1,16 @@
|
|||||||
import folder_paths
|
class FileSubflow:
|
||||||
|
|
||||||
class LoadSubflow:
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(s):
|
||||||
return {"required": { "subflow_name": (folder_paths.get_filename_list("subflows"), ), }}
|
return {}
|
||||||
RETURN_TYPES = ()
|
RETURN_TYPES = ()
|
||||||
FUNCTION = ""
|
FUNCTION = ""
|
||||||
|
|
||||||
CATEGORY = "loaders"
|
CATEGORY = "loaders"
|
||||||
|
|
||||||
class FileSubflow:
|
|
||||||
@classmethod
|
|
||||||
def INPUT_TYPES(s):
|
|
||||||
return {"required": { "subflow_name": (folder_paths.get_filename_list("subflows"), )} }
|
|
||||||
RETURN_TYPES = ()
|
|
||||||
FUNCTION = ""
|
|
||||||
|
|
||||||
CATEGORY = "utils"
|
|
||||||
|
|
||||||
class InMemorySubflow:
|
|
||||||
@classmethod
|
|
||||||
def INPUT_TYPES(s):
|
|
||||||
return {"required": {} }
|
|
||||||
RETURN_TYPES = ()
|
|
||||||
FUNCTION = ""
|
|
||||||
|
|
||||||
CATEGORY = ""
|
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
"LoadSubflow": LoadSubflow,
|
|
||||||
"FileSubflow": FileSubflow,
|
"FileSubflow": FileSubflow,
|
||||||
"InMemorySubflow": InMemorySubflow
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||||
"Subflow": "Load Subflow",
|
"FileSubflow": "Load Subflow",
|
||||||
"FileSubflow": "File Subflow",
|
|
||||||
"InMemorySubflow": "In Memory Subflow"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import os
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
supported_pt_extensions = set(['.ckpt', '.pt', '.bin', '.pth', '.safetensors'])
|
supported_pt_extensions = set(['.ckpt', '.pt', '.bin', '.pth', '.safetensors'])
|
||||||
supported_subflow_extensions = set(['.json', '.png'])
|
|
||||||
|
|
||||||
folder_names_and_paths = {}
|
folder_names_and_paths = {}
|
||||||
|
|
||||||
@ -30,22 +29,17 @@ folder_names_and_paths["custom_nodes"] = ([os.path.join(base_path, "custom_nodes
|
|||||||
|
|
||||||
folder_names_and_paths["hypernetworks"] = ([os.path.join(models_dir, "hypernetworks")], supported_pt_extensions)
|
folder_names_and_paths["hypernetworks"] = ([os.path.join(models_dir, "hypernetworks")], supported_pt_extensions)
|
||||||
|
|
||||||
folder_names_and_paths["subflows"] = ([os.path.join(base_path, "subflows")], supported_subflow_extensions)
|
|
||||||
folder_names_and_paths["classifiers"] = ([os.path.join(models_dir, "classifiers")], {""})
|
folder_names_and_paths["classifiers"] = ([os.path.join(models_dir, "classifiers")], {""})
|
||||||
|
|
||||||
output_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "output")
|
output_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "output")
|
||||||
temp_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "temp")
|
temp_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "temp")
|
||||||
input_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input")
|
input_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input")
|
||||||
subflows_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "subflows")
|
|
||||||
|
|
||||||
filename_list_cache = {}
|
filename_list_cache = {}
|
||||||
|
|
||||||
if not os.path.exists(input_directory):
|
if not os.path.exists(input_directory):
|
||||||
os.makedirs(input_directory)
|
os.makedirs(input_directory)
|
||||||
|
|
||||||
if not os.path.exists(subflows_directory):
|
|
||||||
os.makedirs(subflows_directory)
|
|
||||||
|
|
||||||
def set_output_directory(output_dir):
|
def set_output_directory(output_dir):
|
||||||
global output_directory
|
global output_directory
|
||||||
output_directory = output_dir
|
output_directory = output_dir
|
||||||
@ -70,10 +64,6 @@ def get_input_directory():
|
|||||||
global input_directory
|
global input_directory
|
||||||
return input_directory
|
return input_directory
|
||||||
|
|
||||||
def get_subflows_directory():
|
|
||||||
global subflows_directory
|
|
||||||
return subflows_directory
|
|
||||||
|
|
||||||
#NOTE: used in http server so don't put folders that should not be accessed remotely
|
#NOTE: used in http server so don't put folders that should not be accessed remotely
|
||||||
def get_directory_by_type(type_name):
|
def get_directory_by_type(type_name):
|
||||||
if type_name == "output":
|
if type_name == "output":
|
||||||
@ -82,8 +72,6 @@ def get_directory_by_type(type_name):
|
|||||||
return get_temp_directory()
|
return get_temp_directory()
|
||||||
if type_name == "input":
|
if type_name == "input":
|
||||||
return get_input_directory()
|
return get_input_directory()
|
||||||
if type_name == "subflows":
|
|
||||||
return get_subflows_directory()
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@ -99,9 +87,6 @@ def annotated_filepath(name):
|
|||||||
elif name.endswith("[temp]"):
|
elif name.endswith("[temp]"):
|
||||||
base_dir = get_temp_directory()
|
base_dir = get_temp_directory()
|
||||||
name = name[:-7]
|
name = name[:-7]
|
||||||
elif name.endswith("[subflows]"):
|
|
||||||
base_dir = get_subflows_directory()
|
|
||||||
name = name[:-11]
|
|
||||||
else:
|
else:
|
||||||
return name, None
|
return name, None
|
||||||
|
|
||||||
|
|||||||
@ -120,8 +120,6 @@ app.registerExtension({
|
|||||||
if (nodeData.name == "FileSubflow") {
|
if (nodeData.name == "FileSubflow") {
|
||||||
nodeType.prototype.onConfigure = function() { refreshWidgets(this, this.subflow, true); };
|
nodeType.prototype.onConfigure = function() { refreshWidgets(this, this.subflow, true); };
|
||||||
nodeType.prototype.refreshNode = function(subflow, filename) { refreshNode(this, subflow, filename); };
|
nodeType.prototype.refreshNode = function(subflow, filename) { refreshNode(this, subflow, filename); };
|
||||||
nodeType.prototype.getExportedOutput = function(slot) { return this.subflow.extras.outputSlots[slot]; }
|
|
||||||
nodeType.prototype.getExportedInput = function(slot) { return this.subflow.extras.inputSlots[slot]; }
|
|
||||||
|
|
||||||
nodeData.input.required = { subflow: ["SUBFLOWUPLOAD"] };
|
nodeData.input.required = { subflow: ["SUBFLOWUPLOAD"] };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12953,7 +12953,6 @@ LGraphNode.prototype.executeAction = function(action)
|
|||||||
};
|
};
|
||||||
|
|
||||||
LGraphCanvas.onMenuNodeExport = function(value, options, e, menu, node) {
|
LGraphCanvas.onMenuNodeExport = function(value, options, e, menu, node) {
|
||||||
console.log(node);
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
throw "no node passed";
|
throw "no node passed";
|
||||||
}
|
}
|
||||||
@ -13057,63 +13056,6 @@ LGraphNode.prototype.executeAction = function(action)
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// LGraphCanvas.onDecoupleSubflow = function(value, options, e, menu, node) {
|
|
||||||
// const { subflow } = node;
|
|
||||||
// if (!subflow) return;
|
|
||||||
|
|
||||||
// const subgraph = new LGraph( subflow );
|
|
||||||
|
|
||||||
// for (const node of subgraph._nodes) {
|
|
||||||
// console.log(node);
|
|
||||||
// graph.add(node);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
LGraphCanvas.onCollapseToSubflow = function(value, options, e, menu, node) {
|
|
||||||
const calculatePosition = (nodes) => {
|
|
||||||
const sum = [0, 0];
|
|
||||||
const N = nodes.length;
|
|
||||||
for (const node of nodes) {
|
|
||||||
sum[0] += node.pos[0];
|
|
||||||
sum[1] += node.pos[1];
|
|
||||||
}
|
|
||||||
return [Math.round(sum[0])/N, Math.round(sum[1]/N)];
|
|
||||||
};
|
|
||||||
|
|
||||||
var graphcanvas = LGraphCanvas.active_canvas;
|
|
||||||
if (graphcanvas.selected_nodes && Object.keys(graphcanvas.selected_nodes).length > 1){
|
|
||||||
const nodes = Object.values(graphcanvas.selected_nodes);
|
|
||||||
|
|
||||||
|
|
||||||
// New subflow is the current graph - non included nodes
|
|
||||||
const subgraph = new LGraph(graph.serialize());
|
|
||||||
const subgraphNodes = subgraph._nodes.map(n => n.id);
|
|
||||||
const nodesToKeep = nodes.map(n => n.id);
|
|
||||||
|
|
||||||
for (const n of subgraphNodes) {
|
|
||||||
if(!nodesToKeep.includes(n)) {
|
|
||||||
subgraph.remove(subgraph.getNodeById(n));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const subflow = subgraph.serialize();
|
|
||||||
const subflowNode = LiteGraph.createNode("InMemorySubflow");
|
|
||||||
subflowNode.updateSubflowPrompt(subflow);
|
|
||||||
subflowNode.pos = calculatePosition(subflow.nodes);
|
|
||||||
subflowNode.size[0] = 180;
|
|
||||||
subflowNode.refreshNode(subflow);
|
|
||||||
graph.add(subflowNode);
|
|
||||||
|
|
||||||
// remove selected nodes
|
|
||||||
for (const node of nodes) {
|
|
||||||
graph.remove(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(graph._nodes);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
LGraphCanvas.onMenuNodeRemove = function(value, options, e, menu, node) {
|
LGraphCanvas.onMenuNodeRemove = function(value, options, e, menu, node) {
|
||||||
if (!node) {
|
if (!node) {
|
||||||
throw "no node passed";
|
throw "no node passed";
|
||||||
@ -13373,19 +13315,8 @@ LGraphNode.prototype.executeAction = function(action)
|
|||||||
has_submenu: true,
|
has_submenu: true,
|
||||||
callback: LGraphCanvas.onNodeAlign,
|
callback: LGraphCanvas.onNodeAlign,
|
||||||
});
|
});
|
||||||
options.push({
|
|
||||||
content: "Collapse to Subflow",
|
|
||||||
callback: LGraphCanvas.onCollapseToSubflow
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (Object.keys(this.selected_nodes).length == 1 && node.subflow) {
|
|
||||||
// options.push({
|
|
||||||
// content: "Decouple Subflow",
|
|
||||||
// callback: LGraphCanvas.onDecoupleSubflow,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
options.push(null, {
|
options.push(null, {
|
||||||
content: "Remove",
|
content: "Remove",
|
||||||
disabled: !(node.removable !== false && !node.block_delete ),
|
disabled: !(node.removable !== false && !node.block_delete ),
|
||||||
|
|||||||
@ -573,7 +573,6 @@ export const ComfyWidgets = {
|
|||||||
uploadWidget = node.addWidget("button", "choose file with subflow", "subflow", () => {
|
uploadWidget = node.addWidget("button", "choose file with subflow", "subflow", () => {
|
||||||
fileInput.click();
|
fileInput.click();
|
||||||
});
|
});
|
||||||
console.log(node.widgets);
|
|
||||||
uploadWidget.serialize = false;
|
uploadWidget.serialize = false;
|
||||||
|
|
||||||
// Add handler to check if an image is being dragged over our node
|
// Add handler to check if an image is being dragged over our node
|
||||||
@ -588,7 +587,6 @@ export const ComfyWidgets = {
|
|||||||
|
|
||||||
// On drop upload files
|
// On drop upload files
|
||||||
node.onDragDrop = function (e) {
|
node.onDragDrop = function (e) {
|
||||||
console.log("onDragDrop called");
|
|
||||||
let handled = false;
|
let handled = false;
|
||||||
for (const file of e.dataTransfer.files) {
|
for (const file of e.dataTransfer.files) {
|
||||||
if (file.type === "image/png" || file.type === "application/json") {
|
if (file.type === "image/png" || file.type === "application/json") {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user