Add files via upload

main
EnsignMK 2023-07-15 14:07:12 +02:00 committed by GitHub
parent 445257b913
commit 401275e306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 0 deletions

44
scripts/shutdown.py Normal file
View File

@ -0,0 +1,44 @@
from modules import shared, script_callbacks
from modules import script_callbacks
import gradio as gr
import os
def clean(lst):
y = [x.strip("\n") for x in lst]
return y[-1]
js = """function close_window() {
if (confirm("Close the application?")) {
close();
return true;
} else {
return false;
}
}
"""
def stop_button(component, **kwargs):
after_this_compo = "setting_{}".format(clean(shared.opts.data["quicksettings"].split(",")))
# print(after_this_compo)
if kwargs.get("elem_id") == after_this_compo:
with gr.Row(elem_id="quicksettings", variant="compact"):
btn = gr.Button("Exit ⭕", elem_id="stop_button",size="sm",variant='stop')
hidden_checkbox = gr.Checkbox(visible=False)
def when(hidden_state):
if hidden_state:
os._exit(0)
return False
btn.click(when, hidden_checkbox, hidden_checkbox, _js=js)
script_callbacks.on_after_component(stop_button)