(self)
| 718 | def setup_ui(self): |
| 719 | all_titles = [wrap_call(script.title, script.filename, "title") or script.filename for script in self.scripts] |
| 720 | self.title_map = {title.lower(): script for title, script in zip(all_titles, self.scripts)} |
| 721 | self.titles = [wrap_call(script.title, script.filename, "title") or f"{script.filename} [error]" for script in self.selectable_scripts] |
| 722 | |
| 723 | self.setup_ui_for_section(None) |
| 724 | |
| 725 | dropdown = gr.Dropdown(label="Script", elem_id="script_list", choices=["None"] + self.titles, value="None", type="index") |
| 726 | self.inputs[0] = dropdown |
| 727 | |
| 728 | self.setup_ui_for_section(None, self.selectable_scripts) |
| 729 | |
| 730 | def select_script(script_index): |
| 731 | if script_index is None: |
| 732 | script_index = [0] |
| 733 | |
| 734 | selected_script = self.selectable_scripts[script_index - 1] if script_index>0 else None |
| 735 | |
| 736 | return [gr.update(visible=selected_script == s) for s in self.selectable_scripts] |
| 737 | |
| 738 | if shared.opts.use_ui_config_json: |
| 739 | def init_field(title): |
| 740 | """called when an initial value is set from ui-config.json to show script's UI components""" |
| 741 | |
| 742 | if title == 'None': |
| 743 | return |
| 744 | |
| 745 | script_index = self.titles.index(title) |
| 746 | self.selectable_scripts[script_index].group.visible = True |
| 747 | |
| 748 | dropdown.init_field = init_field |
| 749 | |
| 750 | dropdown.change( |
| 751 | fn=select_script, |
| 752 | inputs=[dropdown], |
| 753 | outputs=[script.group for script in self.selectable_scripts] |
| 754 | ) |
| 755 | |
| 756 | self.script_load_ctr = 0 |
| 757 | |
| 758 | def onload_script_visibility(params): |
| 759 | title = params.get('Script', None) |
| 760 | if title: |
| 761 | try: |
| 762 | title_index = self.titles.index(title) |
| 763 | visibility = title_index == self.script_load_ctr |
| 764 | self.script_load_ctr = (self.script_load_ctr + 1) % len(self.titles) |
| 765 | return gr.update(visible=visibility) |
| 766 | except ValueError: |
| 767 | params['Script'] = None |
| 768 | massage = f'Cannot find Script: "{title}"' |
| 769 | print(massage) |
| 770 | gr.Warning(massage) |
| 771 | return gr.update(visible=False) |
| 772 | |
| 773 | self.infotext_fields.append((dropdown, lambda x: gr.update(value=x.get('Script', 'None')))) |
| 774 | self.infotext_fields.extend([(script.group, onload_script_visibility) for script in self.selectable_scripts]) |
| 775 | |
| 776 | self.apply_on_before_component_callbacks() |
| 777 |
no test coverage detected