-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsize_selector.py
50 lines (42 loc) · 1.36 KB
/
size_selector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import json
class SizeSelector:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
cls.size_sizes, cls.size_dict = cls.read_sizes()
return {
'required': {
'size_selected': (cls.size_sizes,),
}
}
RETURN_TYPES = ("INT", "INT", "STRING")
RETURN_NAMES = ("width", "height", "name")
FUNCTION = "return_res"
CATEGORY = "klinter"
OUTPUT_NODE = True
@classmethod
def read_sizes(cls):
p = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.join(p, 'sizes.json')
with open(file_path, 'r') as file:
data = json.load(file)
size_sizes = [f"{key} - {value['name']}" for key, value in data['sizes'].items()]
size_dict = {f"{key} - {value['name']}": value for key, value in data['sizes'].items()}
return size_sizes, size_dict
def return_res(self, size_selected):
selected_info = self.size_dict[size_selected]
width = int(selected_info["width"])
height = int(selected_info["height"])
name = selected_info["name"]
return (width, height, name)
# Register the node
NODE_CLASS_MAPPINGS = {
"SizeSelector": SizeSelector
}
NODE_DISPLAY_NAME_MAPPINGS = {
"SizeSelector": "Size Selector - klinter"
}
# Export the class
__all__ = ['SizeSelector']