Commit ·
b7aa11b
1
Parent(s): 940a07c
5 sec confirmation window for quit button
Browse files
wgp.py
CHANGED
|
@@ -731,6 +731,12 @@ def quit_application():
|
|
| 731 |
import signal
|
| 732 |
os.kill(os.getpid(), signal.SIGINT)
|
| 733 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 734 |
def autosave_queue():
|
| 735 |
global global_queue_ref
|
| 736 |
if not global_queue_ref:
|
|
@@ -3630,6 +3636,55 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
|
|
| 3630 |
load_queue_btn = gr.UploadButton("Load Queue", file_types=[".zip"], size="sm")
|
| 3631 |
clear_queue_btn = gr.Button("Clear Queue", size="sm", variant="stop")
|
| 3632 |
quit_button = gr.Button("Save and Quit", size="sm", variant="secondary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3633 |
trigger_zip_download_js = """
|
| 3634 |
(base64String) => {
|
| 3635 |
if (!base64String) {
|
|
@@ -3661,6 +3716,35 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
|
|
| 3661 |
}
|
| 3662 |
}
|
| 3663 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3664 |
save_queue_btn.click(
|
| 3665 |
fn=save_queue_action,
|
| 3666 |
inputs=[state],
|
|
@@ -3714,11 +3798,6 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
|
|
| 3714 |
inputs=None,
|
| 3715 |
outputs=[current_gen_column, queue_accordion]
|
| 3716 |
)
|
| 3717 |
-
quit_button.click(
|
| 3718 |
-
fn=quit_application,
|
| 3719 |
-
inputs=[],
|
| 3720 |
-
outputs=[]
|
| 3721 |
-
)
|
| 3722 |
|
| 3723 |
extra_inputs = prompt_vars + [wizard_prompt, wizard_variables_var, wizard_prompt_activated_var, video_prompt_column, image_prompt_column,
|
| 3724 |
prompt_column_advanced, prompt_column_wizard_vars, prompt_column_wizard, lset_name, advanced_row] # show_advanced presets_column,
|
|
|
|
| 731 |
import signal
|
| 732 |
os.kill(os.getpid(), signal.SIGINT)
|
| 733 |
|
| 734 |
+
def request_quit_confirmation():
|
| 735 |
+
return gr.update(visible=False), gr.update(visible=True)
|
| 736 |
+
|
| 737 |
+
def cancel_quit_confirmation():
|
| 738 |
+
return gr.update(visible=True), gr.update(visible=False)
|
| 739 |
+
|
| 740 |
def autosave_queue():
|
| 741 |
global global_queue_ref
|
| 742 |
if not global_queue_ref:
|
|
|
|
| 3636 |
load_queue_btn = gr.UploadButton("Load Queue", file_types=[".zip"], size="sm")
|
| 3637 |
clear_queue_btn = gr.Button("Clear Queue", size="sm", variant="stop")
|
| 3638 |
quit_button = gr.Button("Save and Quit", size="sm", variant="secondary")
|
| 3639 |
+
with gr.Row(visible=False) as quit_confirmation_row:
|
| 3640 |
+
gr.Markdown("Quitting in 5 seconds...", elem_id="quit_timer_label")
|
| 3641 |
+
confirm_quit_button = gr.Button("Confirm Quit Now", elem_id="comfirm_quit_btn_hidden", size="sm", variant="stop")
|
| 3642 |
+
cancel_quit_button = gr.Button("Cancel Quit", size="sm", variant="secondary")
|
| 3643 |
+
hidden_force_quit_trigger = gr.Button("force_quit", visible=False, elem_id="force_quit_btn_hidden")
|
| 3644 |
+
|
| 3645 |
+
start_quit_timer_js = """
|
| 3646 |
+
() => {
|
| 3647 |
+
function findAndClickGradioButton(elemId) {
|
| 3648 |
+
const gradioApp = document.querySelector('gradio-app') || document;
|
| 3649 |
+
const button = gradioApp.querySelector(`#${elemId}`);
|
| 3650 |
+
if (button) {
|
| 3651 |
+
button.click();
|
| 3652 |
+
}
|
| 3653 |
+
}
|
| 3654 |
+
window.quitTimerId = setTimeout(() => {
|
| 3655 |
+
}, 5000);
|
| 3656 |
+
let countdown = 5;
|
| 3657 |
+
const label = document.getElementById('quit_timer_label');
|
| 3658 |
+
if (label) {
|
| 3659 |
+
label.innerText = `Quitting in ${countdown}...`;
|
| 3660 |
+
window.quitCountdownInterval = setInterval(() => {
|
| 3661 |
+
countdown--;
|
| 3662 |
+
if (countdown > 0) {
|
| 3663 |
+
label.innerText = `Quitting in ${countdown}...`;
|
| 3664 |
+
} else {
|
| 3665 |
+
clearInterval(window.quitCountdownInterval);
|
| 3666 |
+
findAndClickGradioButton('comfirm_quit_btn_hidden');
|
| 3667 |
+
}
|
| 3668 |
+
}, 1000);
|
| 3669 |
+
}
|
| 3670 |
+
}
|
| 3671 |
+
"""
|
| 3672 |
+
|
| 3673 |
+
cancel_quit_timer_js = """
|
| 3674 |
+
() => {
|
| 3675 |
+
if (window.quitTimerId) {
|
| 3676 |
+
clearTimeout(window.quitTimerId);
|
| 3677 |
+
window.quitTimerId = null;
|
| 3678 |
+
}
|
| 3679 |
+
if(window.quitCountdownInterval) {
|
| 3680 |
+
clearInterval(window.quitCountdownInterval);
|
| 3681 |
+
window.quitCountdownInterval = null;
|
| 3682 |
+
}
|
| 3683 |
+
const label = document.getElementById('quit_timer_label');
|
| 3684 |
+
if(label) { label.innerText = 'Quit cancelled.'; }
|
| 3685 |
+
}
|
| 3686 |
+
"""
|
| 3687 |
+
|
| 3688 |
trigger_zip_download_js = """
|
| 3689 |
(base64String) => {
|
| 3690 |
if (!base64String) {
|
|
|
|
| 3716 |
}
|
| 3717 |
}
|
| 3718 |
"""
|
| 3719 |
+
|
| 3720 |
+
quit_button.click(
|
| 3721 |
+
fn=request_quit_confirmation,
|
| 3722 |
+
inputs=[],
|
| 3723 |
+
outputs=[quit_button, quit_confirmation_row]
|
| 3724 |
+
).then(
|
| 3725 |
+
fn=None, inputs=None, outputs=None, js=start_quit_timer_js
|
| 3726 |
+
)
|
| 3727 |
+
|
| 3728 |
+
confirm_quit_button.click(
|
| 3729 |
+
fn=quit_application,
|
| 3730 |
+
inputs=[],
|
| 3731 |
+
outputs=[]
|
| 3732 |
+
)
|
| 3733 |
+
|
| 3734 |
+
cancel_quit_button.click(
|
| 3735 |
+
fn=cancel_quit_confirmation,
|
| 3736 |
+
inputs=[],
|
| 3737 |
+
outputs=[quit_button, quit_confirmation_row]
|
| 3738 |
+
).then(
|
| 3739 |
+
fn=None, inputs=None, outputs=None, js=cancel_quit_timer_js
|
| 3740 |
+
)
|
| 3741 |
+
|
| 3742 |
+
hidden_force_quit_trigger.click(
|
| 3743 |
+
fn=quit_application,
|
| 3744 |
+
inputs=[],
|
| 3745 |
+
outputs=[]
|
| 3746 |
+
)
|
| 3747 |
+
|
| 3748 |
save_queue_btn.click(
|
| 3749 |
fn=save_queue_action,
|
| 3750 |
inputs=[state],
|
|
|
|
| 3798 |
inputs=None,
|
| 3799 |
outputs=[current_gen_column, queue_accordion]
|
| 3800 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3801 |
|
| 3802 |
extra_inputs = prompt_vars + [wizard_prompt, wizard_variables_var, wizard_prompt_activated_var, video_prompt_column, image_prompt_column,
|
| 3803 |
prompt_column_advanced, prompt_column_wizard_vars, prompt_column_wizard, lset_name, advanced_row] # show_advanced presets_column,
|