diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-08-10 14:04:38 +0000 |
---|---|---|
committer | AUTOMATIC1111 <16777216c@gmail.com> | 2023-08-10 14:04:38 +0000 |
commit | 70a01cd4440d708bf25cc50393c0430935a8ebc2 (patch) | |
tree | daad07800a3dadfd3caeac1383c1c65ecfcb6284 /modules/ui_components.py | |
parent | 1aefb5025929818b2a96cbb6148fcc2db7b947ec (diff) | |
parent | 070b034cd5b49eb5056a18b43f88aa223fec9e0b (diff) | |
download | stable-diffusion-webui-gfx803-70a01cd4440d708bf25cc50393c0430935a8ebc2.tar.gz stable-diffusion-webui-gfx803-70a01cd4440d708bf25cc50393c0430935a8ebc2.tar.bz2 stable-diffusion-webui-gfx803-70a01cd4440d708bf25cc50393c0430935a8ebc2.zip |
Merge branch 'dev' into refiner
Diffstat (limited to 'modules/ui_components.py')
-rw-r--r-- | modules/ui_components.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/ui_components.py b/modules/ui_components.py index 8f8a7088..bfe2fbd9 100644 --- a/modules/ui_components.py +++ b/modules/ui_components.py @@ -72,3 +72,52 @@ class DropdownEditable(FormComponent, gr.Dropdown): def get_block_name(self):
return "dropdown"
+
+class InputAccordion(gr.Checkbox):
+ """A gr.Accordion that can be used as an input - returns True if open, False if closed.
+
+ Actaully just a hidden checkbox, but creates an accordion that follows and is followed by the state of the checkbox.
+ """
+
+ global_index = 0
+
+ def __init__(self, value, **kwargs):
+ self.accordion_id = kwargs.get('elem_id')
+ if self.accordion_id is None:
+ self.accordion_id = f"input-accordion-{InputAccordion.global_index}"
+ InputAccordion.global_index += 1
+
+ kwargs['elem_id'] = self.accordion_id + "-checkbox"
+ kwargs['visible'] = False
+ super().__init__(value, **kwargs)
+
+ self.change(fn=None, _js='function(checked){ inputAccordionChecked("' + self.accordion_id + '", checked); }', inputs=[self])
+
+ self.accordion = gr.Accordion(kwargs.get('label', 'Accordion'), open=value, elem_id=self.accordion_id, elem_classes=['input-accordion'])
+
+ def extra(self):
+ """Allows you to put something into the label of the accordion.
+
+ Use it like this:
+
+ ```
+ with InputAccordion(False, label="Accordion") as acc:
+ with acc.extra():
+ FormHTML(value="hello", min_width=0)
+
+ ...
+ ```
+ """
+
+ return gr.Column(elem_id=self.accordion_id + '-extra', elem_classes='input-accordion-extra', min_width=0)
+
+ def __enter__(self):
+ self.accordion.__enter__()
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ self.accordion.__exit__(exc_type, exc_val, exc_tb)
+
+ def get_block_name(self):
+ return "checkbox"
+
|