-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_helper.py
71 lines (63 loc) · 2.28 KB
/
config_helper.py
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
# SPDX-FileCopyrightText: 2025 Meinhard Kissich
# SPDX-License-Identifier: MIT
import streamlit as st
from config_io import ConfigIO
class ConfigHelper:
@classmethod
def update_config(cls, key, func = lambda x: x):
s, k = key.split("/")[0], key.split("/")[1]
st.session_state["config"][s][k] = str(func(st.session_state[key]))
ConfigIO.store_config()
@staticmethod
def make_sliders(ctx_lists):
for s in ctx_lists:
st.slider(
label=s.label,
min_value=s.min,
max_value=s.max,
value=s.type(st.session_state["config"][s.section][s.key]),
key=f"{s.section}/{s.key}",
on_change=ConfigHelper.update_config,
args=[f"{s.section}/{s.key}"]
)
@staticmethod
def make_checkboxes(ctx_list):
for s in ctx_list:
st.toggle(
label=s.label,
value=bool(st.session_state["config"][s.section][s.key]),
key=f"{s.section}/{s.key}",
on_change=ConfigHelper.update_config,
args=[f"{s.section}/{s.key}"]
)
@staticmethod
def make_selectboxes(ctx_lists):
for s in ctx_lists:
st.selectbox(
label=s.label,
index=s.options.index(st.session_state["config"][s.section][s.key]),
key=f"{s.section}/{s.key}",
options=s.options,
on_change=ConfigHelper.update_config,
args=[f"{s.section}/{s.key}"]
)
@staticmethod
def make_text_inputs(ctx_list):
for s in ctx_list:
st.text_input(
label=s.label,
value=st.session_state["config"][s.section][s.key],
key=f"{s.section}/{s.key}",
on_change=ConfigHelper.update_config,
args=[f"{s.section}/{s.key}"]
)
@staticmethod
def make_text_ares(ctx_list):
for s in ctx_list:
st.text_area(
label=s.label,
value=st.session_state["config"][s.section][s.key],
key=f"{s.section}/{s.key}",
on_change=ConfigHelper.update_config,
args=[f"{s.section}/{s.key}"]
)