diff --git a/modules/ui_file_saving.py b/modules/ui_file_saving.py index 1625c83..39ab41d 100644 --- a/modules/ui_file_saving.py +++ b/modules/ui_file_saving.py @@ -37,6 +37,14 @@ def create_ui(): shared.gradio['delete_character_confirm'] = gr.Button('Delete', elem_classes="small-button", variant='stop', interactive=not mu) shared.gradio['delete_character_cancel'] = gr.Button('Cancel', elem_classes="small-button") + # Preset saver + with gr.Group(visible=False, elem_classes='file-saver') as shared.gradio['preset_saver']: + shared.gradio['save_preset_filename'] = gr.Textbox(lines=1, label='File name', info='The preset will be saved to your presets/ folder with this base filename.') + shared.gradio['save_preset_contents'] = gr.Textbox(lines=10, label='File contents') + with gr.Row(): + shared.gradio['save_preset_confirm'] = gr.Button('Save', elem_classes="small-button", variant='primary', interactive=not mu) + shared.gradio['save_preset_cancel'] = gr.Button('Cancel', elem_classes="small-button") + def create_event_handlers(): shared.gradio['save_confirm'].click( @@ -65,10 +73,16 @@ def create_event_handlers(): shared.gradio['save_preset'].click( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( - presets.generate_preset_yaml, gradio('interface_state'), gradio('save_contents')).then( - lambda: 'presets/', None, gradio('save_root')).then( - lambda: 'My Preset.yaml', None, gradio('save_filename')).then( - lambda: gr.update(visible=True), None, gradio('file_saver')) + presets.generate_preset_yaml, gradio('interface_state'), gradio('save_preset_contents')).then( + lambda: 'My Preset', None, gradio('save_preset_filename')).then( + lambda: gr.update(visible=True), None, gradio('preset_saver')) + + shared.gradio['save_preset_confirm'].click( + lambda x, y: utils.save_file(f'presets/{x}.yaml', y), gradio('save_preset_filename', 'save_preset_contents'), None).then( + lambda: gr.update(visible=False), None, gradio('preset_saver')).then( + lambda x: gr.update(choices=utils.get_available_presets(), value=x), gradio('save_preset_filename'), gradio('preset_menu')) + + shared.gradio['save_preset_cancel'].click(lambda: gr.update(visible=False), None, gradio('preset_saver')) shared.gradio['delete_preset'].click( lambda x: f'{x}.yaml', gradio('preset_menu'), gradio('delete_filename')).then(