Switch节点增加flat功能,可以把list里的某个元素取出来单独处理

This commit is contained in:
shadowcz007
2024-01-02 17:44:17 +08:00
parent 25fa3a8f6a
commit df37166d42
3 changed files with 49 additions and 19 deletions
+19 -1
View File
@@ -79,6 +79,16 @@ font_files = get_font_files(r_directory)
# print(font_files)
def flatten_list(nested_list):
flat_list = []
for item in nested_list:
if isinstance(item, list):
flat_list.extend(flatten_list(item))
else:
flat_list.append(item)
return flat_list
class ColorInput:
@classmethod
def INPUT_TYPES(s):
@@ -501,6 +511,7 @@ class SwitchByIndex:
"step": 1,
"display": "number"
}),
"flat": (['off',"on"],),
}
}
@@ -514,13 +525,20 @@ class SwitchByIndex:
INPUT_IS_LIST = True
OUTPUT_IS_LIST = (True,)
def run(self, A,B,index):
def run(self, A,B,index,flat):
flat=flat[0]
C=[]
index=index[0]
for a in A:
C.append(a)
for b in B:
C.append(b)
if flat=='on':
C=flatten_list(C)
if index>-1:
try:
C=[C[index]]
+28 -17
View File
@@ -302,6 +302,8 @@
color: #555;
}
select,
button,
input {
@@ -315,10 +317,10 @@
margin-top: 8px;
}
.pickr .pcr-button {
width: 56px!important;
height: 56px!important;
width: 56px !important;
height: 56px !important;
outline: 1px solid white;
}
</style>
@@ -884,7 +886,13 @@
max: 3,
};
const label = data.title == 'PromptSlide ♾️Mixlab' ? data.inputs.prompt_keyword : data.title
const label = data.title;
if (!options.keywords.includes(data.inputs.prompt_keyword)) {
options.keywords = [data.inputs.prompt_keyword, ...options.keywords]
};
// data.title == 'PromptSlide ♾️Mixlab' ? data.inputs.prompt_keyword : data.title
let silde = createNumSlide(label,
data.inputs.weight,
(v) => {
@@ -977,11 +985,11 @@
if (["Color"].includes(data.class_type)) {
let value = data.inputs.color.hex || '#000000';
let d=document.createElement('div');
d.className='card';
let label=document.createElement('label');
label.innerText=data.title;
let d = document.createElement('div');
d.className = 'card';
let label = document.createElement('label');
label.innerText = data.title;
let color = document.createElement('div');
color.id = `color_input_${data.id}`;
@@ -1116,18 +1124,20 @@
label.setAttribute('data-content', value);
if (keywords && keywords[0]) {
label.innerHTML = ``
// label.innerHTML = ``
// 有备选的关键词
let selectTag = createSelect(Array.from([labelText, ...keywords], k => {
let selectTag = createSelect(Array.from(keywords, (k,i) => {
return {
value: k,
text: k,
selected:i==0
}
}), labelText);
}), keywords[0]);
selectTag.style = `background: none;
color: black; max-width: 300px;
border-bottom: 1px solid #acacac;
border-radius: 0;`
color: black; max-width: 300px;
border-bottom: 1px solid #acacac;
border-radius: 0;`
// selectTag.setAttribute('data-content',labelText);
selectTag.addEventListener('change', e => {
e.preventDefault();
window._appData.data[targetId].inputs.prompt_keyword = selectTag.value;
@@ -1184,11 +1194,12 @@
option.value = options[i].value;
option.text = options[i].text;
selectElement.appendChild(option);
// if(options[i].selected)
}
// 设置默认值
selectElement.value = defaultValue;
console.log(defaultValue,options)
return selectElement
}
@@ -1620,7 +1631,7 @@
api.addEventListener('execution_start', ({ detail }) => {
console.log("execution_start", detail)
try {
ui.status.update(`execution_start_#${detail.node}`);
ui.status.update(`execution_start`);
} catch (error) {
}
+2 -1
View File
@@ -101,7 +101,7 @@ app.registerExtension({
async serializeValue (nodeId, widgetIndex) {
// let data = getLocalData('_mixlab_utils_color')
// let hex = data[node.id] || '#000000'
let hex = widget.value
let hex = widget.value || '#000000'
let [r, g, b, a] = hexToRGBA(hex)
return {
hex,
@@ -159,6 +159,7 @@ app.registerExtension({
el: `#${inputColor.id}`,
theme: 'classic', // or 'monolith', or 'nano'
// closeOnScroll: true,
default:'#000000',
swatches: [
'rgba(244, 67, 54, 1)',
'rgba(233, 30, 99, 0.95)',