InputAccordion duplicate elem_id handling (#16381)

This commit is contained in:
w-e-w 2024-10-30 00:03:21 +09:00 committed by GitHub
parent 59481435f4
commit 5206b938ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -91,6 +91,7 @@ class InputAccordion(gr.Checkbox):
Actually just a hidden checkbox, but creates an accordion that follows and is followed by the state of the checkbox.
"""
accordion_id_set = set()
global_index = 0
def __init__(self, value, **kwargs):
@ -99,6 +100,18 @@ class InputAccordion(gr.Checkbox):
self.accordion_id = f"input-accordion-{InputAccordion.global_index}"
InputAccordion.global_index += 1
if not InputAccordion.accordion_id_set:
from modules import script_callbacks
script_callbacks.on_script_unloaded(InputAccordion.reset)
if self.accordion_id in InputAccordion.accordion_id_set:
count = 1
while (unique_id := f'{self.accordion_id}-{count}') in InputAccordion.accordion_id_set:
count += 1
self.accordion_id = unique_id
InputAccordion.accordion_id_set.add(self.accordion_id)
kwargs_checkbox = {
**kwargs,
"elem_id": f"{self.accordion_id}-checkbox",
@ -143,3 +156,7 @@ class InputAccordion(gr.Checkbox):
def get_block_name(self):
return "checkbox"
@classmethod
def reset(cls):
cls.global_index = 0
cls.accordion_id_set.clear()