mirror of
https://github.com/Zyin055/Config-Presets.git
synced 2026-02-01 14:09:54 +00:00
the txt2img and img2img dropdowns are now separated. each has its own config file and its own config presets. adjusted to sampler index not using checkboxes, but a dropdown now. adjusted for the removal of firstpass width/height, and added Upscale by. components on in the UI are tracked with elem_id instead of labels. when creating a new preset, need to restart the UI because of stupid Gradio desync bug. moved our dropdown UI section to below the gallery, instead of below the gallery's buttons. added error handling incase the A1111 UI changes the again to hopefully not brick people's UI. Create button renamed to Save & Restart. #16
37 lines
2.4 KiB
JavaScript
37 lines
2.4 KiB
JavaScript
//add tooltip by piggybacking off of javascript/hints.js ...
|
|
//titles["Add/Remove..."] = "[Config Presets] Add or remove a preset"
|
|
//...or do it our more precise way:
|
|
onUiUpdate(function() {
|
|
//set tooltips
|
|
gradioApp().querySelectorAll("#config_presets_open_config_file_button").forEach(el => el.setAttribute("title", "Open the config file for manual editing if you want to make changes that way, requires Gradio restart after editing. The txt2img and img2img tabs have separate config files."))
|
|
gradioApp().querySelectorAll("#config_preset_save_textbox").forEach(el => el.setAttribute("title", "The label that will be displayed in the dropdown to the left"))
|
|
gradioApp().querySelectorAll("#config_preset_save_button").forEach(el => el.setAttribute("title", "Saves current settings with the new preset name and restarts the UI. Overwrites existing preset. This will save: Sampler, Steps, Width/Height, Hires. fix, Upscale by, Denoising strength, Batch size, CFG Scale."))
|
|
gradioApp().querySelectorAll("#config_preset_add_button").forEach(el => el.setAttribute("title", "[Config Presets] Create or delete a preset"))
|
|
gradioApp().querySelectorAll("#config_preset_cancel_save_button").forEach(el => el.setAttribute("title", "Go back"))
|
|
gradioApp().querySelectorAll("#config_preset_trash_button").forEach(el => el.setAttribute("title", "Permanently delete selected preset"))
|
|
})
|
|
|
|
//this function called by config_preset_dropdown in config_presets.py
|
|
function config_preset_dropdown_change() {
|
|
//when Python changes the enable_hr checkbox in config_preset_dropdown_change() it doesn't fire off the change() JS event, so do this manually
|
|
|
|
//there is a race condition between the checkbox being checked in Python, and us firing its change event in JavaScript, so wait a bit before firing the event
|
|
setTimeout(function() {
|
|
let hiresFixCheckbox = gradioApp().querySelector("#txt2img_enable_hr > label").firstChild //gets the <input> element next to the "Hires. fix" <span>
|
|
|
|
let e = document.createEvent("HTMLEvents")
|
|
e.initEvent("change", true, false)
|
|
hiresFixCheckbox.dispatchEvent(e)
|
|
|
|
//console.log("hiresFixCheckbox="+hiresFixCheckbox)
|
|
//console.log("e="+e)
|
|
}, 200) //50ms is too fast
|
|
}
|
|
|
|
|
|
function config_preset_settings_restart_gradio() {
|
|
console.log('[Config-Presets] Restarting to apply new config preset...')
|
|
setTimeout(function() {
|
|
gradioApp().getElementById("settings_restart_gradio").click()
|
|
}, 1000)
|
|
} |