chrisgoringe / cg-image-picker

227 stars 15 forks source link

Warning when nodes aren't paired nicely #29

Closed chrisgoringe closed 11 months ago

chrisgoringe commented 11 months ago

Chooser nodes should always be directly downstream of a preview and fully connected: that way they can be closely integrated.

Should warn if this isn't the case (maybe even refuse to run?)

chrisgoringe commented 11 months ago

Make inputs required on choosers?

Could make the outputs of 'preview' custom types which will only connect to the inputs of the chooser.

Erehr commented 11 months ago

Is there a reason for not making it a single node? And maybe another just for Fabric? Something like image And showing 'Go' / 'Cancel' / 'Restart from here' buttons based on state.

chrisgoringe commented 11 months ago

Yes, there is a reason for having two nodes... The images are only available at the end of the node execution - they are part of the output.

So you can't see the images and then determine the output of the same node. Hence the need to have two linked nodes...

chrisgoringe commented 11 months ago

Hmmm. Maybe....

if I added a custom event listener to the api:

import { api } from "../../scripts/api.js";

function earlyImageHandler(event) {
    try {
        let nodes = app.graph._nodes_by_id;
        let node = nodes[event.detail.node_id];

        if(!node) {
            console.log(`invalid node id '${event.detail.node_id}'`);
            return;
        }

        // do something with event.details.urls

    }
    catch(e) {
        console.log(`exception occurs\n${e}`);
    }
}

api.addEventListener("early-image-handler", earlyImageHandler);

then I think

PromptServer.instance.send_sync("early-image-handler", {"node_id": unique_id, "urls":[preview1, preview2, ...]})
//now wait

could send the images in mid-execution...

chrisgoringe commented 11 months ago

Done in new branch