Skip to content

Commit

Permalink
Merge pull request #13 from nickve28/change/remove-selected-image
Browse files Browse the repository at this point in the history
Change/remove selected image
  • Loading branch information
nickve28 authored Aug 24, 2024
2 parents 3b58ec5 + 41f5a85 commit 2c8e327
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 28 deletions.
4 changes: 1 addition & 3 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from .nodes import NODE_CLASS_MAPPINGS

WEB_DIRECTORY = "./javascript"

__all__ = ["NODE_CLASS_MAPPINGS", "WEB_DIRECTORY"]
__all__ = ["NODE_CLASS_MAPPINGS"]

11 changes: 0 additions & 11 deletions javascript/nich_nodes.js

This file was deleted.

19 changes: 5 additions & 14 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import time
import uuid
from server import PromptServer
import os
import re
import random
Expand Down Expand Up @@ -52,22 +51,20 @@ def INPUT_TYPES(cls):
"required": {
"directory": ("STRING", { "default": "~/images" }),
"keep_current_selection": ("BOOLEAN", { "default": False }),
"selected_image_name": ("STRING", { "multiline": True }),
"include_subdirectories": ("BOOLEAN", { "default": False }),
},
"optional": {
"regexp_filter": ("STRING", { "default": "", "multiline": True })
},
"hidden": {"unique_id": "UNIQUE_ID"}
}
}

@classmethod
def IS_CHANGED(cls, **kwargs):
return kwargs['selected_image_name'] if kwargs['keep_current_selection'] else str(uuid.uuid1())
return kwargs['regexp_filter'] if kwargs['keep_current_selection'] else str(uuid.uuid1())


def get_current_image(self, selected_image_name):
return selected_image_name if selected_image_name else self.current_image
def get_current_image(self):
return self.current_image


def requires_new_image(self, current_image, keep_current_selection):
Expand All @@ -84,26 +81,20 @@ def get_files(self, full_path, regexp_filter, include_subdirectories):

def sample_images(self, *_args, **kwargs):
directory = kwargs['directory']
selected_image_name = kwargs['selected_image_name']
keep_current_selection = kwargs['keep_current_selection']
regexp_filter = kwargs['regexp_filter']
include_subdirectories = kwargs['include_subdirectories']
unique_id = kwargs['unique_id']

# todo, this image logic is a bit underestimated
# make an ImageSelector class which should be comfy independent and easily testable too
full_path = os.path.expanduser(directory)
prior_selected_image = self.get_current_image(selected_image_name)
prior_selected_image = self.get_current_image()
new_image = prior_selected_image
new_image_required = self.requires_new_image(prior_selected_image, keep_current_selection)
if new_image_required:
image_files = self.get_files(full_path, regexp_filter, include_subdirectories)
self.current_image = self.random_number_generator.choice(image_files)
new_image = self.current_image
elif self.current_image is None:
self.current_image = selected_image_name

PromptServer.instance.send_sync("nich-image-selected", {"node_id": unique_id, "value": new_image})

if new_image_required or self.current_tensor is None:
image = Image.open(os.path.join(full_path, new_image))
Expand Down

0 comments on commit 2c8e327

Please sign in to comment.