File size: 3,946 Bytes
2b0bc5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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 <a href="https://github.com/lllyasviel/stable-diffusion-webui-forge">Forge</a>')
        .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)