Browse Source

Merge branch 'mute-nodes' of https://github.com/jn-jairo/ComfyUI

pull/318/head
comfyanonymous 2 years ago
parent
commit
2b60c308be
  1. 7
      README.md
  2. 91
      web/scripts/app.js

7
README.md

@ -30,6 +30,13 @@ This ui will let you design and execute advanced stable diffusion pipelines usin
Workflow examples can be found on the [Examples page](https://comfyanonymous.github.io/ComfyUI_examples/) Workflow examples can be found on the [Examples page](https://comfyanonymous.github.io/ComfyUI_examples/)
## Shortcuts
- **Ctrl + C** copy selected nodes
- **Ctrl + V** paste copied nodes
- **Ctrl + A** select all nodes
- **Ctrl + M** mute/unmute selected nodes
- **Delete** or **Backspace** delete selected nodes
# Installing # Installing
## Windows ## Windows

91
web/scripts/app.js

@ -417,6 +417,59 @@ class ComfyApp {
}; };
} }
/**
* Handle keypress
*
* Ctrl + M mute/unmute selected nodes
*/
#addProcessKeyHandler() {
const self = this;
const origProcessKey = LGraphCanvas.prototype.processKey;
LGraphCanvas.prototype.processKey = function(e) {
const res = origProcessKey.apply(this, arguments);
if (res === false) {
return res;
}
if (!this.graph) {
return;
}
var block_default = false;
if (e.target.localName == "input") {
return;
}
if (e.type == "keydown") {
// Ctrl + M mute/unmute
if (e.keyCode == 77 && e.ctrlKey) {
if (this.selected_nodes) {
for (var i in this.selected_nodes) {
if (this.selected_nodes[i].mode === 2) { // never
this.selected_nodes[i].mode = 0; // always
} else {
this.selected_nodes[i].mode = 2; // never
}
}
}
block_default = true;
}
}
this.graph.change();
if (block_default) {
e.preventDefault();
e.stopImmediatePropagation();
return false;
}
return res;
};
}
/** /**
* Draws group header bar * Draws group header bar
*/ */
@ -465,10 +518,11 @@ class ComfyApp {
* Draws node highlights (executing, drag drop) and progress bar * Draws node highlights (executing, drag drop) and progress bar
*/ */
#addDrawNodeHandler() { #addDrawNodeHandler() {
const orig = LGraphCanvas.prototype.drawNodeShape; const origDrawNodeShape = LGraphCanvas.prototype.drawNodeShape;
const self = this; const self = this;
LGraphCanvas.prototype.drawNodeShape = function (node, ctx, size, fgcolor, bgcolor, selected, mouse_over) { LGraphCanvas.prototype.drawNodeShape = function (node, ctx, size, fgcolor, bgcolor, selected, mouse_over) {
const res = orig.apply(this, arguments); const res = origDrawNodeShape.apply(this, arguments);
let color = null; let color = null;
if (node.id === +self.runningNodeId) { if (node.id === +self.runningNodeId) {
@ -517,6 +571,21 @@ class ComfyApp {
return res; return res;
}; };
const origDrawNode = LGraphCanvas.prototype.drawNode;
LGraphCanvas.prototype.drawNode = function (node, ctx) {
var editor_alpha = this.editor_alpha;
if (node.mode === 2) { // never
this.editor_alpha = 0.4;
}
const res = origDrawNode.apply(this, arguments);
this.editor_alpha = editor_alpha;
return res;
};
} }
/** /**
@ -588,6 +657,7 @@ class ComfyApp {
document.body.prepend(canvasEl); document.body.prepend(canvasEl);
this.#addProcessMouseHandler(); this.#addProcessMouseHandler();
this.#addProcessKeyHandler();
this.graph = new LGraph(); this.graph = new LGraph();
const canvas = (this.canvas = new LGraphCanvas(canvasEl, this.graph)); const canvas = (this.canvas = new LGraphCanvas(canvasEl, this.graph));
@ -777,6 +847,11 @@ class ComfyApp {
continue; continue;
} }
if (node.mode === 2) {
// Don't serialize muted nodes
continue;
}
const inputs = {}; const inputs = {};
const widgets = node.widgets; const widgets = node.widgets;
@ -816,6 +891,18 @@ class ComfyApp {
}; };
} }
// Remove inputs connected to removed nodes
for (const o in output) {
for (const i in output[o].inputs) {
if (Array.isArray(output[o].inputs[i])
&& output[o].inputs[i].length === 2
&& !output[output[o].inputs[i][0]]) {
delete output[o].inputs[i];
}
}
}
return { workflow, output }; return { workflow, output };
} }

Loading…
Cancel
Save