feat: double-click options

This commit is contained in:
Dr.Lt.Data 2024-01-28 13:47:39 +09:00
parent 05519864b7
commit b5cde5936f
3 changed files with 144 additions and 25 deletions

View File

@ -29,7 +29,7 @@ except:
print(f"[WARN] ComfyUI-Manager: Your ComfyUI version is outdated. Please update to the latest version.") print(f"[WARN] ComfyUI-Manager: Your ComfyUI version is outdated. Please update to the latest version.")
version = [2, 4, 2] version = [2, 5]
version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '') version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '')
print(f"### Loading: ComfyUI-Manager ({version_str})") print(f"### Loading: ComfyUI-Manager ({version_str})")
@ -175,7 +175,8 @@ def write_config():
'bypass_ssl': get_config()['bypass_ssl'], 'bypass_ssl': get_config()['bypass_ssl'],
'default_ui': get_config()['default_ui'], 'default_ui': get_config()['default_ui'],
'component_policy': get_config()['component_policy'], 'component_policy': get_config()['component_policy'],
"windows_selector_event_loop_policy": get_config()['windows_selector_event_loop_policy'], 'double_click_policy': get_config()['double_click_policy'],
'windows_selector_event_loop_policy': get_config()['windows_selector_event_loop_policy'],
} }
with open(config_path, 'w') as configfile: with open(config_path, 'w') as configfile:
config.write(configfile) config.write(configfile)
@ -196,6 +197,7 @@ def read_config():
'bypass_ssl': default_conf['bypass_ssl'] if 'bypass_ssl' in default_conf else False, 'bypass_ssl': default_conf['bypass_ssl'] if 'bypass_ssl' in default_conf else False,
'default_ui': default_conf['default_ui'] if 'default_ui' in default_conf else 'none', 'default_ui': default_conf['default_ui'] if 'default_ui' in default_conf else 'none',
'component_policy': default_conf['component_policy'] if 'component_policy' in default_conf else 'workflow', 'component_policy': default_conf['component_policy'] if 'component_policy' in default_conf else 'workflow',
'double_click_policy': default_conf['double_click_policy'] if 'double_click_policy' in default_conf else 'copy-all',
"windows_selector_event_loop_policy": default_conf['windows_selector_event_loop_policy'] if 'windows_selector_event_loop_policy' in default_conf else False, "windows_selector_event_loop_policy": default_conf['windows_selector_event_loop_policy'] if 'windows_selector_event_loop_policy' in default_conf else False,
} }
@ -209,7 +211,8 @@ def read_config():
'bypass_ssl': False, 'bypass_ssl': False,
'default_ui': 'none', 'default_ui': 'none',
'component_policy': 'workflow', 'component_policy': 'workflow',
"windows_selector_event_loop_policy": False 'double_click_policy': 'copy-all',
'windows_selector_event_loop_policy': False
} }
@ -261,6 +264,10 @@ def set_component_policy(mode):
get_config()['component_policy'] = mode get_config()['component_policy'] = mode
def set_double_click_policy(mode):
get_config()['double_click_policy'] = mode
def try_install_script(url, repo_path, install_cmd): def try_install_script(url, repo_path, install_cmd):
if platform.system() == "Windows" and comfy_ui_commit_datetime.date() >= comfy_ui_required_commit_datetime.date(): if platform.system() == "Windows" and comfy_ui_commit_datetime.date() >= comfy_ui_required_commit_datetime.date():
if not os.path.exists(startup_script_path): if not os.path.exists(startup_script_path):
@ -1786,6 +1793,17 @@ async def component_policy(request):
return web.Response(status=200) return web.Response(status=200)
@server.PromptServer.instance.routes.get("/manager/dbl_click/policy")
async def dbl_click_policy(request):
if "value" in request.rel_url.query:
set_double_click_policy(request.rel_url.query['value'])
write_config()
else:
return web.Response(text=get_config()['double_click_policy'], status=200)
return web.Response(status=200)
@server.PromptServer.instance.routes.get("/manager/channel_url_list") @server.PromptServer.instance.routes.get("/manager/channel_url_list")
async def channel_url_list(request): async def channel_url_list(request):
channels = get_channel_dict() channels = get_channel_dict()

View File

