from modules.script_callbacks import on_ui_settings, on_before_ui from modules.shared import opts, OptionInfo def add_ui_settings(): from gradio import Slider args = {"section": ("ui_tabs_ex", "Tabs Extension"), "category_id": "ui"} opts.add_option( "tabs_ex_delay", OptionInfo( 50, "Delay (ms) before moving the Extensions", Slider, {"minimum": 0, "maximum": 500, "step": 25}, **args, ).needs_reload_ui(), ) opts.add_option( "tabs_ex_act_color", OptionInfo( "greenyellow", "Color for active Extensions", **args, ) .link("CSS", "https://www.w3schools.com/cssref/css_colors.php") .needs_reload_ui(), ) opts.add_option( "tabs_ex_version", OptionInfo( False, "Hide the version number", **args, ).needs_reload_ui(), ) opts.add_option( "tabs_ex_forge", OptionInfo( False, 'Hide the "Integrated" text', **args, ) .info('for Forge') .needs_reload_ui(), ) opts.add_option( "tabs_ex_sort", OptionInfo( False, "Sort Extensions based on Configs", **args, ).needs_reload_ui(), ) opts.add_option( "tabs_ex_toggle", OptionInfo( False, "Allow hiding the extension content when clicking on the same tab button again", **args, ).needs_reload_ui(), ) opts.add_option( "tabs_ex_scripts_toggle", OptionInfo( False, "Allow Ctrl + Click to toggle the Scripts dropdown as well", **args, ).needs_reload_ui(), ) opts.add_option( "tabs_ex_rmb", OptionInfo( False, "Use Right Click instead of Ctrl + Click for toggling Extensions", **args, ).needs_reload_ui(), ) opts.add_option( "tabs_ex_open", OptionInfo( True, "Automatically show the first extension tab on startup", **args, ).needs_reload_ui(), ) opts.add_option( "tabs_ex_container", OptionInfo( False, "Hide the Extension container", **args, ) .info("In certain configurations, the original Extension container will show up as an empty space in the Webui. You can enable this to hide the container") .needs_reload_ui(), ) def load_ui_settings(): import os color = getattr(opts, "tabs_ex_act_color", "greenyellow").strip().lower() css_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "style.css") if not os.path.isfile(css_path): # Создаём минимальный файл с нужной переменной with open(css_path, "w", encoding="utf-8") as f: f.write("body {\n --tabs-highlight-color: %s;\n}\n" % color) return with open(css_path, "r", encoding="utf-8", errors="ignore") as f: lines = f.readlines() key = "--tabs-highlight-color:" idx = next((i for i, line in enumerate(lines) if key in line), None) if idx is not None: prefix = lines[idx].split(":")[0] lines[idx] = f"{prefix}: {color};\n" else: # Если строки нет — добавляем под body либо в конец insert_at = len(lines) for i, line in enumerate(lines): if line.strip().startswith("body"): insert_at = i + 1 break lines.insert(insert_at, f" --tabs-highlight-color: {color};\n") with open(css_path, "w", encoding="utf-8") as f: f.writelines(lines)