Skip to content

Commit 0995e87

Browse files
committed
added save button and shortcut (s) to Modal View
1 parent 737eb28 commit 0995e87

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

javascript/imageviewer.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,25 @@ function modalImageSwitch(offset) {
8181
}
8282
}
8383

84+
function saveImage(){
85+
const tabTxt2Img = gradioApp().getElementById("tab_txt2img")
86+
const tabImg2Img = gradioApp().getElementById("tab_img2img")
87+
const saveTxt2Img = "save_txt2img"
88+
const saveImg2Img = "save_img2img"
89+
if (tabTxt2Img.style["display"] != "none") {
90+
gradioApp().getElementById(saveTxt2Img).click()
91+
} else if (tabImg2Img.style["display"] != "none") {
92+
gradioApp().getElementById(saveImg2Img).click()
93+
} else {
94+
console.error("missing implementation for saving modal of this type")
95+
}
96+
}
97+
98+
function modalSaveImage(event) {
99+
saveImage()
100+
event.stopPropagation()
101+
}
102+
84103
function modalNextImage(event) {
85104
modalImageSwitch(1)
86105
event.stopPropagation()
@@ -93,6 +112,9 @@ function modalPrevImage(event) {
93112

94113
function modalKeyHandler(event) {
95114
switch (event.key) {
115+
case "s":
116+
saveImage()
117+
break;
96118
case "ArrowLeft":
97119
modalPrevImage(event)
98120
break;
@@ -198,6 +220,13 @@ document.addEventListener("DOMContentLoaded", function() {
198220
modalTileImage.title = "Preview tiling";
199221
modalControls.appendChild(modalTileImage)
200222

223+
const modalSave = document.createElement("span")
224+
modalSave.className = "modalSave cursor"
225+
modalSave.innerHTML = "🖫"
226+
modalSave.addEventListener("click", modalSaveImage, true)
227+
modalSave.title = "Save Image(s)"
228+
modalControls.appendChild(modalSave)
229+
201230
const modalClose = document.createElement('span')
202231
modalClose.className = 'modalClose cursor';
203232
modalClose.innerHTML = '×'

modules/ui.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ def create_ui(wrap_gradio_gpu_call):
630630
import modules.img2img
631631
import modules.txt2img
632632

633-
633+
634634
with gr.Blocks(analytics_enabled=False) as txt2img_interface:
635635
txt2img_prompt, roll, txt2img_prompt_style, txt2img_negative_prompt, txt2img_prompt_style2, submit, _, _, txt2img_prompt_style_apply, txt2img_save_style, txt2img_paste, token_counter, token_button = create_toprow(is_img2img=False)
636636
dummy_component = gr.Label(visible=False)
@@ -683,7 +683,8 @@ def create_ui(wrap_gradio_gpu_call):
683683

684684
with gr.Column():
685685
with gr.Row():
686-
save = gr.Button('Save')
686+
saveButtonId = 'save_txt2img'
687+
save = gr.Button('Save', elem_id=saveButtonId)
687688
send_to_img2img = gr.Button('Send to img2img')
688689
send_to_inpaint = gr.Button('Send to inpaint')
689690
send_to_extras = gr.Button('Send to extras')
@@ -901,7 +902,8 @@ def create_ui(wrap_gradio_gpu_call):
901902

902903
with gr.Column():
903904
with gr.Row():
904-
save = gr.Button('Save')
905+
saveButtonId = 'save_img2img'
906+
save = gr.Button('Save', elem_id=saveButtonId)
905907
img2img_send_to_img2img = gr.Button('Send to img2img')
906908
img2img_send_to_inpaint = gr.Button('Send to inpaint')
907909
img2img_send_to_extras = gr.Button('Send to extras')

style.css

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ input[type="range"]{
314314

315315
.modalControls {
316316
display: grid;
317-
grid-template-columns: 32px auto 1fr 32px;
318-
grid-template-areas: "zoom tile space close";
317+
grid-template-columns: 32px auto 32px 1fr 32px;
318+
grid-template-areas: "zoom tile save space close";
319319
position: absolute;
320320
top: 0;
321321
left: 0;
@@ -333,6 +333,10 @@ input[type="range"]{
333333
grid-area: zoom;
334334
}
335335

336+
.modalSave {
337+
grid-area: save;
338+
}
339+
336340
.modalTileImage {
337341
grid-area: tile;
338342
}
@@ -346,8 +350,18 @@ input[type="range"]{
346350
cursor: pointer;
347351
}
348352

353+
.modalSave {
354+
color: white;
355+
font-size: 30px;
356+
margin-top: 6px;
357+
font-weight: bold;
358+
cursor: pointer;
359+
}
360+
349361
.modalClose:hover,
350362
.modalClose:focus,
363+
.modalSave:hover,
364+
.modalSave:focus,
351365
.modalZoom:hover,
352366
.modalZoom:focus {
353367
color: #999;

0 commit comments

Comments
 (0)