@ -17,12 +17,13 @@ import { SnapshotManager } from "./snapshot.js";
import { ModelInstaller } from "./model-downloader.js"; import { ModelInstaller } from "./model-downloader.js";
import { manager_instance, setManagerInstance, install_via_git_url, install_pip, rebootAPI, free_models } from "./common.js"; import { manager_instance, setManagerInstance, install_via_git_url, install_pip, rebootAPI, free_models } from "./common.js";
import { ComponentBuilderDialog, load_components, set_component_policy, getPureName } from "./components-manager.js"; import { ComponentBuilderDialog, load_components, set_component_policy, getPureName } from "./components-manager.js";
import { set_double_click_policy } from "./node_fixer.js";
var docStyle = document.createElement('style'); var docStyle = document.createElement('style');
docStyle.innerHTML = ` docStyle.innerHTML = `
#cm-manager-dialog { #cm-manager-dialog {
width: 1000px; width: 1000px;
height: 495px; height: 520px;
box-sizing: content-box; box-sizing: content-box;
z-index: 10000; z-index: 10000;
} }
@ -136,7 +137,7 @@ docStyle.innerHTML = `
.cm-notice-board { .cm-notice-board {
width: 290px; width: 290px;
height: 230px; height: 270px;
overflow: auto; overflow: auto;
color: var(--input-text); color: var(--input-text);
border: 1px solid var(--descrip-text); border: 1px solid var(--descrip-text);
@ -906,6 +907,26 @@ class ManagerMenuDialog extends ComfyDialog {
set_component_policy(event.target.value); set_component_policy(event.target.value);
}); });
let dbl_click_policy_combo = document.createElement("select");
dbl_click_policy_combo.setAttribute("title", "When loading the workflow, configure which version of the component to use.");
dbl_click_policy_combo.className = "cm-menu-combo";
dbl_click_policy_combo.appendChild($el('option', { value: 'none', text: 'Double-Click: None' }, []));
dbl_click_policy_combo.appendChild($el('option', { value: 'copy-all', text: 'Double-Click: Copy All Connections' }, []));
dbl_click_policy_combo.appendChild($el('option', { value: 'copy-input', text: 'Double-Click: Copy Input Connections' }, []));
dbl_click_policy_combo.appendChild($el('option', { value: 'possible-input', text: 'Double-Click: Possible Input Connections' }, []));
api.fetchApi('/manager/dbl_click/policy')
.then(response => response.text())
.then(data => {
dbl_click_policy_combo.value = data;
set_double_click_policy(data);
});
dbl_click_policy_combo.addEventListener('change', function (event) {
api.fetchApi(`/manager/dbl_click/policy?value=${event.target.value}`);
set_double_click_policy(event.target.value);
});
api.fetchApi('/manager/share_option') api.fetchApi('/manager/share_option')
.then(response => response.text()) .then(response => response.text())
.then(data => { .then(data => {
@ -935,6 +956,7 @@ class ManagerMenuDialog extends ComfyDialog {
default_ui_combo, default_ui_combo,
share_combo, share_combo,
component_policy_combo, component_policy_combo,
dbl_click_policy_combo,
$el("br", {}, []), $el("br", {}, []),
$el("br", {}, []), $el("br", {}, []),

View File

@ -1,6 +1,16 @@
import { app } from "../../scripts/app.js"; import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js"; import { api } from "../../scripts/api.js";
let double_click_policy = "copy-all";
api.fetchApi('/manager/dbl_click/policy')
.then(response => response.text())
.then(data => set_double_click_policy(data));
export function set_double_click_policy(mode) {
double_click_policy = mode;
}
function addMenuHandler(nodeType, cb) { function addMenuHandler(nodeType, cb) {
const getOpts = nodeType.prototype.getExtraMenuOptions; const getOpts = nodeType.prototype.getExtraMenuOptions;
nodeType.prototype.getExtraMenuOptions = function () { nodeType.prototype.getExtraMenuOptions = function () {
@ -36,7 +46,59 @@ function lookup_nearest_nodes(node) {
return nearest_node; return nearest_node;
} }
function node_info_copy(src, dest) { function lookup_nearest_inputs(node) {
let input_map = {};
for(let i in node.inputs) {
let input = node.inputs[i];
if(input_map[input.type])
continue;
input_map[input.type] = {distance: Infinity, input_name: input.name, node: null, slot: null};
}
let x = node.pos[0] + node.size[0]/2;
let y = node.pos[1] + node.size[1]/2;
for(let other of app.graph._nodes) {
if(other === node || !other.outputs)
continue;
let dist = distance(node, other);
for(let input_type in input_map) {
for(let j in other.outputs) {
let output = other.outputs[j];
if(output.type == input_type) {
if(input_map[input_type].distance > dist) {
input_map[input_type].distance = dist;
input_map[input_type].node = other;
input_map[input_type].slot = parseInt(j);
}
}
}
}
}
let res = {};
for (let i in input_map) {
if (input_map[i].node) {
res[i] = input_map[i];
}
}
return res;
}
function connect_inputs(nearest_inputs, node) {
for(let i in nearest_inputs) {
let info = nearest_inputs[i];
info.node.connect(info.slot, node.id, info.input_name);
}
}
function node_info_copy(src, dest, connect_both) {
// copy input connections // copy input connections
for(let i in src.inputs) { for(let i in src.inputs) {
let input = src.inputs[i]; let input = src.inputs[i];
@ -48,6 +110,7 @@ function node_info_copy(src, dest) {
} }
// copy output connections // copy output connections
if(connect_both) {
let output_links = {}; let output_links = {};
for(let i in src.outputs) { for(let i in src.outputs) {
let output = src.outputs[i]; let output = src.outputs[i];
@ -70,6 +133,7 @@ function node_info_copy(src, dest) {
} }
} }
} }
}
app.graph.afterChange(); app.graph.afterChange();
} }
@ -81,15 +145,30 @@ app.registerExtension({
let orig_dblClick = node.onDblClick; let orig_dblClick = node.onDblClick;
node.onDblClick = () => { node.onDblClick = () => {
orig_dblClick?.apply?.(this, arguments); orig_dblClick?.apply?.(this, arguments);
if(node.inputs?.some(x => x.link != null) || node.outputs?.some(x => x.links != null && x.links.length > 0) ) if(node.inputs?.some(x => x.link != null) || node.outputs?.some(x => x.links != null && x.links.length > 0) )
return; return;
if(!node.inputs && !node.outputs) if(!node.inputs && !node.outputs)
return; return;
switch(double_click_policy) {
case "copy-all":
case "copy-input":
{
let src_node = lookup_nearest_nodes(node); let src_node = lookup_nearest_nodes(node);
if(src_node) if(src_node)
node_info_copy(src_node, node); node_info_copy(src_node, node, double_click_policy == "copy-all");
}
break;
case "possible-input":
{
let nearest_inputs = lookup_nearest_inputs(node);
if(nearest_inputs)
connect_inputs(nearest_inputs, node);
}
break;
}
} }
}, },