streamlit-toggle-diy 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- streamlit_toggle_diy/__init__.py +140 -0
- streamlit_toggle_diy-1.0.1.dist-info/LICENSE +19 -0
- streamlit_toggle_diy-1.0.1.dist-info/METADATA +10 -0
- streamlit_toggle_diy-1.0.1.dist-info/RECORD +6 -0
- streamlit_toggle_diy-1.0.1.dist-info/WHEEL +5 -0
- streamlit_toggle_diy-1.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,140 @@
|
|
1
|
+
import os
|
2
|
+
import streamlit.components.v1 as components
|
3
|
+
import streamlit as st
|
4
|
+
|
5
|
+
_RELEASE = True
|
6
|
+
|
7
|
+
if not _RELEASE:
|
8
|
+
_component_func = components.declare_component(
|
9
|
+
"streamlit_toggle_diy",
|
10
|
+
url="http://localhost:3001",
|
11
|
+
)
|
12
|
+
else:
|
13
|
+
parent_dir = os.path.dirname(os.path.abspath(__file__))
|
14
|
+
build_dir = os.path.join(parent_dir, "frontend/build")
|
15
|
+
_component_func = components.declare_component("streamlit_toggle_diy", path=build_dir)
|
16
|
+
|
17
|
+
|
18
|
+
def st_toggle_switch(
|
19
|
+
label=None,
|
20
|
+
key=None,
|
21
|
+
default_value=False,
|
22
|
+
label_after=False,
|
23
|
+
inactive_color='#D3D3D3',
|
24
|
+
active_color="#11567f",
|
25
|
+
track_color="#29B5E8",
|
26
|
+
label_bg_color_start=None, # 新增参数
|
27
|
+
label_bg_color_end=None, # 新增参数
|
28
|
+
background_color_near_button_start=None, # 新增参数
|
29
|
+
background_color_near_button_end=None # 新增参数
|
30
|
+
):
|
31
|
+
if label_after:
|
32
|
+
label_end = label
|
33
|
+
label_start = ''
|
34
|
+
justify = 'flex-start'
|
35
|
+
else:
|
36
|
+
label_start = label
|
37
|
+
label_end = ''
|
38
|
+
justify = 'flex-start'
|
39
|
+
# justify = 'flex-end'
|
40
|
+
|
41
|
+
toggle_value = _component_func(
|
42
|
+
key=key,
|
43
|
+
default_value=default_value,
|
44
|
+
label_after=label_after,
|
45
|
+
label_start=label_start,
|
46
|
+
label_end=label_end,
|
47
|
+
justify=justify,
|
48
|
+
inactive_color=inactive_color,
|
49
|
+
active_color=active_color,
|
50
|
+
track_color=track_color,
|
51
|
+
label_bg_color_start=label_bg_color_start, # 传递新增参数
|
52
|
+
label_bg_color_end=label_bg_color_end, # 传递新增参数
|
53
|
+
background_color_near_button_start=background_color_near_button_start, # 传递新增参数
|
54
|
+
background_color_near_button_end=background_color_near_button_end # 传递新增参数
|
55
|
+
)
|
56
|
+
return toggle_value if toggle_value is not None else default_value
|
57
|
+
|
58
|
+
|
59
|
+
if not _RELEASE:
|
60
|
+
st.header('Streamlit Toggle Switch')
|
61
|
+
st.write('---')
|
62
|
+
|
63
|
+
# 使用 color_picker 选择颜色
|
64
|
+
color1_start = st.color_picker('选择 Question 1 标签起始背景颜色', '#FFD700')
|
65
|
+
color1_end = st.color_picker('选择 Question 1 标签结束背景颜色', '#FF8C00')
|
66
|
+
|
67
|
+
color2_start = st.color_picker('选择 Question 2 标签起始背景颜色', '#ADFF2F')
|
68
|
+
color2_end = st.color_picker('选择 Question 2 标签结束背景颜色', '#32CD32')
|
69
|
+
|
70
|
+
color3_start = st.color_picker('选择 Question 3 标签起始背景颜色', '#1E90FF')
|
71
|
+
color3_end = st.color_picker('选择 Question 3 标签结束背景颜色', '#0000FF')
|
72
|
+
|
73
|
+
color4_start = st.color_picker('选择 Question 4 标签起始背景颜色', '#FF69B4')
|
74
|
+
color4_end = st.color_picker('选择 Question 4 标签结束背景颜色', '#FF1493')
|
75
|
+
|
76
|
+
color5_start = st.color_picker('选择 Disable Filter 标签起始背景颜色', '#00FA9A')
|
77
|
+
color5_end = st.color_picker('选择 Disable Filter 标签结束背景颜色', '#00FF7F')
|
78
|
+
|
79
|
+
# 新增颜色选择器用于按钮附近的背景颜色
|
80
|
+
button_bg_start = st.color_picker('选择按钮附近的起始背景颜色', '#FFFFFF')
|
81
|
+
button_bg_end = st.color_picker('选择按钮附近的结束背景颜色', '#FFFFFF')
|
82
|
+
|
83
|
+
columns = st.columns(3)
|
84
|
+
with columns[0]:
|
85
|
+
st_toggle_switch(
|
86
|
+
label="Question 1",
|
87
|
+
key='c1',
|
88
|
+
label_after=False,
|
89
|
+
label_bg_color_start=color1_start,
|
90
|
+
label_bg_color_end=color1_end,
|
91
|
+
background_color_near_button_start=button_bg_start, # 传递新增参数
|
92
|
+
background_color_near_button_end=button_bg_end # 传递新增参数
|
93
|
+
)
|
94
|
+
st_toggle_switch(
|
95
|
+
label="Question 2",
|
96
|
+
key='c2',
|
97
|
+
label_after=False,
|
98
|
+
label_bg_color_start=color2_start,
|
99
|
+
label_bg_color_end=color2_end,
|
100
|
+
background_color_near_button_start=button_bg_start,
|
101
|
+
background_color_near_button_end=button_bg_end
|
102
|
+
)
|
103
|
+
with columns[1]:
|
104
|
+
st_toggle_switch(
|
105
|
+
label="Question 3",
|
106
|
+
key='q2',
|
107
|
+
label_after=True,
|
108
|
+
default_value=True,
|
109
|
+
label_bg_color_start=color3_start,
|
110
|
+
label_bg_color_end=color3_end,
|
111
|
+
background_color_near_button_start=button_bg_start,
|
112
|
+
background_color_near_button_end=button_bg_end
|
113
|
+
)
|
114
|
+
st_toggle_switch(
|
115
|
+
label="Question 4",
|
116
|
+
key='q3',
|
117
|
+
label_after=True,
|
118
|
+
default_value=True,
|
119
|
+
label_bg_color_start=color4_start,
|
120
|
+
label_bg_color_end=color4_end,
|
121
|
+
background_color_near_button_start=button_bg_start,
|
122
|
+
background_color_near_button_end=button_bg_end
|
123
|
+
)
|
124
|
+
with columns[2]:
|
125
|
+
range_slider_toggle = st_toggle_switch(
|
126
|
+
"Disable Filter",
|
127
|
+
key='q1',
|
128
|
+
label_after=False,
|
129
|
+
default_value=True,
|
130
|
+
label_bg_color_start=color5_start,
|
131
|
+
label_bg_color_end=color5_end,
|
132
|
+
background_color_near_button_start=button_bg_start,
|
133
|
+
background_color_near_button_end=button_bg_end
|
134
|
+
)
|
135
|
+
range_slider = st.slider(
|
136
|
+
label="Filter Range",
|
137
|
+
min_value=0,
|
138
|
+
max_value=100,
|
139
|
+
disabled=range_slider_toggle
|
140
|
+
)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2022 Carlos D. Serrano
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: streamlit_toggle_diy
|
3
|
+
Version: 1.0.1
|
4
|
+
Summary: Creates a customizable toggle, and you can switch the background color of label
|
5
|
+
Home-page: https://github.com/sqlinsights/streamlit-toggle-switch
|
6
|
+
Author: Flow_Water
|
7
|
+
Author-email: 1665526933@qq.com
|
8
|
+
Requires-Python: >=3.6
|
9
|
+
License-File: LICENSE
|
10
|
+
Requires-Dist: streamlit>=0.63
|
@@ -0,0 +1,6 @@
|
|
1
|
+
streamlit_toggle_diy/__init__.py,sha256=AGRjNeZsgLF4783MjB7feh-FBzcczvz_yozCyZSbuME,5237
|
2
|
+
streamlit_toggle_diy-1.0.1.dist-info/LICENSE,sha256=NjPmumOMFSp_Jkk0GC961Ie0-R4mbAV6POCovLzRQJk,1061
|
3
|
+
streamlit_toggle_diy-1.0.1.dist-info/METADATA,sha256=-GUgPeZ_K1pi_afw2Z7RlgfEloKrAwGLNPEO_dOWc6c,356
|
4
|
+
streamlit_toggle_diy-1.0.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
5
|
+
streamlit_toggle_diy-1.0.1.dist-info/top_level.txt,sha256=nFI-mEsztmjsHXlvV0MpfzhT-2ovmY270y2Ulm--D3I,21
|
6
|
+
streamlit_toggle_diy-1.0.1.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
streamlit_toggle_diy
|