WebUI/modules/ui_components.py

65 lines
1.6 KiB
Python
Raw Normal View History

2023-01-01 10:08:40 +00:00
import gradio as gr
2023-03-20 13:09:36 +00:00
class FormComponent:
def get_expected_parent(self):
return gr.components.Form
2023-01-01 10:08:40 +00:00
2023-03-20 13:09:36 +00:00
gr.Dropdown.get_expected_parent = FormComponent.get_expected_parent
2023-01-01 10:08:40 +00:00
2023-03-20 13:09:36 +00:00
class ToolButton(FormComponent, gr.Button):
"""Small button with single emoji as text, fits inside gradio forms"""
2023-03-20 13:09:36 +00:00
def __init__(self, *args, **kwargs):
classes = kwargs.pop("elem_classes", [])
super().__init__(*args, elem_classes=["tool", *classes], **kwargs)
def get_block_name(self):
return "button"
2023-03-20 13:09:36 +00:00
class FormRow(FormComponent, gr.Row):
2023-01-01 10:08:40 +00:00
"""Same as gr.Row but fits inside gradio forms"""
def get_block_name(self):
return "row"
2023-03-20 13:09:36 +00:00
class FormColumn(FormComponent, gr.Column):
"""Same as gr.Column but fits inside gradio forms"""
def get_block_name(self):
return "column"
class FormGroup(FormComponent, gr.Group):
"""Same as gr.Row but fits inside gradio forms"""
def get_block_name(self):
return "group"
2023-03-20 13:09:36 +00:00
class FormHTML(FormComponent, gr.HTML):
"""Same as gr.HTML but fits inside gradio forms"""
def get_block_name(self):
return "html"
2023-03-20 13:09:36 +00:00
class FormColorPicker(FormComponent, gr.ColorPicker):
"""Same as gr.ColorPicker but fits inside gradio forms"""
def get_block_name(self):
return "colorpicker"
2023-03-20 13:09:36 +00:00
class DropdownMulti(FormComponent, gr.Dropdown):
"""Same as gr.Dropdown but always multiselect"""
def __init__(self, **kwargs):
super().__init__(multiselect=True, **kwargs)
def get_block_name(self):
return "dropdown"