Merge pull request #30 from ilian6806/develop
- Import and export options added in quicksettings - New gradio selects handled - Script selections savedpull/38/head
commit
8560a9c9eb
|
|
@ -32,6 +32,7 @@ state.core = (function () {
|
||||||
const SELECTS = {
|
const SELECTS = {
|
||||||
'sampling': 'sampling',
|
'sampling': 'sampling',
|
||||||
'hires_upscaler': 'hr_upscaler',
|
'hires_upscaler': 'hr_upscaler',
|
||||||
|
'script': '#script_list',
|
||||||
};
|
};
|
||||||
|
|
||||||
const MULTI_SELECTS = {
|
const MULTI_SELECTS = {
|
||||||
|
|
@ -104,13 +105,61 @@ state.core = (function () {
|
||||||
handleSettingsPage();
|
handleSettingsPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createHeaderButton(title, text, className, style, action) {
|
||||||
|
|
||||||
|
const button = state.utils.html.create('button', {
|
||||||
|
title: title,
|
||||||
|
innerHTML: text,
|
||||||
|
className: className,
|
||||||
|
}, style);
|
||||||
|
|
||||||
|
if (action) {
|
||||||
|
button.addEventListener('click', action);
|
||||||
|
}
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createHeaderFileInput(title, text, className) {
|
||||||
|
|
||||||
|
let inputId = 'state-import-file-inline';
|
||||||
|
|
||||||
|
let importBtn = createHeaderButton(title,text, className, {
|
||||||
|
display: 'none'
|
||||||
|
}, () => {
|
||||||
|
actions.importState(inputId);
|
||||||
|
});
|
||||||
|
|
||||||
|
let label = state.utils.html.create('label', {}, { cursor: 'pointer' });
|
||||||
|
label.appendChild(state.utils.html.create('input', {
|
||||||
|
type: 'file',
|
||||||
|
id: inputId,
|
||||||
|
accept: 'application/json',
|
||||||
|
}, {
|
||||||
|
display: 'none'
|
||||||
|
}));
|
||||||
|
label.appendChild(document.createTextNode(text));
|
||||||
|
label.addEventListener('change', () => {
|
||||||
|
importBtn.dispatchEvent(new Event('click'));
|
||||||
|
});
|
||||||
|
|
||||||
|
let button = createHeaderButton(title, '', className, {});
|
||||||
|
button.appendChild(label);
|
||||||
|
|
||||||
|
return {
|
||||||
|
hiddenButton: importBtn,
|
||||||
|
button: button
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function loadUI() {
|
function loadUI() {
|
||||||
let resetBtn = document.createElement("button");
|
|
||||||
resetBtn.innerHTML = "*️⃣";
|
|
||||||
resetBtn.addEventListener('click', actions.resetAll);
|
|
||||||
let quickSettings = gradioApp().getElementById("quicksettings");
|
let quickSettings = gradioApp().getElementById("quicksettings");
|
||||||
resetBtn.className = quickSettings.querySelector('button').className;
|
let className = quickSettings.querySelector('button').className;
|
||||||
quickSettings.appendChild(resetBtn);
|
quickSettings.appendChild(createHeaderButton('State: Reset', "*️⃣", className, {}, actions.resetAll));
|
||||||
|
quickSettings.appendChild(createHeaderButton('State: Export',"📤", className, {}, actions.exportState));
|
||||||
|
let fileInput = createHeaderFileInput('State: Import',"📥", className);
|
||||||
|
quickSettings.appendChild(fileInput.hiddenButton);
|
||||||
|
quickSettings.appendChild(fileInput.button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -150,6 +199,16 @@ state.core = (function () {
|
||||||
bindTabClickEvents(); // dirty hack here...
|
bindTabClickEvents(); // dirty hack here...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getElement(id) {
|
||||||
|
for (let i = 0; i < TABS.length; i++) {
|
||||||
|
if (id.startsWith(`${TABS[i]}_#`)) {
|
||||||
|
// handle elements with same ids in different tabs...
|
||||||
|
return gradioApp().querySelector('#tab_' + id.replace(`${TABS[i]}_#`, `${TABS[i]} #`));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gradioApp().getElementById(id);
|
||||||
|
}
|
||||||
|
|
||||||
function handleSavedInput(id) {
|
function handleSavedInput(id) {
|
||||||
|
|
||||||
const elements = gradioApp().querySelectorAll(`#${id} textarea, #${id} input`);
|
const elements = gradioApp().querySelectorAll(`#${id} textarea, #${id} input`);
|
||||||
|
|
@ -201,8 +260,7 @@ state.core = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSavedSelects(id) {
|
function handleSavedSelects(id) {
|
||||||
const select = gradioApp().getElementById(`${id}`);
|
state.utils.handleSelect(getElement(id), id, store);
|
||||||
state.utils.handleSelect(select, id, store);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSavedMultiSelects(id) {
|
function handleSavedMultiSelects(id) {
|
||||||
|
|
@ -297,8 +355,8 @@ state.core = (function () {
|
||||||
exportState: function () {
|
exportState: function () {
|
||||||
state.utils.saveFile('sd-webui-state', store.getAll());
|
state.utils.saveFile('sd-webui-state', store.getAll());
|
||||||
},
|
},
|
||||||
importState: function () {
|
importState: function (id) {
|
||||||
const fileInput = gradioApp().getElementById('state-import-file');
|
const fileInput = gradioApp().getElementById(id || 'state-import-file');
|
||||||
if (! fileInput.files || ! fileInput.files[0]) {
|
if (! fileInput.files || ! fileInput.files[0]) {
|
||||||
alert('Please select a JSON file!');
|
alert('Please select a JSON file!');
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -77,9 +77,15 @@ state.utils = {
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
state.utils.onContentChange(select, function (el) {
|
state.utils.onContentChange(select, function (el) {
|
||||||
const selected = el.querySelector('span.single-select');
|
let selected = el.querySelector('span.single-select');
|
||||||
if (selected) {
|
if (selected) {
|
||||||
store.set(id, selected.textContent);
|
store.set(id, selected.textContent);
|
||||||
|
} else {
|
||||||
|
// new gradio version...
|
||||||
|
let input = select.querySelector('input');
|
||||||
|
if (input) {
|
||||||
|
store.set(id, input.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 150);
|
}, 150);
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ def on_ui_settings():
|
||||||
"hires_resize_x",
|
"hires_resize_x",
|
||||||
"hires_resize_y",
|
"hires_resize_y",
|
||||||
"hires_denoising_strength",
|
"hires_denoising_strength",
|
||||||
|
"script"
|
||||||
]
|
]
|
||||||
}, section=section))
|
}, section=section))
|
||||||
|
|
||||||
|
|
@ -56,7 +57,8 @@ def on_ui_settings():
|
||||||
"batch_size",
|
"batch_size",
|
||||||
"cfg_scale",
|
"cfg_scale",
|
||||||
"denoising_strength",
|
"denoising_strength",
|
||||||
"seed"
|
"seed",
|
||||||
|
"script"
|
||||||
]
|
]
|
||||||
}, section=section))
|
}, section=section))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue