
@@ -673,13 +670,13 @@
-
-
-
+
+
+
@@ -692,6 +689,16 @@
Edit Text
+
+
+
diff --git a/index.js b/index.js
index ade6d62b..dc8129e0 100644
--- a/index.js
+++ b/index.js
@@ -2941,17 +2941,9 @@ document.getElementById('btnLoadHistory').addEventListener('click',async functio
img.dataset.path =`${output_dir_relative}/${image_path}`
img.className = "history-image"
img.dataset.metadata_json_string = JSON.stringify(metadata_jsons[i])
- container.appendChild(img)
- img.addEventListener('click',async (e)=>{
- const metadata_json = JSON.parse(e.target.dataset.metadata_json_string)
- console.log("metadata_json: ",metadata_json)
- // document.querySelector('#tiSeed').value = metadata_json.Seed
- document.querySelector('#historySeedLabel').textContent = metadata_json.Seed
- autoFillInSettings(metadata_json)
- let image_path = img.dataset.path
- const image_path_escape = image_path.replace(/\o/g,"/o") //escape string "\o" in "\output"
- await placeEmbedded(image_path_escape)
- })
+ img_container = viewer.Thumbnail.wrapImgInContainer(img, "thumbnail-image-container")
+ viewer.Thumbnail.addSPButtonToContainer(img_container, "svg_sp_btn_datadownload", "Copy Meta Data", loadMetaData, img)
+ container.appendChild(img_container)
i++
}
@@ -2961,6 +2953,19 @@ document.getElementById('btnLoadHistory').addEventListener('click',async functio
})
+async function loadMetaData(img){
+ debugger
+ const metadata_json = JSON.parse(img.dataset.metadata_json_string)
+ console.log("metadata_json: ",metadata_json)
+ // document.querySelector('#tiSeed').value = metadata_json.Seed
+ document.querySelector('#historySeedLabel').textContent = metadata_json.Seed
+ autoFillInSettings(metadata_json)
+ let image_path = img.dataset.path
+ const image_path_escape = image_path.replace(/\o/g,"/o") //escape string "\o" in "\output"
+ await placeEmbedded(image_path_escape)
+}
+
+
document.getElementById('btnImageSearch').addEventListener('click',async function(){
try{
diff --git a/viewer.js b/viewer.js
index c152bdfd..668ac6f8 100644
--- a/viewer.js
+++ b/viewer.js
@@ -152,51 +152,27 @@ class ViewerImage {
}
}
+ AddButtonHtml(){
- addButtonHtml(){
- // Create new container element
- const container = document.createElement('div');
-
-
- container.className = "viewer-image-container";
-
-
- const elem = document.getElementById('svg_sp_btn');
-
- // Create a copy of it
- const clone = elem.cloneNode(true);
- const button = clone
- button.style.display = null
- button.setAttribute('title',"use this image to generate more variance like it")
-
- // Create button element
- // const button = document.createElement('sp-button');
- button.className = "viewer-image-button";
- // button.innerHTML = "Button";
-
- button.addEventListener('click', async ()=> {
- //set init image event listener, use when settion is active
- const layer = await app.activeDocument.activeLayers[0]
- const image_name = await psapi.setInitImage(layer, random_session_id)
- const path = `./server/python_server/init_images/${image_name}`
- g_viewer_manager.addInitImageLayers(layer,path,false)
-
- })
-
+ const container = Thumbnail.wrapImgInContainer(this.img_html, "thumbnail-image-container")
+ Thumbnail.addSPButtonToContainer(container, "svg_sp_btn", "use this image to generate more variance like it", addImageToLayer, this)
-
- // Append elements to container
- container.appendChild(this.img_html);
- container.appendChild(button);
-
-
-
this.img_html = container;
}
+
}
+async function addImageToLayer(e){
+ //set init image event listener, use when settion is active
+ const layer = await app.activeDocument.activeLayers[0]
+ const image_name = await psapi.setInitImage(layer, random_session_id)
+ const path = `./server/python_server/init_images/${image_name}`
+ g_viewer_manager.addInitImageLayers(layer,path,false)
+}
+
+
class OutputImage extends ViewerImage {
constructor (layer, path) {
super()
@@ -628,10 +604,34 @@ class InitMaskImage extends ViewerImage {
}
}
+ class Thumbnail{
+ static wrapImgInContainer(img, container_style_class){
+ const container = document.createElement('div');
+ container.className = container_style_class;
+ container.appendChild(img);
+ return container;
+ }
+
+ static addSPButtonToContainer(container, button_id, title, callbackFunction, param1){
+ const elem = document.getElementById(button_id);
+ const clone = elem.cloneNode(true);
+ const button = clone
+ button.style.display = null
+ button.setAttribute('title',title)
+
+ // Create button element
+ button.className = "thumbnail-image-button";
+ button.addEventListener('click', () => callbackFunction(param1))
+ container.appendChild(button)
+ }
+
+ }
+
module.exports = {
OutputImage,
InitImage,
InitMaskImage,
ViewerObjState,
- ViewerManager
+ ViewerManager,
+ Thumbnail
}