mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-04-19 08:58:52 +02:00
Merge branch 'beta' into textualinv
This commit is contained in:
commit
c6d6446606
@ -1,10 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
import shutil
|
||||||
|
|
||||||
# The config file is in the same directory as this script
|
# The config file is in the same directory as this script
|
||||||
config_directory = os.path.dirname(__file__)
|
config_directory = os.path.dirname(__file__)
|
||||||
config_yaml = os.path.join(config_directory, "config.yaml")
|
config_yaml = os.path.join(config_directory, "..", "config.yaml")
|
||||||
config_json = os.path.join(config_directory, "config.json")
|
config_json = os.path.join(config_directory, "config.json")
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Get values from config file')
|
parser = argparse.ArgumentParser(description='Get values from config file')
|
||||||
@ -15,6 +16,12 @@ parser.add_argument('key', metavar='key', nargs='+',
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
config = None
|
||||||
|
|
||||||
|
# migrate the old config yaml location
|
||||||
|
config_legacy_yaml = os.path.join(config_directory, "config.yaml")
|
||||||
|
if os.path.isfile(config_legacy_yaml):
|
||||||
|
shutil.move(config_legacy_yaml, config_yaml)
|
||||||
|
|
||||||
if os.path.isfile(config_yaml):
|
if os.path.isfile(config_yaml):
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
@ -24,7 +31,6 @@ if os.path.isfile(config_yaml):
|
|||||||
config = yaml.load(configfile)
|
config = yaml.load(configfile)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
config = {}
|
|
||||||
elif os.path.isfile(config_json):
|
elif os.path.isfile(config_json):
|
||||||
import json
|
import json
|
||||||
with open(config_json, 'r') as configfile:
|
with open(config_json, 'r') as configfile:
|
||||||
@ -32,8 +38,8 @@ elif os.path.isfile(config_json):
|
|||||||
config = json.load(configfile)
|
config = json.load(configfile)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
config = {}
|
|
||||||
else:
|
if config is None:
|
||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
for k in args.key:
|
for k in args.key:
|
||||||
|
@ -102,7 +102,13 @@ def init():
|
|||||||
|
|
||||||
|
|
||||||
def getConfig(default_val=APP_CONFIG_DEFAULTS):
|
def getConfig(default_val=APP_CONFIG_DEFAULTS):
|
||||||
config_yaml_path = os.path.join(CONFIG_DIR, "config.yaml")
|
config_yaml_path = os.path.join(CONFIG_DIR, "..", "config.yaml")
|
||||||
|
|
||||||
|
# migrate the old config yaml location
|
||||||
|
config_legacy_yaml = os.path.join(CONFIG_DIR, "config.yaml")
|
||||||
|
if os.path.isfile(config_legacy_yaml):
|
||||||
|
shutil.move(config_legacy_yaml, config_yaml_path)
|
||||||
|
|
||||||
if os.path.isfile(config_yaml_path):
|
if os.path.isfile(config_yaml_path):
|
||||||
try:
|
try:
|
||||||
yaml = YAML()
|
yaml = YAML()
|
||||||
@ -133,8 +139,11 @@ def getConfig(default_val=APP_CONFIG_DEFAULTS):
|
|||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
# Save config in new format
|
# Save config in new format
|
||||||
setConfig(config)
|
setConfig(config)
|
||||||
shutil.move(config_json_path, config_json_path + ".bak")
|
|
||||||
log.info("Saved old config.json as config.json.bak")
|
with open(config_json_path + ".txt", "w") as f:
|
||||||
|
f.write("Moved to config.yaml inside the Easy Diffusion folder. You can open it in any text editor.")
|
||||||
|
os.remove(config_json_path)
|
||||||
|
|
||||||
return getConfig(default_val)
|
return getConfig(default_val)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warn(traceback.format_exc())
|
log.warn(traceback.format_exc())
|
||||||
@ -143,7 +152,7 @@ def getConfig(default_val=APP_CONFIG_DEFAULTS):
|
|||||||
|
|
||||||
def setConfig(config):
|
def setConfig(config):
|
||||||
try: # config.yaml
|
try: # config.yaml
|
||||||
config_yaml_path = os.path.join(CONFIG_DIR, "config.yaml")
|
config_yaml_path = os.path.join(CONFIG_DIR, "..", "config.yaml")
|
||||||
yaml = YAML()
|
yaml = YAML()
|
||||||
|
|
||||||
if not hasattr(config, "_yaml_comment"):
|
if not hasattr(config, "_yaml_comment"):
|
||||||
@ -158,8 +167,19 @@ def setConfig(config):
|
|||||||
|
|
||||||
config = commented_config
|
config = commented_config
|
||||||
yaml.indent(mapping=2, sequence=4, offset=2)
|
yaml.indent(mapping=2, sequence=4, offset=2)
|
||||||
with open(config_yaml_path, "w", encoding="utf-8") as f:
|
|
||||||
|
try:
|
||||||
|
f = open(config_yaml_path + ".tmp", "w", encoding="utf-8")
|
||||||
yaml.dump(config, f)
|
yaml.dump(config, f)
|
||||||
|
finally:
|
||||||
|
f.close() # do this explicitly to avoid NUL bytes (possible rare bug when using 'with')
|
||||||
|
|
||||||
|
# verify that the new file is valid, and only then overwrite the old config file
|
||||||
|
# helps prevent the rare NUL bytes error from corrupting the config file
|
||||||
|
yaml = YAML()
|
||||||
|
with open(config_yaml_path + ".tmp", "r", encoding="utf-8") as f:
|
||||||
|
yaml.load(f)
|
||||||
|
shutil.move(config_yaml_path + ".tmp", config_yaml_path)
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
log.error(traceback.format_exc())
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@
|
|||||||
<div id="preview-content">
|
<div id="preview-content">
|
||||||
<div id="preview-tools" class="displayNone">
|
<div id="preview-tools" class="displayNone">
|
||||||
<button id="clear-all-previews" class="secondaryButton"><i class="fa-solid fa-trash-can icon"></i> Clear All</button>
|
<button id="clear-all-previews" class="secondaryButton"><i class="fa-solid fa-trash-can icon"></i> Clear All</button>
|
||||||
<button class="tertiaryButton" id="show-download-popup"><i class="fa-solid fa-download"></i> Download images</button>
|
<button class="tertiaryButton" id="show-download-dialog"><i class="fa-solid fa-download"></i> Download images</button>
|
||||||
<div class="display-settings">
|
<div class="display-settings">
|
||||||
<button id="undo" class="displayNone primaryButton">
|
<button id="undo" class="displayNone primaryButton">
|
||||||
Undo <i class="fa-solid fa-rotate-left icon"></i>
|
Undo <i class="fa-solid fa-rotate-left icon"></i>
|
||||||
@ -467,31 +467,37 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="popup" id="download-images-popup">
|
<dialog id="download-images-dialog">
|
||||||
<div>
|
<div class="dialog-header">
|
||||||
<i class="close-button fa-solid fa-xmark"></i>
|
<div class="dialog-header-left">
|
||||||
<h1>Download all images</h1>
|
<h4>Download all images</h4>
|
||||||
<div class="parameters-table">
|
<span></span>
|
||||||
<div>
|
|
||||||
<div><i class="fa fa-file-zipper"></i></div>
|
|
||||||
<div><label for="theme">Download as a ZIP file</label><small>Instead of downloading individual files, generate one zip file with all images</small></div>
|
|
||||||
<div><div class="input-toggle"><input id="zip_toggle" name="zip_toggle" checked="" type="checkbox"><label for="zip_toggle"></label></div></div>
|
|
||||||
</div>
|
|
||||||
<div id="download-add-folders">
|
|
||||||
<div><i class="fa fa-folder-tree"></i></div>
|
|
||||||
<div><label for="theme">Add per-job folders</label><small>Place images into job folders</small></div>
|
|
||||||
<div><div class="input-toggle"><input id="tree_toggle" name="tree_toggle" checked="" type="checkbox"><label for="tree_toggle"></label></div></div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div><i class="fa fa-sliders"></i></div>
|
|
||||||
<div><label for="theme">Add metadata files</label><small>For each image, also download a JSON file with all the settings used to generate the image</small></div>
|
|
||||||
<div><div class="input-toggle"><input id="json_toggle" name="json_toggle" checked="" type="checkbox"><label for="json_toggle"></label></div></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<div>
|
||||||
|
<i id="download-images-close-button" class="fa-solid fa-xmark fa-lg"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="parameters-table">
|
||||||
|
<div>
|
||||||
|
<div><i class="fa fa-file-zipper"></i></div>
|
||||||
|
<div><label for="theme">Download as a ZIP file</label><small>Instead of downloading individual files, generate one zip file with all images</small></div>
|
||||||
|
<div><div class="input-toggle"><input id="zip_toggle" name="zip_toggle" checked="" type="checkbox"><label for="zip_toggle"></label></div></div>
|
||||||
|
</div>
|
||||||
|
<div id="download-add-folders">
|
||||||
|
<div><i class="fa fa-folder-tree"></i></div>
|
||||||
|
<div><label for="theme">Add per-job folders</label><small>Place images into job folders</small></div>
|
||||||
|
<div><div class="input-toggle"><input id="tree_toggle" name="tree_toggle" checked="" type="checkbox"><label for="tree_toggle"></label></div></div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div><i class="fa fa-sliders"></i></div>
|
||||||
|
<div><label for="theme">Add metadata files</label><small>For each image, also download a JSON file with all the settings used to generate the image</small></div>
|
||||||
|
<div><div class="input-toggle"><input id="json_toggle" name="json_toggle" checked="" type="checkbox"><label for="json_toggle"></label></div></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
<button id="save-all-images" class="primaryButton"><i class="fa-solid fa-images"></i> Start download</button>
|
<button id="save-all-images" class="primaryButton"><i class="fa-solid fa-images"></i> Start download</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</dialog>
|
||||||
<div id="save-settings-config" class="popup">
|
<div id="save-settings-config" class="popup">
|
||||||
<div>
|
<div>
|
||||||
<i class="close-button fa-solid fa-xmark"></i>
|
<i class="close-button fa-solid fa-xmark"></i>
|
||||||
|
@ -485,7 +485,7 @@ dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dialog::backdrop {
|
dialog::backdrop {
|
||||||
background: rgba(0, 0, 0, 0.5);
|
background: var(--backdrop-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog > div {
|
dialog > div {
|
||||||
@ -1448,10 +1448,18 @@ button#save-system-settings-btn {
|
|||||||
line-height: 200%;
|
line-height: 200%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#download-images-popup .parameters-table > div {
|
#download-images-dialog .parameters-table > div {
|
||||||
background: var(--background-color1);
|
background: var(--background-color1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fa-xmark {
|
||||||
|
cursor: pointer;;
|
||||||
|
}
|
||||||
|
|
||||||
/* SCROLLBARS */
|
/* SCROLLBARS */
|
||||||
:root {
|
:root {
|
||||||
--scrollbar-width: 14px;
|
--scrollbar-width: 14px;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
:root {
|
:root, ::backdrop {
|
||||||
--main-hue: 222;
|
--main-hue: 222;
|
||||||
--main-saturation: 4%;
|
--main-saturation: 4%;
|
||||||
--value-base: 13%;
|
--value-base: 13%;
|
||||||
|
@ -565,12 +565,6 @@ modifierSettingsCloseBtn.addEventListener("click", (e) => {
|
|||||||
modifierSettingsDialog.close()
|
modifierSettingsDialog.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
modifierSettingsDialog.addEventListener('mousedown', function (event) {
|
modalDialogCloseOnBackdropClick(modifierSettingsDialog)
|
||||||
var rect = modifierSettingsDialog.getBoundingClientRect();
|
makeDialogDraggable(modifierSettingsDialog)
|
||||||
var isInDialog=(rect.top <= event.clientY && event.clientY <= rect.top + rect.height
|
|
||||||
&& rect.left <= event.clientX && event.clientX <= rect.left + rect.width);
|
|
||||||
if (!isInDialog) {
|
|
||||||
modifierSettingsDialog.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
@ -138,9 +138,10 @@ let initialText = document.querySelector("#initial-text")
|
|||||||
let versionText = document.querySelector("#version")
|
let versionText = document.querySelector("#version")
|
||||||
let previewTools = document.querySelector("#preview-tools")
|
let previewTools = document.querySelector("#preview-tools")
|
||||||
let clearAllPreviewsBtn = document.querySelector("#clear-all-previews")
|
let clearAllPreviewsBtn = document.querySelector("#clear-all-previews")
|
||||||
let showDownloadPopupBtn = document.querySelector("#show-download-popup")
|
let showDownloadDialogBtn = document.querySelector("#show-download-dialog")
|
||||||
let saveAllImagesPopup = document.querySelector("#download-images-popup")
|
let saveAllImagesDialog = document.querySelector("#download-images-dialog")
|
||||||
let saveAllImagesBtn = document.querySelector("#save-all-images")
|
let saveAllImagesBtn = document.querySelector("#save-all-images")
|
||||||
|
let saveAllImagesCloseBtn = document.querySelector("#download-images-close-button")
|
||||||
let saveAllZipToggle = document.querySelector("#zip_toggle")
|
let saveAllZipToggle = document.querySelector("#zip_toggle")
|
||||||
let saveAllTreeToggle = document.querySelector("#tree_toggle")
|
let saveAllTreeToggle = document.querySelector("#tree_toggle")
|
||||||
let saveAllJSONToggle = document.querySelector("#json_toggle")
|
let saveAllJSONToggle = document.querySelector("#json_toggle")
|
||||||
@ -1509,9 +1510,10 @@ clearAllPreviewsBtn.addEventListener("click", (e) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/* Download images popup */
|
/* Download images popup */
|
||||||
showDownloadPopupBtn.addEventListener("click", (e) => {
|
showDownloadDialogBtn.addEventListener("click", (e) => { saveAllImagesDialog.showModal() })
|
||||||
saveAllImagesPopup.classList.add("active")
|
saveAllImagesCloseBtn.addEventListener("click", (e) => { saveAllImagesDialog.close() })
|
||||||
})
|
modalDialogCloseOnBackdropClick(saveAllImagesDialog)
|
||||||
|
makeDialogDraggable(saveAllImagesDialog)
|
||||||
|
|
||||||
saveAllZipToggle.addEventListener("change", (e) => {
|
saveAllZipToggle.addEventListener("change", (e) => {
|
||||||
if (saveAllZipToggle.checked) {
|
if (saveAllZipToggle.checked) {
|
||||||
|
@ -1071,3 +1071,58 @@ async function deleteKeys(keyToDelete) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function modalDialogCloseOnBackdropClick(dialog) {
|
||||||
|
dialog.addEventListener('mousedown', function (event) {
|
||||||
|
var rect = dialog.getBoundingClientRect()
|
||||||
|
var isInDialog=(rect.top <= event.clientY && event.clientY <= rect.top + rect.height
|
||||||
|
&& rect.left <= event.clientX && event.clientX <= rect.left + rect.width)
|
||||||
|
if (!isInDialog) {
|
||||||
|
dialog.close()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeDialogDraggable(element) {
|
||||||
|
element.querySelector(".dialog-header").addEventListener('mousedown', (function() {
|
||||||
|
let deltaX=0
|
||||||
|
let deltaY=0
|
||||||
|
let dragStartX=0
|
||||||
|
let dragStartY=0
|
||||||
|
let oldTop=0
|
||||||
|
let oldLeft=0
|
||||||
|
|
||||||
|
function dlgDragStart(e) {
|
||||||
|
e = e || window.event;
|
||||||
|
const d = e.target.closest("dialog")
|
||||||
|
e.preventDefault();
|
||||||
|
dragStartX = e.clientX;
|
||||||
|
dragStartY = e.clientY;
|
||||||
|
oldTop = parseInt(d.style.top)
|
||||||
|
oldLeft = parseInt(d.style.left)
|
||||||
|
if (isNaN(oldTop)) { oldTop=0 }
|
||||||
|
if (isNaN(oldLeft)) { oldLeft=0 }
|
||||||
|
document.addEventListener('mouseup', dlgDragClose);
|
||||||
|
document.addEventListener('mousemove', dlgDrag);
|
||||||
|
}
|
||||||
|
|
||||||
|
function dlgDragClose(e) {
|
||||||
|
document.removeEventListener('mouseup', dlgDragClose);
|
||||||
|
document.removeEventListener('mousemove', dlgDrag);
|
||||||
|
}
|
||||||
|
|
||||||
|
function dlgDrag(e) {
|
||||||
|
e = e || window.event;
|
||||||
|
const d = e.target.closest("dialog")
|
||||||
|
e.preventDefault();
|
||||||
|
deltaX = dragStartX - e.clientX;
|
||||||
|
deltaY = dragStartY - e.clientY;
|
||||||
|
d.style.left = `${oldLeft-2*deltaX}px`
|
||||||
|
d.style.top = `${oldTop-2*deltaY}px`
|
||||||
|
}
|
||||||
|
|
||||||
|
return dlgDragStart
|
||||||
|
})() )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
<h4>Download tiled image</h4>
|
<h4>Download tiled image</h4>
|
||||||
<span>Generate a larger image from this tile</span>
|
<span>Generate a larger image from this tile</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="modifier-settings-header-right">
|
<div id="download-header-right">
|
||||||
<i id="downnload-tiled-close-button" class="fa-solid fa-xmark fa-lg"></i>
|
<i id="downnload-tiled-close-button" class="fa-solid fa-xmark fa-lg"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -139,14 +139,8 @@
|
|||||||
// ---- Close popup
|
// ---- Close popup
|
||||||
document.getElementById("dti-cancel").addEventListener("click", (e) => downloadTiledImageDialog.close())
|
document.getElementById("dti-cancel").addEventListener("click", (e) => downloadTiledImageDialog.close())
|
||||||
document.getElementById("downnload-tiled-close-button").addEventListener("click", (e) => downloadTiledImageDialog.close())
|
document.getElementById("downnload-tiled-close-button").addEventListener("click", (e) => downloadTiledImageDialog.close())
|
||||||
downloadTiledImageDialog.addEventListener('click', function (event) {
|
modalDialogCloseOnBackdropClick(downloadTiledImageDialog)
|
||||||
var rect = downloadTiledImageDialog.getBoundingClientRect();
|
makeDialogDraggable(downloadTiledImageDialog)
|
||||||
var isInDialog=(rect.top <= event.clientY && event.clientY <= rect.top + rect.height
|
|
||||||
&& rect.left <= event.clientX && event.clientX <= rect.left + rect.width);
|
|
||||||
if (!isInDialog) {
|
|
||||||
downloadTiledImageDialog.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// ---- Stylesheet
|
// ---- Stylesheet
|
||||||
const styleSheet = document.createElement("style")
|
const styleSheet = document.createElement("style")
|
||||||
|
Loading…
Reference in New Issue
Block a user