Merge pull request #22 from ilian6806/develop

Added extra networks support
pull/30/head
Ilian Iliev 2023-04-11 13:25:08 +03:00 committed by GitHub
commit 4cc8fa3ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 28 deletions

View File

@ -38,6 +38,10 @@ state.core = (function () {
'styles': 'styles' 'styles': 'styles'
}; };
const TOGGLE_BUTTONS = {
'extra_networks': 'extra_networks',
};
let store = null; let store = null;
function hasSetting(id, tab) { function hasSetting(id, tab) {
@ -59,6 +63,16 @@ state.core = (function () {
.catch(error => console.error('[state]: Error getting JSON file:', error)); .catch(error => console.error('[state]: Error getting JSON file:', error));
} }
function forEachElement(list, config, action) {
for (const [settingId, element] of Object.entries(list)) {
TABS.forEach(tab => {
if (config.hasSetting(settingId, tab)) {
action(element, tab);
}
});
}
}
function load(config) { function load(config) {
store = new state.Store(); store = new state.Store();
@ -66,37 +80,25 @@ state.core = (function () {
loadUI(); loadUI();
restoreTabs(config); restoreTabs(config);
for (const [settingId, element] of Object.entries(ELEMENTS)) { forEachElement(ELEMENTS, config, (element, tab) => {
TABS.forEach(tab => { handleSavedInput(`${tab}_${element}`);
if (config.hasSetting(settingId, tab)) { });
handleSavedInput(`${tab}_${element}`);
}
});
}
for (const [settingId, element] of Object.entries(ELEMENTS_WITHOUT_PREFIX)) { forEachElement(ELEMENTS_WITHOUT_PREFIX, config, (element, tab) => {
TABS.forEach(tab => { handleSavedInput(`${element}`);
if (config.hasSetting(settingId, tab)) { });
handleSavedInput(`${element}`);
}
});
}
for (const [settingId, element] of Object.entries(SELECTS)) { forEachElement(SELECTS, config, (element, tab) => {
TABS.forEach(tab => { handleSavedSelects(`${tab}_${element}`);
if (config.hasSetting(settingId, tab)) { });
handleSavedSelects(`${tab}_${element}`);
}
});
}
for (const [settingId, element] of Object.entries(MULTI_SELECTS)) { forEachElement(MULTI_SELECTS, config, (element, tab) => {
TABS.forEach(tab => { handleSavedMultiSelects(`${tab}_${element}`);
if (config.hasSetting(settingId, tab)) { });
handleSavedMultiSelects(`${tab}_${element}`);
} forEachElement(TOGGLE_BUTTONS, config, (element, tab) => {
}); handleToggleButton(`${tab}_${element}`);
} });
handleExtensions(config); handleExtensions(config);
handleSettingsPage(); handleSettingsPage();
@ -208,6 +210,17 @@ state.core = (function () {
state.utils.handleMultipleSelect(select, id, store); state.utils.handleMultipleSelect(select, id, store);
} }
function handleToggleButton(id) {
const btn = gradioApp().querySelector(`button#${id}`);
if (! btn) { return; }
if (store.get(id) === 'true') {
state.utils.triggerMouseEvent(btn);
}
btn.addEventListener('click', function () {
store.set(id, Array.from(this.classList).indexOf('secondary-down') === -1);
});
}
function handleExtensions(config) { function handleExtensions(config) {
if (config['state_extensions']) { if (config['state_extensions']) {
config['state_extensions'].forEach(function (ext) { config['state_extensions'].forEach(function (ext) {

View File

@ -17,6 +17,7 @@ def on_ui_settings():
"choices": [ "choices": [
"prompt", "prompt",
"negative_prompt", "negative_prompt",
"extra_networks",
"styles", "styles",
"sampling", "sampling",
"sampling_steps", "sampling_steps",
@ -42,6 +43,7 @@ def on_ui_settings():
"choices": [ "choices": [
"prompt", "prompt",
"negative_prompt", "negative_prompt",
"extra_networks",
"styles", "styles",
"sampling", "sampling",
"resize_mode", "resize_mode",