test2023h5 commited on
Commit
b5e36f9
·
verified ·
1 Parent(s): bb1270e

Upload 43 files

Browse files
Files changed (43) hide show
  1. locales/zh/app.py +40 -0
  2. locales/zh/pages/002 Form Component/demo_button.py +141 -0
  3. locales/zh/pages/002 Form Component/demo_checkbox.py +76 -0
  4. locales/zh/pages/002 Form Component/demo_dialog.py +78 -0
  5. locales/zh/pages/002 Form Component/demo_expander.py +30 -0
  6. locales/zh/pages/002 Form Component/demo_menu.py +100 -0
  7. locales/zh/pages/002 Form Component/demo_radio.py +93 -0
  8. locales/zh/pages/002 Form Component/demo_selectbox.py +77 -0
  9. locales/zh/pages/002 Form Component/demo_slider.py +35 -0
  10. locales/zh/pages/002 Form Component/demo_textarea.py +46 -0
  11. locales/zh/pages/002 Form Component/demo_textinput.py +64 -0
  12. locales/zh/pages/002 Form Component/demo_upload.py +42 -0
  13. locales/zh/pages/002 Form Component/folder.json +1 -0
  14. locales/zh/pages/003 Content Display/demo_audio.py +39 -0
  15. locales/zh/pages/003 Content Display/demo_html.py +49 -0
  16. locales/zh/pages/003 Content Display/demo_image.py +92 -0
  17. locales/zh/pages/003 Content Display/demo_markdown.py +57 -0
  18. locales/zh/pages/003 Content Display/demo_message.py +37 -0
  19. locales/zh/pages/003 Content Display/demo_sqlite.py +39 -0
  20. locales/zh/pages/003 Content Display/demo_table.py +252 -0
  21. locales/zh/pages/003 Content Display/demo_text.py +35 -0
  22. locales/zh/pages/003 Content Display/demo_video.py +36 -0
  23. locales/zh/pages/003 Content Display/demo_write.py +78 -0
  24. locales/zh/pages/003 Content Display/folder.json +1 -0
  25. locales/zh/pages/004 Chart Data/demo_bokeh.py +128 -0
  26. locales/zh/pages/004 Chart Data/demo_pyplot.py +133 -0
  27. locales/zh/pages/004 Chart Data/folder.json +1 -0
  28. locales/zh/pages/005 Layout Related/demo_columns.py +100 -0
  29. locales/zh/pages/005 Layout Related/demo_row.py +102 -0
  30. locales/zh/pages/005 Layout Related/demo_section.py +81 -0
  31. locales/zh/pages/005 Layout Related/demo_sidebar.py +53 -0
  32. locales/zh/pages/005 Layout Related/demo_style.py +68 -0
  33. locales/zh/pages/005 Layout Related/demo_tabs.py +35 -0
  34. locales/zh/pages/005 Layout Related/folder.json +1 -0
  35. locales/zh/pages/006 Advanced Usage/demo_component.py +101 -0
  36. locales/zh/pages/006 Advanced Usage/demo_loadvue.py +132 -0
  37. locales/zh/pages/006 Advanced Usage/demo_onload.py +46 -0
  38. locales/zh/pages/006 Advanced Usage/demo_session.py +22 -0
  39. locales/zh/pages/006 Advanced Usage/demo_template.py +133 -0
  40. locales/zh/pages/006 Advanced Usage/demo_when.py +101 -0
  41. locales/zh/pages/006 Advanced Usage/folder.json +1 -0
  42. locales/zh/system/.ipynb_checkpoints/config-checkpoint.yaml +16 -0
  43. locales/zh/system/config.yaml +16 -0
locales/zh/app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### SimpleStart 简介
2
+ import simplestart as ss
3
+
4
+ ss.md("## SimpleStart 介绍")
5
+
6
+
7
+ ss.space()
8
+ ss.md('''
9
+ ### 无需前端编程的 Python 网页开发工具
10
+ SimpleStart 是一款无需前端网页编程的工具,所有开发工作都通过 Python 在后台完成。即使不精通 HTML、CSS、JavaScript、Ajax 等知识,也能轻松开发网页应用。
11
+
12
+ ''')
13
+
14
+ ss.space()
15
+
16
+ ss.md('''
17
+ ### 提供丰富的组件
18
+ SimpleStart 提供包括文本、按钮、列表、表格、音频、视频等在内的多种网页开发所需组件,支持容器和布局,同时允许用户自定义组件。
19
+
20
+ ''')
21
+
22
+ ss.space()
23
+
24
+ ss.md('''
25
+ ### 提供数据可视化支持
26
+ SimpleStart 通过图像、表格、Plot 图表和 SQLite 数据库等方式实现数据可视化。它支持静态和交互式图表的显示,并提供数据的显示和编辑功能。
27
+ ''')
28
+
29
+ ss.space()
30
+ ss.md("---")
31
+ ss.write("关于安装使用等,请访问")
32
+ ss.md('''
33
+ [在线帮助](http://www.simplestart.cc)
34
+ ''')
35
+
36
+ def locale():
37
+ ss.send_message("change_locale", {"locale":""});
38
+
39
+
40
+ ss.button("English", onclick = locale)
locales/zh/pages/002 Form Component/demo_button.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Button 按钮
2
+ import simplestart as ss
3
+
4
+ ss.md('''
5
+ ## ss.button 按钮
6
+ ''')
7
+ ss.md('''
8
+ [在线帮助](https://www.simplestart.cc/zh/doc_form/ss-button.html)
9
+ ''')
10
+ ss.space()
11
+ ss.md('''
12
+ #### 🔅 示例
13
+ ''')
14
+
15
+ #自定义函数
16
+ def myclick():
17
+ mytext.text = "You clicked "
18
+
19
+ def reset():
20
+ mytext.text = "This is button"
21
+ but1.type = ""
22
+ ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
23
+ ss.getcm().components[but1.id]["content"]["options"]["endicon"] = ""
24
+ ss.getcm().components[but1.id]["content"]["options"]["icon_color"] = "mediumseagreen"
25
+ ss.getcm().components[but1.id]["content"]["options"]["style"] = "background-color:initial;color:initial"
26
+ ss.session["iconstr"] = ''
27
+ ss.session["style_str"] = ''
28
+ ss.session["style"] = ''
29
+
30
+
31
+ #基本用法
32
+ cols = ss.columns([40,"flex:60"], design=True)
33
+ with cols[0]:
34
+ mytext = ss.text("This is button")
35
+ but1 = ss.button("Click it", icon = "mdi-account-circle", onclick=myclick)
36
+
37
+ def onradiochange(event):
38
+ value = event.value
39
+ if value == "default":
40
+ but1.type = ""
41
+ ss.session["buttonstyle"] = ""
42
+ elif value == "outlined":
43
+ but1.type = "outlined"
44
+ ss.session["buttonstyle"] = 'type = "outlined\",'
45
+ elif value == "flat":
46
+ but1.type = "tonal"
47
+ ss.session["buttonstyle"] = 'type = "flat\",'
48
+ elif value == "text":
49
+ but1.type = "text"
50
+ ss.session["buttonstyle"] = 'type = "text\",'
51
+ elif value == "plain":
52
+ but1.type = "plain"
53
+ ss.session["buttonstyle"] = 'type = "plain\",'
54
+
55
+ def oncheckbox_change(state, value):
56
+ if value == True:
57
+ ss.getcm().components[but1.id]["content"]["options"]["icon"] = "aim"
58
+ ss.session["iconstr"] = ' icon="search",'
59
+ else:
60
+ ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
61
+ ss.session["iconstr"] = ''
62
+ but1.update()
63
+
64
+ def onradiochange2(event):
65
+ index = event.index
66
+
67
+ if index == 0:
68
+ ss.getcm().components[but1.id]["content"]["options"]["icon"] = "mdi-account-circle"
69
+ ss.getcm().components[but1.id]["content"]["options"]["endIcon"] = ""
70
+ ss.session["iconstr"] = ' icon="mdi-account-circle",'
71
+ elif index == 1:
72
+ ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
73
+ ss.getcm().components[but1.id]["content"]["options"]["endIcon"] = "mdi-alert"
74
+ ss.session["iconstr"] = ' endIcon="mdi-alert",'
75
+ else:
76
+ ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
77
+ ss.getcm().components[but1.id]["content"]["options"]["endIcon"] = ""
78
+ ss.session["iconstr"] = ''
79
+ but1.update()
80
+
81
+
82
+ def changeColor(bkcolor):
83
+ ss.getcm().components[but1.id]["content"]["options"]["style"] = f"background-color:{bkcolor}; color:white"
84
+ ss.getcm().components[but1.id]["content"]["options"]["icon_color"] = "white"
85
+ ss.session["style_str"] = f'style="background-color:{bkcolor}, color:white"'
86
+ ss.session["style"] = 'style=style,'
87
+ but1.update()
88
+
89
+
90
+ with cols[1]:
91
+ ss.text("测试")
92
+
93
+ ss.write("---")
94
+ ss.radio(["default", "outlined", "flat", "text", "plain"], "default", inline = True, onchange=onradiochange)
95
+
96
+ ss.write("---")
97
+ ss.radio([(1, "图标(前)"), (2, "图标(后)"), (3, "图标按钮")], inline = True, onchange=onradiochange2)
98
+
99
+
100
+ ss.write("---")
101
+ ss.button("", type = "flat", size = "small", style="background-color:#409eff", onclick=lambda:changeColor('#409eff'))
102
+ ss.button("", type = "flat", size = "small", style="background-color:#67c23a", onclick=lambda:changeColor('#67c23a'))
103
+ ss.button("", type = "flat", size = "small", style="background-color:#e6a23c", onclick=lambda:changeColor('#e6a23c'))
104
+ ss.button("", type = "flat", size = "small", style="background-color:#f56c6c", onclick=lambda:changeColor('#f56c6c'))
105
+ ss.button("", type = "flat", size = "small", style="background-color:#909399", onclick=lambda:changeColor('#909399'))
106
+
107
+
108
+ ss.space()
109
+ ss.button("重置", onclick=reset)
110
+
111
+
112
+ ss.space("mt-8")
113
+
114
+ ss.write("#### 🔎 代码")
115
+
116
+ ss.md('''
117
+ ```python
118
+ import simplestart as ss
119
+
120
+ def clickme():
121
+ mytext.text = "You clicked"
122
+
123
+ mytext = ss.text("This is button")
124
+ @style_str
125
+ ss.button("Click it", @buttonstyle @iconstr @style onclick=clickme)
126
+ ```
127
+ ''')
128
+
129
+ ss.md('''
130
+ ::: tip
131
+ 函数调用
132
+ ss.button(label, type, color, size, icon, onclick)
133
+ :::
134
+ ''')
135
+
136
+ def onPageLoad():
137
+ ss.session["buttonstyle"] = ""
138
+ ss.session["iconstr"] = ""
139
+ ss.session["style"] = ""
140
+ ss.session["style_str"] = ""
141
+
locales/zh/pages/002 Form Component/demo_checkbox.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Checkbox 多选框
2
+ import simplestart as ss
3
+
4
+ ss.write("### ss.checkbox")
5
+
6
+ def onchange(event):
7
+ ss.session["checked_value"] = event.value
8
+
9
+
10
+ ss.md('''
11
+ ---
12
+ #### 🔅 示例1
13
+ ''')
14
+
15
+ ss.md("onchange: @checked_value")
16
+
17
+ ss.checkbox("checkme", onchange = onchange)
18
+ ss.checkbox("initially checked", checked = True, onchange = onchange)
19
+
20
+
21
+ ss.write('''
22
+ ---
23
+ #### 🔎 代码
24
+ ''')
25
+
26
+ ss.md('''
27
+ ```python
28
+ import simplestart as ss
29
+
30
+ def onchange(state, value):
31
+ state["checked_value"] = value
32
+
33
+ #ui
34
+ ss.md("onchange: @checked_value")
35
+
36
+ ss.checkbox("checkme", onchange = onchange)
37
+ ss.checkbox("initially checked", checked = True, onchange = onchange)
38
+
39
+
40
+ ''')
41
+
42
+ ss.space()
43
+ ss.md('''
44
+ ---
45
+ #### 🔅 示例2
46
+ 获取 checkbox 的状态
47
+ ''')
48
+
49
+ mycheck = ss.checkbox("check me", onchange = onchange)
50
+
51
+ def myclick():
52
+ ss.message(mycheck.value)
53
+
54
+ ss.button("获取状态", onclick = myclick)
55
+
56
+ ss.space()
57
+ ss.write('''
58
+ ---
59
+ #### 🔎 代码
60
+ ''')
61
+
62
+ ss.md('''
63
+ ```python
64
+ import simplestart as ss
65
+
66
+ mycheck = ss.checkbox("check me", onchange = onchange)
67
+
68
+ def myclick():
69
+ ss.message(mycheck.value)
70
+
71
+ ss.button("获取状态", onclick = myclick)
72
+
73
+ ''')
74
+
75
+ def onPageLoad():
76
+ ss.session["checked_value"] = ""
locales/zh/pages/002 Form Component/demo_dialog.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Dialog 对话框
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.dialog 对话框")
5
+
6
+ ss.space()
7
+
8
+ ss.md('''
9
+ ---
10
+ #### 🔅 示例
11
+ ''')
12
+
13
+ def testme():
14
+ ss.message("testme")
15
+
16
+ def showit():
17
+ if ss.session["str_fullscreen"] != "":
18
+ dialog.show(fullscreen = True)
19
+ else:
20
+ dialog.show()
21
+
22
+ def myclose(event):
23
+ ss.message("dialog close with result " + event.value)
24
+
25
+ dialog = ss.dialog("对话框标题", onclose=myclose)
26
+ with dialog:
27
+ ss.text("SimpleStart dialog demostration")
28
+ ss.md("---")
29
+ ss.button("testme", onclick=testme)
30
+ ss.md(":smile:")
31
+
32
+ cols = ss.columns([60,"flex:40; border-left:1px solid lightgray"], border=True, style="border:1px solid lightgray")
33
+ with cols[0]:
34
+ mytext = ss.text("This is dialog")
35
+ ss.button("show dialog", onclick=showit)
36
+
37
+ def mycheck(event):
38
+ if event.value == True:
39
+ ss.session["str_fullscreen"] = "fullscreen = True"
40
+ #dialog.show(fullscreen = True)
41
+ else:
42
+ ss.session["str_fullscreen"] = ""
43
+
44
+ with cols[1]:
45
+ ss.text("对话框选项")
46
+ ss.checkbox("全屏", onchange=mycheck)
47
+
48
+ ss.space()
49
+ ss.write('''
50
+ ---
51
+ #### 🔎 代码
52
+ ''')
53
+
54
+ ss.md('''
55
+ ```python
56
+ import simplestart as ss
57
+
58
+ def myclose(event):
59
+ ss.message("dialog close with result " + event.value)
60
+
61
+ dialog = ss.dialog(title="对话框标题", onclose=myclose)
62
+ with dialog:
63
+ ss.text("Opening from the bottom")
64
+ ss.md("---")
65
+ ss.button("testme", onclick=testme)
66
+ ss.md(":smile:")
67
+
68
+ def showit():
69
+ dialog.show(@str_fullscreen)
70
+
71
+ ss.button("show dialog", onclick=showit)
72
+ ```
73
+ ''')
74
+
75
+ def onPageEnter():
76
+ ss.session["str_fullscreen"] = ""
77
+
78
+
locales/zh/pages/002 Form Component/demo_expander.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Expander 下拉展开控件
2
+ import streamsync as ss
3
+
4
+ ss.md("## ss.expander 下拉展开")
5
+
6
+
7
+ ss.md('''
8
+ #### 🔅 示例
9
+ ''')
10
+
11
+ with ss.expander("关于SimpleStart", expanded = True):
12
+ ss.text("Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi, ratione debitis quis est labore voluptatibus! \
13
+ Eaque cupiditate minima, at placeat totam, magni doloremque veniam neque porro libero rerum unde voluptatem!", style="padding:10px")
14
+
15
+
16
+ ss.space()
17
+ ss.write('''
18
+ ---
19
+ #### 🔎 代码
20
+ ''')
21
+
22
+ ss.md('''
23
+ ```python
24
+ import simplestart as ss
25
+
26
+ with ss.expander("关于SimpleStart"):
27
+ ss.text("Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi, ratione debitis quis est labore voluptatibus! \
28
+ Eaque cupiditate minima, at placeat totam, magni doloremque veniam neque porro libero rerum unde voluptatem!")
29
+ ```
30
+ ''')
locales/zh/pages/002 Form Component/demo_menu.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Menu 菜单
2
+ import streamsync as ss
3
+
4
+ ss.md("## ss.menu")
5
+
6
+ ss.md('''
7
+ #### 🔅 示例
8
+ ''')
9
+
10
+ data = [
11
+ {'index': '1', 'title': 'Processing Center', 'icon':'mdi-home'},
12
+ {'type': 'spacer'}, #add spacer
13
+ {
14
+ 'index': '2',
15
+ 'title': 'Workspace',
16
+ 'icon' : 'mdi-plus',
17
+ 'subItems': [
18
+ {'index': '2-1', 'title': 'item one'},
19
+ {'index': '2-2', 'title': 'item two'},
20
+ {'index': '2-3', 'title': 'item three'},
21
+ {
22
+ 'index': '2-4',
23
+ 'title': 'item four',
24
+ 'subItems': [
25
+ {'index': '2-4-1', 'title': 'item one'},
26
+ {'index': '2-4-2', 'title': 'item two'},
27
+ {'index': '2-4-3', 'title': 'item three'},
28
+ ],
29
+ },
30
+ ],
31
+ },
32
+ {'index': '3', 'title': 'Info', 'disabled': True, 'icon':'mdi-cancel'},
33
+ {'index': '4', 'title': 'Orders', 'icon':'mdi-wrench'},
34
+ ]
35
+
36
+ def menu_select(event):
37
+ print("menu1")
38
+ ss.message(event.data["keyPath"])
39
+
40
+
41
+ ss.md("### 顶栏菜单")
42
+ ss.menu(data, direction = "horizontal", onselect = menu_select)
43
+
44
+ ss.space()
45
+ ss.md("### 侧栏菜单")
46
+
47
+ ss.menu(data, direction = "vertical", dark = True, onselect = menu_select)
48
+
49
+
50
+ ss.space()
51
+ ss.write('''
52
+ ---
53
+ #### 🔎 代码
54
+ ''')
55
+
56
+ ss.md('''
57
+ ```python
58
+ import simplestart as ss
59
+
60
+ data = [
61
+ {'index': '1', 'title': 'Processing Center', 'icon':'mdi-home'},
62
+ {'type': 'spacer'}, #add spacer
63
+ {
64
+ 'index': '2',
65
+ 'title': 'Workspace',
66
+ 'icon' : 'mdi-plus',
67
+ 'subItems': [
68
+ {'index': '2-1', 'title': 'item one'},
69
+ {'index': '2-2', 'title': 'item two'},
70
+ {'index': '2-3', 'title': 'item three'},
71
+ {
72
+ 'index': '2-4',
73
+ 'title': 'item four',
74
+ 'subItems': [
75
+ {'index': '2-4-1', 'title': 'item one'},
76
+ {'index': '2-4-2', 'title': 'item two'},
77
+ {'index': '2-4-3', 'title': 'item three'},
78
+ ],
79
+ },
80
+ ],
81
+ },
82
+ {'index': '3', 'title': 'Info', 'disabled': True, 'icon':'mdi-cancel'},
83
+ {'index': '4', 'title': 'Orders', 'icon':'mdi-wrench'},
84
+ ]
85
+
86
+ def menu_select(event):
87
+ print("menu1")
88
+ ss.message(event.data["keyPath"])
89
+
90
+
91
+ ss.md("### Horiontal Menu")
92
+ ss.menu(data, direction = "horizontal", onselect = menu_select)
93
+
94
+ ss.space()
95
+ ss.md("### Vertical Menu")
96
+
97
+ ss.menu(data, direction = "vertical", dark = True, onselect = menu_select)
98
+
99
+ ```
100
+ ''')
locales/zh/pages/002 Form Component/demo_radio.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Radio 单选框
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.radio 单选框")
5
+
6
+ ss.space()
7
+
8
+ ss.md('''
9
+ #### 🔅 示例
10
+ ''')
11
+
12
+ def onchange(event):
13
+ ss.session["options_value"] = event.value
14
+ ss.session["options_index"] = event.index
15
+
16
+ ss.md("onchange: value:@options_value, index:@options_index")
17
+
18
+ options = ["Option 1", "Option 2", "Option 3"]
19
+ myradio = ss.radio(options, label = "### my radio1", index = 0, onchange = onchange)
20
+
21
+
22
+ options = [("C++", '#### <span style="color:blue">C++</span>'),
23
+ ("Javascript", '#### <span style="color:green">Javascript</span>'),
24
+ ("Python", '#### <span style="color:red">Python</span>')
25
+ ]
26
+ ss.radio(options, inline = True, label = "### my radio2", index = 0, iconColor = "blue", onchange = onchange)
27
+
28
+
29
+
30
+ ss.write("---")
31
+ ss.write("#### 🔎 代码")
32
+
33
+ ss.md('''
34
+ ```python
35
+ import simplestart as ss
36
+
37
+ def onchange(event):
38
+ ss.session["options_value"] = event.value
39
+ ss.session["options_index"] = event.index
40
+
41
+ ss.md("onchange: value:\@options_value, index:\@options_index")
42
+
43
+ options = ["Option 1", "Option 2", "Option 3"]
44
+ myradio = ss.radio(options, label = "### my radio1", index = 0, onchange = onchange)
45
+
46
+
47
+ options = [("C++", '#### <span style="color:blue">C++</span>'),
48
+ ("Javascript", '#### <span style="color:green">Javascript</span>'),
49
+ ("Python", '#### <span style="color:red">Python</span>')
50
+ ]
51
+ ss.radio(options, inline = True, label = "### my radio2", index = 0, iconColor = "blue", onchange = onchange)
52
+
53
+ def onPageLoad():
54
+ ss.session["options_value"] = ""
55
+
56
+ ''')
57
+
58
+
59
+ ss.space()
60
+ ss.md('''
61
+ ---
62
+ #### 🔅 示例 - 获取状态值
63
+ ''')
64
+
65
+ def myclick1():
66
+ ss.message(myradio.value)
67
+
68
+ ss.button("获取状态值", onclick = myclick1)
69
+
70
+ def myclick2():
71
+ ss.message(myradio.index)
72
+
73
+ ss.button("获取状态值索引", onclick = myclick2)
74
+
75
+ ss.write("---")
76
+ ss.write("#### 🔎 代码段")
77
+
78
+ ss.md('''
79
+ ```python
80
+ #...
81
+ def myclick1():
82
+ ss.message(myradio.value)
83
+
84
+ ss.button("获取状态值", onclick = myclick1)
85
+
86
+ def myclick2():
87
+ ss.message(myradio.index)
88
+
89
+ ss.button("获取状态值索引", onclick = myclick2)
90
+ ''')
91
+
92
+ def onPageLoad():
93
+ ss.session["options_value"] = ""
locales/zh/pages/002 Form Component/demo_selectbox.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Selectbox 选择器
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.selectbox 选择器")
5
+
6
+ ss.space()
7
+ ss.md('''
8
+ #### 🔅 示例1
9
+ 在页面上创建一个带标题的,有3个选项的selectbox.
10
+ ''')
11
+ ss.space()
12
+
13
+ options = ["option1","option2", "option3"]
14
+
15
+ def selchange(event):
16
+ ss.message(f"You select {event.value}, index of {event.index}")
17
+
18
+ select1 = ss.selectbox(options, index=0, title = "### Please select", onchange = selchange)
19
+
20
+
21
+
22
+ ss.write("#### 🔎 代码")
23
+
24
+ ss.md("""
25
+ ```python
26
+ import simplestart as ss
27
+
28
+ options = ["option1","option2", "option3"]
29
+
30
+ def selchange(event):
31
+ ss.session["select_value"] = event.value
32
+ ss.session["select_index"] = select1.index
33
+
34
+ ss.write("info value: index:")
35
+ select1 = ss.selectbox(options, value="option1", onchange = selchange)
36
+
37
+
38
+ ```
39
+ """)
40
+
41
+ ss.md('''
42
+ #### 🔅 示例2
43
+ 获取selectbox当前的选项. 除了在selectbox的onchange事件里,通过event的index和value获取用户的选项信息外,还可以通过selectbox的变量获取用户的选择信息。
44
+ ''')
45
+ ss.space()
46
+
47
+ def onclick1():
48
+ ss.message(select1.value)
49
+
50
+ ss.button("当前选项值", onclick = onclick1)
51
+
52
+ def onclick2():
53
+ ss.message(select1.index)
54
+
55
+ ss.button("当前选项索引", onclick = onclick2)
56
+
57
+ ss.space()
58
+
59
+ ss.write("#### 🔎 代码段")
60
+
61
+ ss.md("""
62
+ ```python
63
+
64
+ #...
65
+
66
+ def onclick1():
67
+ ss.message(select1.value)
68
+
69
+ ss.button("当前选项值", onclick = onclick1)
70
+
71
+ def onclick2():
72
+ ss.message(select1.index)
73
+
74
+ ss.button("当前选项索引", onclick = onclick2)
75
+
76
+ ```
77
+ """)
locales/zh/pages/002 Form Component/demo_slider.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Slider 滑块
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.slider 滑块")
5
+
6
+ ss.space()
7
+
8
+ ss.md('''
9
+ #### 🔅 示例
10
+ ''')
11
+
12
+ ss.md("### Please drag the slider to change the value")
13
+
14
+ info = ss.text("number")
15
+
16
+ def onchange(event):
17
+ info.text = event.value
18
+
19
+ ss.slider("<b>my slider</b>", value = 500, min = 0, max = 1000, onchange = onchange, style="width:50%")
20
+
21
+ ss.space()
22
+
23
+ ss.write("#### 🔎 代码")
24
+
25
+ ss.md('''
26
+ ```python
27
+ import simplestart as ss
28
+
29
+ info = ss.text("number")
30
+
31
+ def onchange(state, value):
32
+ info.text = value
33
+
34
+ ss.slider(500, 0, 1000, onchange = onchange)
35
+ ''')
locales/zh/pages/002 Form Component/demo_textarea.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Textarea 文本域
2
+ import streamsync as ss
3
+
4
+ ss.md("## ss.textarea 文本域")
5
+
6
+
7
+ ss.space()
8
+ ss.md("#### 🔅 示例")
9
+
10
+ ss.md("---")
11
+
12
+ #基本用法
13
+ #test = ss.text_input("hello, world", type="textarea")
14
+ mytext = ss.textarea("hello, world")
15
+
16
+ ss.write("---")
17
+ ss.write("#### 🔎 代码")
18
+
19
+ ss.md('''
20
+ ```python
21
+ import simplestart as ss
22
+
23
+ mytext = ss.textarea("hello, world")
24
+
25
+ ''')
26
+
27
+ ss.space()
28
+ ss.md("#### 🔅 获取文本域的文本值")
29
+ ss.md("---")
30
+
31
+ def myclick():
32
+ ss.message(mytext.value)
33
+
34
+ ss.button("获取文本", onclick = myclick)
35
+
36
+ ss.write("---")
37
+ ss.write("#### 🔎 代码段")
38
+
39
+ ss.md('''
40
+ ```python
41
+ #...
42
+ def myclick():
43
+ ss.message(mytext.value)
44
+
45
+ ss.button("获取文本", onclick = myclick)
46
+ ''')
locales/zh/pages/002 Form Component/demo_textinput.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Text_input 文本
2
+ import streamsync as ss
3
+
4
+
5
+ ss.md("## ss.text_input 文本")
6
+
7
+ ss.space()
8
+ ss.md("#### 🔅 示例")
9
+
10
+ ss.md("---")
11
+ ss.space()
12
+
13
+ def onchange(state, value):
14
+ ss.message(f"onchange, {value}")
15
+
16
+ def onclear(state, value):
17
+ ss.message("onclear event happend")
18
+
19
+ def onblur(state, value):
20
+ print("onblur")
21
+ ss.message(f"onblur, {value}")
22
+
23
+ def testme():
24
+ ss.message(myinput.value)
25
+
26
+ #ui
27
+ cols = ss.columns([50,50], border = True)
28
+ with cols[0]:
29
+ myinput = ss.text_input("Hello SimpleStart", clearable=True)
30
+
31
+
32
+ def myevent(event):
33
+ if event.tag == "sel1":
34
+ myinput.variant = event.value
35
+ elif event.tag == "sel2":
36
+ myinput.type = event.value
37
+ elif event.tag == "but1":
38
+ ss.message(myinput.value)
39
+
40
+
41
+ with cols[1]:
42
+ ss.selectbox(["filled","outlined","underlined", "solo", "solo-filled", "solo-inverted"], label='#### <span style = "color:green">Change the input style</span>', \
43
+ value="solo", onchange = myevent, eventTag="sel1")
44
+
45
+ ss.selectbox(["text","time", "date", "week", "month", "password", "color"], label='#### <span style = "color:green">Change the input type</span>', \
46
+ onchange = myevent, eventTag="sel2")
47
+
48
+ ss.write('#### <span style = "color:green">获取input值</span>')
49
+ ss.button("获取文本值", onclick=myevent, eventTag="but1")
50
+
51
+
52
+ ss.write("---")
53
+ ss.write("#### 🔎 代码")
54
+
55
+ ss.md('''
56
+ ```python
57
+ import simplestart as ss
58
+
59
+ myinput = ss.text_input("Hello SimpleStart", clearable=True)
60
+
61
+ #或者
62
+ #ss.text_input("hello", type="text", variant = "filled")
63
+
64
+ ''')
locales/zh/pages/002 Form Component/demo_upload.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Upload 文件上传
2
+ import streamsync as ss
3
+ import pandas as pd
4
+
5
+ ss.write("备注:python-multipart需要安装包加入")
6
+
7
+ ss.md("## ss.upload 文件上传")
8
+
9
+
10
+ ss.space()
11
+ ss.md("#### 🔅 示例 - 上传图片")
12
+ ss.space()
13
+
14
+
15
+ def onsucess(event):
16
+ filename = event.value
17
+ path = f'{ss.baseinfo["package_path"]}/uploads/{filename}'
18
+ myimage.image = path
19
+
20
+ ss.upload("Upload Image ...", accept="image/png, image/jpeg, image/bmp", icon="mdi-camera", onsucess = onsucess)
21
+
22
+ myimage = ss.image()
23
+
24
+ ss.space()
25
+ ss.write("---")
26
+ ss.write("#### 🔎 代码")
27
+
28
+ ss.md('''
29
+ ```python
30
+ import simplestart as ss
31
+
32
+ def onsucess(event):
33
+ filename = event.value
34
+ path = f'{ss.baseinfo["package_path"]}/uploads/{filename}'
35
+
36
+ myimage.image = path
37
+
38
+ ss.upload(label = "Upload Image ...", accept="image/png, image/jpeg, image/bmp", icon="mdi-camera", onsucess = onsucess)
39
+
40
+ myimage = ss.image()
41
+
42
+ ''')
locales/zh/pages/002 Form Component/folder.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"alias":"表单组件"}
locales/zh/pages/003 Content Display/demo_audio.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Audio 音频播放
2
+ import streamsync as ss
3
+
4
+ ss.md("## ss.audio 音频播放")
5
+
6
+
7
+ ss.space()
8
+ ss.md('''
9
+ #### 🔅 示例
10
+ ''')
11
+
12
+ ss.space()
13
+
14
+ audiosrc = "media/test.wav"
15
+ player = ss.audio(audiosrc)
16
+
17
+
18
+ ss.space("mt-8")
19
+
20
+ ss.write('''
21
+ ---
22
+ #### 🔎 代码
23
+ ''')
24
+
25
+ ss.md('''
26
+ ```python
27
+ import simplestart as ss
28
+
29
+ audiosrc = "media/davide_quatela--breathing_barcelona.mp3"
30
+ player = ss.audio(audiosrc)
31
+ ```
32
+ ''')
33
+
34
+
35
+ ss.md('''
36
+ ::: tip
37
+ ss.audio 支持音频格式包括 wav, mp3 等
38
+ :::
39
+ ''')
locales/zh/pages/003 Content Display/demo_html.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Html 超文本
2
+ import streamsync as ss
3
+
4
+
5
+ ss.md("## ss.html 超文本")
6
+
7
+ ss.space("")
8
+
9
+ ss.md('''
10
+ #### 🔅 示例
11
+ ''')
12
+
13
+
14
+ ss.md("### html")
15
+
16
+ ss.html(f"""
17
+ <p>This is a piece of rich text content, which contains <strong>bold</strong> and <em>italic</em> text.</p>
18
+ <style>
19
+ .testclass{{
20
+ color:red;
21
+ font-weight:bold;
22
+ }}
23
+ </style>
24
+ <div class="testclass">this is red</div>
25
+ """)
26
+
27
+ ss.space("mt-8")
28
+
29
+ ss.write('''
30
+ ---
31
+ #### 🔎 代码
32
+ ''')
33
+
34
+ ss.md('''
35
+ ```python
36
+ import simplestart as ss
37
+
38
+ ss.html(f"""
39
+ <p>This is a piece of rich text content, which contains <strong>bold</strong> and <em>italic</em> text.</p>
40
+ <style>
41
+ .testclass{{
42
+ color:red;
43
+ font-weight:bold;
44
+ }}
45
+ </style>
46
+ <div class="testclass">this is red</div>
47
+ """)
48
+ ```
49
+ ''')
locales/zh/pages/003 Content Display/demo_image.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Image 图像
2
+ import simplestart as ss
3
+
4
+ import cv2
5
+ from PIL import Image
6
+ import os
7
+
8
+ ss.md("## ss.image 图像")
9
+
10
+ ss.md('''
11
+ #### 🔅 示例
12
+ ''')
13
+
14
+ ss.space()
15
+
16
+ style = "width:200px;height:200px;margin:10px"
17
+ img = "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
18
+
19
+ cols = ss.columns([60,"flex:40"], border=True)
20
+ with cols[0]:
21
+ mytext = ss.text("This is image")
22
+ ss.space()
23
+ myimg = ss.image(img, style=style, fit="contain")
24
+ ss.text("Image fit mode: fill")
25
+
26
+ def onradiochange(event):
27
+ #ss.message(event.value)
28
+ ss.session["fit_str"] = event.value
29
+ ss.getcm().components[myimg.id]["content"]["options"]["fit"] = event.value
30
+ myimg.update()
31
+
32
+ def onradiochange2(event):
33
+ value = event.value
34
+ index = event.index
35
+
36
+
37
+ source = ["Http", "PIL", "OpenCV", "Local"]
38
+ ss.session["source_str"] = source[index]
39
+
40
+
41
+ if index == 0:
42
+ img = "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
43
+ ss.session["image_path"] = "\"https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg\""
44
+ myimg.image = img
45
+ if index == 1:
46
+ image = Image.open('./media/image/dalao.jpeg')
47
+ ss.session["image_path"] = "Image.open('./media/image/dalao.jpeg')"
48
+ myimg.image = image
49
+ if index == 2:
50
+ img = cv2.imread('./media/image/cat.jpeg',cv2.IMREAD_COLOR)
51
+ ss.session["image_path"] = "cv2.imread('./media/image/cat.jpeg',cv2.IMREAD_COLOR)"
52
+ myimg.image = img
53
+ if index == 3:
54
+ file_path = './media/image/dog.jpeg'
55
+ ss.session["image_path"] = "'./media/image/dog.jpeg'"
56
+ myimg.image = file_path
57
+
58
+ myimg.update()
59
+
60
+
61
+ with cols[1]:
62
+ ss.text("image fit mode")
63
+ ss.radio(["fill", "contain", "cover", "none", "scale-down"], index = 1, inline = True, onchange=onradiochange)
64
+ ss.space()
65
+ ss.text("image source")
66
+ ss.radio(["Http image","PIL image", "OpenCV image", "Local image"], index = 0, inline = True, onchange=onradiochange2)
67
+
68
+ ss.space()
69
+
70
+ ss.write('''
71
+ #### 🔎 代码
72
+ ''')
73
+
74
+ ss.md('''
75
+ ```python
76
+ import simplestart as ss
77
+ import cv2
78
+ from PIL import Image
79
+
80
+ style = "width:100px; height:100px; margin:10px"
81
+ img = "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
82
+ ss.image(img, style=style, fit="fill")
83
+ ```
84
+ ''')
85
+
86
+
87
+
88
+ def onPageLoad():
89
+ ss.session["info"] = "x"
90
+ ss.session["fit_str"] = "fill"
91
+ ss.session["source_str"] = "Http"
92
+ ss.session["image_path"] = "\"https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg\""
locales/zh/pages/003 Content Display/demo_markdown.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Markdown 文本
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.markdown md文本")
5
+
6
+ ss.space()
7
+
8
+ ss.md('''
9
+ #### 🔅 示例
10
+ ''')
11
+
12
+ ss.space()
13
+
14
+ ss.markdown("- 19^th^")
15
+ ss.markdown("# 一级标题")
16
+ ss.markdown("## 二级标题")
17
+ ss.markdown("### 三级标题")
18
+
19
+ #水平分割线
20
+ ss.markdown("---")
21
+
22
+ ss.markdown('''
23
+ - list item1
24
+ - list item2
25
+ - list item3
26
+ ''')
27
+
28
+ ss.markdown(":smile:")
29
+
30
+
31
+
32
+ ss.space("mt-8")
33
+
34
+ ss.write('''
35
+ ---
36
+ #### 🔎 代码
37
+ ''')
38
+
39
+ ss.md('''
40
+ ```python
41
+ import simplestart as ss
42
+
43
+ ss.markdown("# 一级标题")
44
+ ss.markdown("## 二级标题")
45
+ ss.markdown("### 三级标题")
46
+
47
+ #水平分割线
48
+ ss.markdown("---")
49
+
50
+ ss.markdown(\'''
51
+ - list item1
52
+ - list item2
53
+ - list item3
54
+ \''')
55
+
56
+ ```
57
+ ''')
locales/zh/pages/003 Content Display/demo_message.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Message 消息提示
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.message 弹出消息")
5
+
6
+ ss.space()
7
+
8
+
9
+ ss.md('''
10
+ #### 🔅 示例
11
+ ''')
12
+ ss.space()
13
+
14
+
15
+ def showmsg():
16
+ ss.message("Hello, world")
17
+
18
+ showmsg()
19
+ ss.button("message", onclick=showmsg)
20
+
21
+
22
+ ss.space("mt-8")
23
+
24
+ ss.write('''
25
+ ---
26
+ #### 🔎 代码
27
+ ''')
28
+
29
+ ss.md('''
30
+ ```python
31
+ import simplestart as ss
32
+
33
+ def showmsg():
34
+ ss.message("Hello, the world")
35
+
36
+ ```
37
+ ''')
locales/zh/pages/003 Content Display/demo_sqlite.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Sqlite 数据库
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.sqlite 数据库")
5
+
6
+ ss.space()
7
+ ss.md('''
8
+ 提供 sqlite 数据库的简单操作
9
+ ''')
10
+
11
+ ss.space()
12
+ ss.md('''
13
+ #### 🔅 示例
14
+ ''')
15
+
16
+ ss.md('''
17
+ ::: tip
18
+ 这个例子从sqlite数据库里读取鸢尾花数据集,并以csv表格的方式展示。
19
+ 关于sqlite的管理,simplestart提供了一简单的内置工具,可以进行简单的增、删、改操作。
20
+ :::
21
+ ''')
22
+
23
+ sql = ss.sqlite("./data/ss_data.db")
24
+ df = sql.pd_query("select * from iris")
25
+
26
+ mytable = ss.table(df, editable = True)###, handlers={"current-change":current_change, "selection-change":selection_change})
27
+
28
+ ss.space()
29
+ ss.write("#### 代码")
30
+
31
+ ss.md('''
32
+ ```python
33
+ import simplestart as ss
34
+
35
+ sql = ss.sqlite("./data/ss_data.db")
36
+ data = sql.pd_query("select * from HousingData")
37
+ ss.write(data)
38
+ ```
39
+ ''')
locales/zh/pages/003 Content Display/demo_table.py ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Table 表格
2
+ import simplestart as ss
3
+ import pandas as pd
4
+
5
+ ss.md("## ss.table 表格数据")
6
+
7
+ ss.md("以表格方式显示数据")
8
+
9
+ ss.space()
10
+
11
+ ss.md('''
12
+ #### 🔅 示例
13
+ ''')
14
+
15
+ '''
16
+ 这里mytable.update会引起前端重新获取getcontent, 包括数据。真实情况不是这样,用户只能在初始时改变参数,所以不会造成频繁获取数据
17
+ '''
18
+ def onchange_index(event):
19
+ value = event.value
20
+
21
+ if value == True:
22
+ ss.getcm().components[mytable.id]["content"]["index"] = True
23
+ ss.session["showIndex"] = ', index = True'
24
+ else:
25
+ ss.getcm().components[mytable.id]["content"]["index"] = False
26
+ ss.session["showIndex"] = ''
27
+ mytable.update()
28
+
29
+ def onchange_border(event):
30
+ value = event.value
31
+
32
+ if value == True:
33
+ ss.getcm().components[mytable.id]["content"]["border"] = True
34
+ ss.session["showBorder"] = ', border = True'
35
+ else:
36
+ ss.getcm().components[mytable.id]["content"]["border"] = False
37
+ ss.session["showBorder"] = ''
38
+ mytable.update()
39
+
40
+
41
+ def onchange_sortable(event):
42
+ value = event.value
43
+
44
+ if value == True:
45
+ ss.getcm().components[mytable.id]["content"]["sortable"] = True
46
+ ss.session["sortable"] = ', sortable = True'
47
+ else:
48
+ ss.getcm().components[mytable.id]["content"]["sortable"] = False
49
+ ss.session["sortable"] = ''
50
+ mytable.update()
51
+
52
+ def onchange_searchable(event):
53
+ value = event.value
54
+
55
+ if value == True:
56
+ ss.getcm().components[mytable.id]["content"]["searchable"] = True
57
+ ss.session["searchable"] = ', searchable = True'
58
+ else:
59
+ ss.getcm().components[mytable.id]["content"]["searchable"] = False
60
+ ss.session["searchable"] = ''
61
+ mytable.update()
62
+
63
+
64
+ def onchange_selectable(event):
65
+ value = event.value
66
+
67
+ if value == True:
68
+ ss.getcm().components[mytable.id]["content"]["selectable"] = True
69
+ ss.session["selectable"] = ', selectable = True'
70
+ else:
71
+ ss.getcm().components[mytable.id]["content"]["selectable"] = False
72
+ ss.session["selectable"] = ''
73
+ mytable.update()
74
+
75
+ def onchange_editable(event):
76
+ value = event.value
77
+
78
+ if value == True:
79
+ ss.getcm().components[mytable.id]["content"]["editable"] = True
80
+ ss.session["editable"] = ', editable = True'
81
+ else:
82
+ ss.getcm().components[mytable.id]["content"]["editable"] = False
83
+ ss.session["editable"] = ''
84
+ mytable.update()
85
+
86
+
87
+ def current_change(state, value):
88
+ ss.session["row_selected"] = value["index"]
89
+
90
+ def selection_change(state, value):
91
+ ss.session["selection_change"] = value["selected"]
92
+
93
+
94
+ # 创建一个包含三列的数据集
95
+ data = {'name': ['👧🏻 Alice', '👦🏻 Bob', '👦🏻 Charlie'],
96
+ 'age': [25, 30, 35],
97
+ 'city': ['New York', 'San Francisco', 'Los Angeles'],
98
+ 'health':[90,80,90]
99
+ }
100
+
101
+ df = pd.DataFrame(data)
102
+
103
+ def rowclicked(event):
104
+ #ss.message("row clicked")
105
+ #ss.write("event", event)
106
+ ss.session["itemname"] = event.value["name"]
107
+
108
+
109
+ cols = ss.columns([70,"flex:30; border-left:1px solid lightgray"], design=True, style="border:1px solid lightgray")
110
+ with cols[0]:
111
+ mytable = ss.table(df, handlers={"click:row": rowclicked})
112
+ ss.md("#### Events")
113
+ ss.write("Row clicked: @itemname")
114
+
115
+
116
+ with cols[1]:
117
+ ss.text("setting")
118
+ ss.checkbox("索引", onchange = onchange_index)
119
+ ss.space()
120
+ ss.checkbox("边框", onchange = onchange_border)
121
+ ss.space()
122
+ ss.checkbox("排序", onchange = onchange_sortable)
123
+ ss.space()
124
+ ss.checkbox("选择", onchange = onchange_selectable)
125
+ ss.space()
126
+ ss.checkbox("搜索", onchange = onchange_searchable)
127
+ ss.space()
128
+ ss.checkbox("编辑", onchange = onchange_editable)
129
+
130
+ ss.space("mt-8")
131
+
132
+ ss.write('''
133
+ ---
134
+ #### 🔎 代码
135
+ ''')
136
+
137
+ ss.md('''
138
+ ```python
139
+ import simplestart as ss
140
+
141
+ def current_change(state, value):
142
+ ss.session["row_selected"] = value["index"]
143
+
144
+ def selection_change(state, value):
145
+ ss.session["selection_change"] = value["selected"]
146
+
147
+ data = {'name': ['Alice', 'Bob', 'Charlie'],
148
+ 'age': [25, 30, 35],
149
+ 'city': ['New York', 'San Francisco', 'Los Angeles']}
150
+ df = pd.DataFrame(data)
151
+
152
+ ss.table(df, handlers={\"current-change\":current_change, \"selection-change\":selection_change})
153
+ ss.md(\"#### Events\")
154
+ ss.write(\"Row selected: \")
155
+ ss.write(\"Selection changed: \")
156
+
157
+ def onPageLoad():
158
+ ss.session["row_selected"] = ''
159
+ ss.session["selection_change"] = ''
160
+
161
+ ```
162
+ ''')
163
+
164
+
165
+ ss.md('''
166
+ ---
167
+ #### 🔅 示例 - 自定义列
168
+ ''')
169
+
170
+
171
+ data = {'name': ['👧🏻 Alice', '👦🏻 Bob', '👦🏻 Charlie'],
172
+ 'age': [25, 30, 35],
173
+ 'city': [':sunny: New York', ':cloud: San Francisco', ':sunny: Los Angeles'],
174
+ 'health':[90,80,90]
175
+ }
176
+
177
+ df = pd.DataFrame(data)
178
+
179
+ cols = ss.columns([70,"flex:30; border-left:1px solid lightgray"], design=True, style="border:1px solid lightgray")
180
+
181
+
182
+ vuecode = '''
183
+ <template>
184
+ <v-clip>123</v-clip>
185
+ </template>
186
+ '''
187
+
188
+ vuecode = "../components/mycell.vue"
189
+
190
+ #mytable_ex = ss.table(df, custom_columns = ["city"], custom_columns_template = vuestr)
191
+ with cols[0]:
192
+ mytable_ex = ss.table(df, custom_columns = ["city"], vue_columns = ["health"], vue_code = vuecode)
193
+ with cols[1]:
194
+ ss.write("每一列可以定制显示")
195
+
196
+ ss.space("mt-8")
197
+
198
+ ss.write('''
199
+ ---
200
+ #### 🔎 代码
201
+ ''')
202
+
203
+ ss.md('''
204
+ ```python
205
+ import simplestart as ss
206
+
207
+ data = {'name': ['👧🏻 Alice', '👦🏻 Bob', '👦🏻 Charlie'],
208
+ 'age': [25, 30, 35],
209
+ 'city': [':sunny: New York', ':cloud: San Francisco', ':sunny: Los Angeles'],
210
+ 'health':[90,80,90]
211
+ }
212
+ df = pd.DataFrame(data)
213
+
214
+ vuestr = \'''
215
+ <template>
216
+ <v-row>
217
+ <v-rating
218
+ v-model="rating" density="compact" color="orange" half-increments></v-rating>
219
+ <v-chip variant="text">{{item.value}}</v-chip>
220
+ </v-row>
221
+ </template>
222
+
223
+ <script>
224
+
225
+ module.exports = {
226
+ props:["item"],
227
+
228
+ data () {
229
+ return {
230
+ rating: 3
231
+ }
232
+ },
233
+ methods: {
234
+ //todo
235
+ },
236
+ mounted: function () {
237
+ this.rating = this.item.value/20
238
+ },
239
+ }
240
+ </script>
241
+ \'''
242
+
243
+ ss.table(df, custom_columns = ["city"], vue_columns = ["health"], vue_code = vuecode)
244
+ ```
245
+ ''')
246
+
247
+ def onPageLoad():
248
+ ss.session["show_border"] = ''
249
+ ss.session["selectable"] = ''
250
+ ss.session["sortable"] = ''
251
+ ss.session["row_selected"] = ''
252
+ ss.session["selection_change"] = ''
locales/zh/pages/003 Content Display/demo_text.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Text 文本
2
+ import streamsync as ss
3
+
4
+ ss.md("## ss.text 文本")
5
+ ss.md("支持style参数")
6
+
7
+
8
+ ss.space()
9
+ ss.space()
10
+ ss.md('''
11
+ #### 🔅 示例
12
+ ''')
13
+
14
+ ss.md("---")
15
+
16
+ #基本用法
17
+ test = ss.text("hello, world")
18
+
19
+ #改变颜色
20
+ ss.text("This is a red string", style="color:red")
21
+
22
+ ss.space()
23
+ ss.write("#### 🔎 代码")
24
+
25
+ ss.md('''
26
+ ```python
27
+ import simplestart as ss
28
+
29
+ #基本用法
30
+ test = ss.text("hello, world")
31
+
32
+ #改变颜色
33
+ ss.text("This is a red string", style="color:red")
34
+ ```
35
+ ''')
locales/zh/pages/003 Content Display/demo_video.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Video 视频播放
2
+ import streamsync as ss
3
+
4
+ ss.md("## ss.video 视频播放")
5
+
6
+ ss.md("支持播放mp4等格式的视频")
7
+
8
+ ss.md('''
9
+ #### 🔅 示例
10
+ ''')
11
+
12
+ src = "https://media.w3.org/2010/05/sintel/trailer.mp4"
13
+
14
+ player = ss.video(src, style="width:50%")
15
+
16
+ ss.text("来源: https://media.w3.org/2010/05/sintel/trailer.mp4", style="color:gray")
17
+
18
+ ss.space("mt-8")
19
+
20
+ ss.write('''
21
+ ---
22
+ #### 🔎 代码
23
+ ''')
24
+
25
+ ss.md('''
26
+ ```python
27
+ import simplestart as ss
28
+
29
+ src = "https://media.w3.org/2010/05/sintel/trailer.mp4"
30
+
31
+ player = ss.video(src, style="width:100%; max-width:640px")
32
+
33
+ #修改视频地址
34
+ #player.src = "..."
35
+ ```
36
+ ''')
locales/zh/pages/003 Content Display/demo_write.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Write 输出数据
2
+
3
+ import streamsync as ss
4
+ import pandas as pd
5
+
6
+ ss.md("## ss.write 输出")
7
+
8
+ ss.md("ss.write 类似于print,可以输出文本,列表和其它类型,方便测试和输出")
9
+
10
+ ss.space()
11
+
12
+ ss.md('''
13
+ #### 🔅 示例
14
+ ''')
15
+
16
+
17
+ ss.md("#### 1. 输出文本")
18
+ ss.write("This is a text")
19
+
20
+ ss.md('''
21
+ ```python
22
+ ss.write("This is a text")
23
+ ```
24
+ ''')
25
+
26
+ ss.md("#### 2. 输出多个变量")
27
+ a = "aaa"
28
+ b = "bbb"
29
+ ss.write(a, ",", b)
30
+
31
+ ss.md('''
32
+ ```python
33
+ a = "aaa"
34
+ b = "bbb"
35
+ ss.write(a, ",", b)
36
+ ```
37
+ ''')
38
+
39
+ ss.md("#### 3. 输出列表")
40
+ data = ["aaa", "bbb", "ccc"]
41
+ ss.write(data)
42
+
43
+ data = {"aaa":1, "bbb":2, "ccc":3}
44
+ ss.write(data)
45
+
46
+ ss.md('''
47
+ ```python
48
+ data = ["aaa", "bbb", "ccc"]
49
+ ss.write(data)
50
+
51
+ data = {"aaa":1, "bbb":2, "ccc":3}
52
+ ss.write(data)
53
+ ```
54
+ ''')
55
+
56
+
57
+ ss.md("#### 4. 输出表格")
58
+ # 创建数据
59
+ data = {'name': ['Alice', 'Bob', 'Charlie', 'David'],
60
+ 'age': [25, 30, 35, 40],
61
+ 'city': ['New York', 'Paris', 'London', 'Sydney']}
62
+
63
+ # 将数据转换为 DataFrame 格式
64
+ df = pd.DataFrame(data)
65
+ ss.write(df)
66
+
67
+ ss.md('''
68
+ ```python
69
+ # 创建数据
70
+ data = {'name': ['Alice', 'Bob', 'Charlie', 'David'],
71
+ 'age': [25, 30, 35, 40],
72
+ 'city': ['New York', 'Paris', 'London', 'Sydney']}
73
+
74
+ # 将数据转换为 DataFrame 格式
75
+ df = pd.DataFrame(data)
76
+ ss.write(df)
77
+ ```
78
+ ''')
locales/zh/pages/003 Content Display/folder.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"alias":"数据展示"}
locales/zh/pages/004 Chart Data/demo_bokeh.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import simplestart as ss
2
+
3
+ from bokeh.plotting import figure
4
+ from bokeh.models import ColumnDataSource
5
+ from bokeh.resources import CDN
6
+ from bokeh.embed import file_html
7
+ from sklearn.datasets import load_iris
8
+ import pandas as pd
9
+
10
+ # 加载 Iris 数据集
11
+ iris = load_iris()
12
+ df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
13
+ df['species'] = iris.target
14
+ df['species'] = df['species'].map({0: 'setosa', 1: 'versicolor', 2: 'virginica'})
15
+
16
+
17
+ # 创建图形数据源和图形对象
18
+ source = ColumnDataSource(data=dict(
19
+ sepal_length=df['sepal length (cm)'],
20
+ sepal_width=df['sepal width (cm)'],
21
+ petal_length=df['petal length (cm)'],
22
+ petal_width=df['petal width (cm)'],
23
+ species=df['species']
24
+ ))
25
+
26
+ # 创建 Bokeh 图表
27
+ p = figure(title="Iris 数据集散点图", x_axis_label='花萼长度 (cm)', y_axis_label='花萼宽度 (cm)',
28
+ tools="pan,wheel_zoom,box_zoom,reset,hover,save", width = 800)
29
+
30
+ # 根据种类设置不同颜色
31
+ colors = {'setosa': 'blue', 'versicolor': 'green', 'virginica': 'red'}
32
+
33
+ for species, color in colors.items():
34
+ df_species = df[df['species'] == species]
35
+ source_species = ColumnDataSource(data=dict(
36
+ sepal_length=df_species['sepal length (cm)'],
37
+ sepal_width=df_species['sepal width (cm)']
38
+ ))
39
+ p.scatter('sepal_length', 'sepal_width', source=source_species, legend_label=species, color=color,
40
+ size=10, alpha=0.5)
41
+
42
+ p.legend.title = 'Species'
43
+ p.legend.location = 'top_left'
44
+
45
+ # 将 Bokeh 图形嵌入到 Streamlit
46
+ html = file_html(p, CDN, "Iris 数据集散点图")
47
+
48
+ #ui
49
+ ss.md('''
50
+ ## simplestart 图表演示 - bokeh
51
+ ''')
52
+
53
+ ss.space()
54
+ ss.md('''
55
+ #### 🔅 示例
56
+ 利用bokeh展示Iris数据的交互式散点图
57
+ ''')
58
+
59
+ ss.space()
60
+ ss.htmlview(html, border = False)
61
+
62
+ ss.space()
63
+ ss.write("#### 🔎 代码")
64
+
65
+ def viewcode():
66
+ ss.session["viewcode"] = 1
67
+
68
+ ss.session["viewcode"] = 0
69
+ ss.button("查看", size="small", onclick = viewcode)
70
+
71
+ def conditioner(event):
72
+ return (ss.session["viewcode"] == 1)
73
+
74
+ code = '''
75
+ ```python
76
+ import simplestart as ss
77
+
78
+ from bokeh.plotting import figure
79
+ from bokeh.models import ColumnDataSource
80
+ from bokeh.resources import CDN
81
+ from bokeh.embed import file_html
82
+ from sklearn.datasets import load_iris
83
+ import pandas as pd
84
+
85
+ # 加载 Iris 数据集
86
+ iris = load_iris()
87
+ df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
88
+ df['species'] = iris.target
89
+ df['species'] = df['species'].map({0: 'setosa', 1: 'versicolor', 2: 'virginica'})
90
+
91
+
92
+ # 创建图形数据源和图形对象
93
+ source = ColumnDataSource(data=dict(
94
+ sepal_length=df['sepal length (cm)'],
95
+ sepal_width=df['sepal width (cm)'],
96
+ petal_length=df['petal length (cm)'],
97
+ petal_width=df['petal width (cm)'],
98
+ species=df['species']
99
+ ))
100
+
101
+ # 创建 Bokeh 图表
102
+ p = figure(title="Iris 数据集散点图", x_axis_label='花萼长度 (cm)', y_axis_label='花萼宽度 (cm)',
103
+ tools="pan,wheel_zoom,box_zoom,reset,hover,save", width = 800)
104
+
105
+ # 根据种类设置不同颜色
106
+ colors = {'setosa': 'blue', 'versicolor': 'green', 'virginica': 'red'}
107
+
108
+ for species, color in colors.items():
109
+ df_species = df[df['species'] == species]
110
+ source_species = ColumnDataSource(data=dict(
111
+ sepal_length=df_species['sepal length (cm)'],
112
+ sepal_width=df_species['sepal width (cm)']
113
+ ))
114
+ p.scatter('sepal_length', 'sepal_width', source=source_species, legend_label=species, color=color,
115
+ size=10, alpha=0.5)
116
+
117
+ p.legend.title = 'Species'
118
+ p.legend.location = 'top_left'
119
+
120
+ # 将 Bokeh 图形嵌入到 Streamlit
121
+ html = file_html(p, CDN, "Iris 数据集散点图")
122
+
123
+ #ui
124
+ ss.htmlview(html, border = False)
125
+ '''
126
+
127
+ with ss.when(conditioner):
128
+ ss.md(code)
locales/zh/pages/004 Chart Data/demo_pyplot.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamsync as ss
2
+
3
+ import seaborn as sns
4
+ import matplotlib as mpl
5
+ #mpl.use("Agg") #很重要,否则在ss中会崩溃
6
+ import matplotlib.pyplot as plt
7
+
8
+
9
+ #下载不了,所以加一个参数data_home
10
+ data_home = "./data/seaborn"
11
+
12
+ ss.md('''
13
+ ## ss.pyplot 绘图
14
+ ''')
15
+
16
+
17
+ ss.space()
18
+ ss.md('''
19
+ #### 🔅 示例
20
+ ''')
21
+
22
+ ss.write("#### 1. 画折线图")
23
+
24
+ sns.set_style("whitegrid")
25
+ titanic = sns.load_dataset("titanic", data_home=data_home)
26
+ sns.lineplot(x="age", y="fare", hue="sex", data=titanic)
27
+ plt.show()
28
+
29
+ fig = plt.gcf()
30
+ ss.pyplot(fig, style="border:1px solid gray; width:600px")
31
+
32
+ ss.write("#### 2. 画散点图")
33
+
34
+ sns.set_style("whitegrid")
35
+ tips = sns.load_dataset("tips", data_home=data_home)
36
+ sns.scatterplot(x="total_bill", y="tip", data=tips)
37
+ plt.show()
38
+
39
+ fig = plt.gcf()
40
+ ss.pyplot(fig, style="border:1px solid gray; width:600px")
41
+
42
+ ss.write("#### 3. 画条形图")
43
+
44
+ sns.set_style("whitegrid")
45
+ titanic = sns.load_dataset("titanic",data_home=data_home)
46
+ sns.barplot(x="class", y="survived", data=titanic)
47
+ plt.show()
48
+
49
+ fig = plt.gcf()
50
+ ss.pyplot(fig, style="border:1px solid gray; width:600px")
51
+
52
+
53
+ ss.write("#### 4. 画直方图")
54
+ sns.set_style("whitegrid")
55
+ titanic = sns.load_dataset("titanic",data_home=data_home)
56
+ sns.histplot(x="age", data=titanic)
57
+ plt.show()
58
+
59
+ fig = plt.gcf()
60
+ ss.pyplot(fig, style="border:1px solid gray; width:600px")
61
+
62
+
63
+ ss.space()
64
+
65
+ ss.write("#### 🔎 代码")
66
+ ss.write("---")
67
+
68
+ def viewcode():
69
+ ss.session["viewcode"] = 1
70
+
71
+ ss.button("查看", size="small", onclick = viewcode)
72
+
73
+
74
+ def conditioner(event):
75
+ return ss.session["viewcode"] == 1
76
+
77
+ with ss.when(conditioner):
78
+ ss.md('''
79
+ ```python
80
+ import streamsync as ss
81
+
82
+ import seaborn as sns
83
+ import matplotlib as mpl
84
+ mpl.use("Agg") #很重要,否则在ss中会崩溃
85
+ import matplotlib.pyplot as plt
86
+
87
+
88
+ #下载不了,所以加一个参数data_home
89
+ data_home = "./data/seaborn"
90
+
91
+
92
+ ss.write("#### 1. 画折线图")
93
+
94
+ sns.set_style("whitegrid")
95
+ titanic = sns.load_dataset("titanic", data_home=data_home)
96
+ sns.lineplot(x="age", y="fare", hue="sex", data=titanic)
97
+ plt.show()
98
+
99
+ fig = plt.gcf()
100
+ ss.pyplot(fig, style="border:1px solid gray; width:600px")
101
+
102
+ ss.write("#### 2. 画散点图")
103
+
104
+ sns.set_style("whitegrid")
105
+ tips = sns.load_dataset("tips", data_home=data_home)
106
+ sns.scatterplot(x="total_bill", y="tip", data=tips)
107
+ plt.show()
108
+
109
+ fig = plt.gcf()
110
+ ss.pyplot(fig, style="border:1px solid gray; width:600px")
111
+
112
+ ss.write("#### 3. 画条形图")
113
+
114
+ sns.set_style("whitegrid")
115
+ titanic = sns.load_dataset("titanic",data_home=data_home)
116
+ sns.barplot(x="class", y="survived", data=titanic)
117
+ plt.show()
118
+
119
+ fig = plt.gcf()
120
+ ss.pyplot(fig, style="border:1px solid gray; width:600px")
121
+
122
+
123
+ ss.write("#### 4. 画直方图")
124
+ sns.set_style("whitegrid")
125
+ titanic = sns.load_dataset("titanic",data_home=data_home)
126
+ sns.histplot(x="age", data=titanic)
127
+ plt.show()
128
+
129
+ fig = plt.gcf()
130
+ ss.pyplot(fig, style="border:1px solid gray; width:600px")
131
+ ```
132
+ ''')
133
+
locales/zh/pages/004 Chart Data/folder.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"alias":"图表数据"}
locales/zh/pages/005 Layout Related/demo_columns.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Columns 列布局
2
+ import streamsync as ss
3
+
4
+ ss.md("## ss.columns 列布局")
5
+
6
+ ss.space()
7
+ ss.md("#### 🔅 示例")
8
+
9
+ ss.space()
10
+
11
+ ss.md("### 平均间距")
12
+
13
+ def onchange1(event):
14
+ #cols_ex1.design = True
15
+ cols_ex1_id = cols1[0].id #通过cols_ex1不能直接得到
16
+
17
+ if event.value == True:
18
+ ss.getcm().components[cols_ex1_id]["content"]["options"]["border"] = True
19
+ ss.session["cols1_design"] = ', border = True'
20
+ else:
21
+ ss.getcm().components[cols_ex1_id]["content"]["options"]["border"] = False
22
+ ss.session["cols1_design"] = ''
23
+ ss.update_cm(cols_ex1_id)
24
+
25
+ ss.checkbox("border", checked = True, onchange = onchange1)
26
+
27
+ cols1 = ss.columns(2, border=True)
28
+
29
+ with cols1[0]:
30
+ ss.text("First of two columns")
31
+
32
+ with cols1[1]:
33
+ ss.text("Second of two columns")
34
+
35
+
36
+ ss.space()
37
+ ss.write("---")
38
+ ss.write("#### 🔎 代码")
39
+ ss.md('''
40
+ ```python
41
+ import simplestart as ss
42
+
43
+ cols1 = ss.columns(2, border = True)
44
+
45
+ with cols1[0]:
46
+ ss.text("First of two columns")
47
+
48
+ with cols1[1]:
49
+ ss.text("Second of two columns")
50
+ ```
51
+ ''')
52
+
53
+ ss.space()
54
+
55
+
56
+ ss.md("### 按比例间距")
57
+
58
+ def onchange2(event):
59
+ #cols_ex1.design = True
60
+ cols_ex2_id = cols2[0].id #通过cols_ex1不能直接得到
61
+
62
+ if event.value == True:
63
+ ss.getcm().components[cols_ex2_id]["content"]["options"]["border"] = True
64
+ ss.session["cols2_design"] = ', border = True'
65
+ else:
66
+ ss.getcm().components[cols_ex2_id]["content"]["options"]["border"] = False
67
+ ss.session["cols2_design"] = ''
68
+ ss.update_cm(cols_ex2_id)
69
+
70
+
71
+ ss.checkbox("border", checked = True, onchange = onchange2)
72
+
73
+ cols2 = ss.columns([4,6], border = True)
74
+
75
+ with cols2[0]:
76
+ ss.text("First of two columns")
77
+ with cols2[1]:
78
+ ss.text("Second of two columns")
79
+
80
+
81
+ ss.space()
82
+ ss.write("---")
83
+ ss.write("#### 🔎 代码")
84
+ ss.md('''
85
+ ```python
86
+ import simplestart as ss
87
+
88
+ cols1 = ss.columns([4,6], border = True)
89
+
90
+ with cols1[0]:
91
+ ss.text("First of two columns")
92
+
93
+ with cols1[1]:
94
+ ss.text("Second of two columns")
95
+ ```
96
+ ''')
97
+
98
+ def onPageLoad():
99
+ ss.session["cols1_design"] = ''
100
+ ss.session["cols2_design"] = ''
locales/zh/pages/005 Layout Related/demo_row.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Row 行布局
2
+
3
+ import streamsync as ss
4
+
5
+ ss.md("## ss.row 行布局")
6
+
7
+ ss.space()
8
+ ss.md("#### 🔅 示例")
9
+ ss.write("通过 ss.row 将两个按钮限制在一行内显示,同时利用ss.spacer 改变按钮的布局")
10
+
11
+ ss.space()
12
+
13
+ def onchange1():
14
+ pass
15
+
16
+
17
+ #ui
18
+
19
+ style = "background:#d3d3d354; padding:5px;"
20
+
21
+ ss.space()
22
+ ss.write("#### 1. Normal")
23
+ ss.space()
24
+ with ss.row(style=style):
25
+ ss.button("button1")
26
+ ss.button("button2")
27
+
28
+ ss.space()
29
+ ss.write("#### 2. Center")
30
+ ss.space()
31
+ with ss.row(style=style):
32
+ ss.spacer()
33
+ ss.button("button1")
34
+ ss.button("button2")
35
+ ss.spacer()
36
+
37
+ ss.space()
38
+ ss.write("#### 3. Right align")
39
+ ss.space()
40
+ with ss.row(style=style):
41
+ ss.spacer()
42
+ ss.button("button1")
43
+ ss.button("button2")
44
+
45
+ ss.space()
46
+ ss.write("#### 4. Right respectively")
47
+ ss.space()
48
+ with ss.row(style=style):
49
+ ss.spacer()
50
+ ss.button("button1")
51
+ ss.spacer()
52
+ ss.button("button2")
53
+
54
+
55
+ ss.space("mt-16")
56
+ ss.write("#### 🔎 代码")
57
+
58
+ ss.md('''
59
+ ```python
60
+ import simplestart as ss
61
+
62
+ style = "background:#d3d3d354; padding:5px;"
63
+ ss.space()
64
+ ss.write("#### 1. Normal")
65
+ ss.space()
66
+ with ss.row(style=style):
67
+ ss.button("button1")
68
+ ss.button("button2")
69
+
70
+ ss.space()
71
+ ss.write("#### 2. Center")
72
+ ss.space()
73
+ with ss.row(style=style):
74
+ ss.spacer()
75
+ ss.button("button1")
76
+ ss.button("button2")
77
+ ss.spacer()
78
+
79
+ ss.space()
80
+ ss.write("#### 3. Right align")
81
+ ss.space()
82
+ with ss.row(style=style):
83
+ ss.spacer()
84
+ ss.button("button1")
85
+ ss.button("button2")
86
+
87
+ ss.space()
88
+ ss.write("#### 4. Right respectively")
89
+ ss.space()
90
+ with ss.row(style=style):
91
+ ss.spacer()
92
+ ss.button("button1")
93
+ ss.spacer()
94
+ ss.button("button2")
95
+
96
+ ''')
97
+
98
+ ss.md('''
99
+ ::: tip
100
+ ss.space 表示增加间距, ss.spacer 是用来填补间距达到修改布局的作用
101
+ :::
102
+ ''')
locales/zh/pages/005 Layout Related/demo_section.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Section 一般容器
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.section 容器")
5
+
6
+ ss.md("section 父容器, 可以装载其它组件, 支持style参数")
7
+
8
+
9
+ ss.space()
10
+ ss.md('''
11
+ #### 🔅 示例
12
+ ''')
13
+
14
+ #api
15
+ def clear():
16
+ section.empty()
17
+
18
+ def write_something():
19
+ section.text("Hello, I am inside section 2")
20
+
21
+ #ui
22
+ with ss.section("Section1", shadow = 10, border = True, rounded=True, width = "50%", height=300):
23
+ ss.text("This is inside the section 1")
24
+
25
+
26
+ ss.space()
27
+
28
+ section = ss.section()
29
+ section.text("This is inside the section 2")
30
+
31
+ ss.space("mt-4 mb-4")
32
+ ss.text("outside the section")
33
+
34
+
35
+ ss.md("---")
36
+
37
+ ss.button("clear", onclick=clear)
38
+
39
+ ss.button("add something", onclick=write_something)
40
+
41
+ ss.space()
42
+
43
+ ss.write("#### 🔎 代码")
44
+
45
+ ss.md("""
46
+ ```python
47
+ import simplestart as ss
48
+
49
+ #api
50
+ def clear():
51
+ section.empty()
52
+
53
+ def write_something():
54
+ section.text("Hello, I am inside section 2")
55
+
56
+ #ui
57
+ with ss.section(title = "Section1", shadow = 10, border = True, rounded=True, width = "50%", height=300):
58
+ ss.text("This is inside the section 1")
59
+
60
+
61
+ ss.space()
62
+
63
+ section = ss.section()
64
+ section.text("This is inside the section 2")
65
+
66
+ ss.space()
67
+ ss.text("outside the section")
68
+
69
+ ss.md("---")
70
+
71
+ ss.button("clear", onclick=clear)
72
+ ss.button("add something", onclick=write_something)
73
+
74
+ ```
75
+ """)
76
+
77
+ ss.md('''
78
+ ::: tip
79
+ 除了可以通过 with 语法添加组件,也可以直接通过section.text(), section.button()等方式添加容器内的组件
80
+ :::
81
+ ''')
locales/zh/pages/005 Layout Related/demo_sidebar.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Sidebar 侧边栏
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.sidebar 侧边栏")
5
+
6
+ ss.md("在屏幕左侧的侧边栏内显示各种组件,例如可以放置数据控制和一些设置。")
7
+
8
+ ss.md('''
9
+ #### 🔅 示例
10
+ ''')
11
+
12
+
13
+ sidebar = ss.sidebar()
14
+
15
+ with sidebar:
16
+ ss.button("click")
17
+ ss.selectbox(["one", "two", "three"])
18
+
19
+
20
+ def testme(state, value):
21
+ with sidebar:
22
+ ss.text("text in sidebar")
23
+
24
+
25
+ ss.button("test", onclick = testme)
26
+
27
+
28
+ ss.space()
29
+
30
+ ss.write("#### 🔎 代码")
31
+
32
+ ss.md('''
33
+ ```python
34
+ import simplestart as ss
35
+
36
+ sidebar = ss.sidebar()
37
+
38
+ with sidebar:
39
+ ss.button("click")
40
+ ss.selectbox(["one", "two", "three"])
41
+
42
+
43
+ def testme(state, value):
44
+ with sidebar:
45
+ ss.text("text in sidebar")
46
+ #or
47
+ #sidebar.text("text in sidebar")
48
+
49
+
50
+ ss.button("test", onclick = testme)
51
+
52
+ ```
53
+ ''')
locales/zh/pages/005 Layout Related/demo_style.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Style 样式设置
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.style 样式设置")
5
+
6
+ ss.space()
7
+ ss.md("#### 🔅 示例")
8
+ ss.write("向 HTML 文档中注入 CSS 样式")
9
+
10
+ ss.html('''
11
+ <div class="test1">this is a sample1</div>
12
+ <div class="test2">this is a sample2</div>
13
+ ''')
14
+
15
+
16
+ ss.style('''
17
+ .test1{
18
+ background-color:lightgray;
19
+ padding:5px;
20
+ width:150px;
21
+ margin-bottom:10px;
22
+ border:1px solid lightblue
23
+ }
24
+ .test2{
25
+ color:red;
26
+ border:1px solid lightgreen;
27
+ padding:5px;
28
+ width:150px;
29
+ }
30
+ ''')
31
+
32
+ ss.space()
33
+
34
+ ss.write("#### 🔎 代码")
35
+
36
+
37
+ ss.space()
38
+
39
+ ss.write('''
40
+ ---
41
+ #### 代码
42
+ ''')
43
+
44
+ ss.md('''
45
+ ```python
46
+ import simplestart as ss
47
+
48
+ ss.html(\'''
49
+ <div class="test1">this is a sample1</div>
50
+ <div class="test2">this is a sample2</div>
51
+ \''')
52
+
53
+ ss.style(\'''
54
+ .test1{
55
+ background-color:lightgray;
56
+ padding:5px;
57
+ width:150px;
58
+ margin-bottom:10px;
59
+ border:1px solid lightblue
60
+ }
61
+ .test2{
62
+ color:red;
63
+ border:1px solid lightgreen;
64
+ padding:5px;
65
+ width:150px;
66
+ }
67
+ \''')
68
+ ''')
locales/zh/pages/005 Layout Related/demo_tabs.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Tabs 标签页
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.tabs 标签页")
5
+
6
+ ss.space("mt-16")
7
+ ss.md("#### 🔅 示例")
8
+
9
+ tabtitles = ["tab1", "tab2", "tab3"]
10
+ tabs = ss.tabs(tabtitles)
11
+
12
+ with tabs[0]:
13
+ ss.text("this is tab 1")
14
+ with tabs[1]:
15
+ ss.text("this is tab 2")
16
+ with tabs[2]:
17
+ ss.text("this is tab 3")
18
+
19
+ ss.space()
20
+ ss.write("#### 🔎 代码")
21
+
22
+ ss.md('''
23
+ ```python
24
+ import simplestart as ss
25
+
26
+ tabtitles = ["tab1", "tab2", "tab3"]
27
+ tabs = ss.tabs(tabtitles)
28
+
29
+ with tabs[0]:
30
+ ss.text("this is tab 1")
31
+ with tabs[1]:
32
+ ss.text("this is tab 2")
33
+ with tabs[2]:
34
+ ss.text("this is tab 3")
35
+ ''')
locales/zh/pages/005 Layout Related/folder.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"alias":"布局相关"}
locales/zh/pages/006 Advanced Usage/demo_component.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### ss.component 自定义组件
2
+ import simplestart as ss
3
+
4
+ ss.md("### ss.component")
5
+ ss.md("可以通过html,js, css自定义组件,通过iframe实现")
6
+
7
+ ss.space()
8
+ ss.md('''
9
+ #### 🔅 示例
10
+ ''')
11
+ ss.space()
12
+
13
+ def testme(state, value):
14
+ mytext.text = "接收到的前端UI的数据: " + value["value"]
15
+
16
+ #默认情况下,<iframe> 的宽度为 300 像素,高度为 150 像素。
17
+ ss.text("在文本框中输入内容并按回车")
18
+
19
+ myplugin = ss.component(path = f"components/index.html", onData = testme) ###style="border:none")
20
+
21
+ def postdata():
22
+ data = {"my_input_value":"text from python"}
23
+ myplugin.postMessage(data)
24
+
25
+ mytext = ss.text("接收到的前端UI的数据: ")
26
+
27
+ ss.markdown("---")
28
+ ss.space()
29
+ ss.text("点击按钮,传递数据到UI前端")
30
+ ss.button("post data", onclick=postdata)
31
+
32
+ ss.space()
33
+
34
+ ss.write("Python端代码")
35
+
36
+ ss.md('''
37
+ ```python
38
+ import simplestart as ss
39
+
40
+ def testme(state, value):
41
+ mytext.text = "接收到的前端UI的数据: " + value["value"]
42
+
43
+ ss.text("在文本框中输入内容并按回车")
44
+ myplugin = ss.component(path = f"components/index.html", onData = testme)
45
+
46
+ def postdata():
47
+ data = {"my_input_value":"text from python"}
48
+ myplugin.postMessage(data)
49
+
50
+ mytext = ss.text("接收到的前端UI的数据: ")
51
+
52
+ ss.markdown("---")
53
+
54
+ ss.space()
55
+ ss.text("点击按钮,传递数据到UI前端")
56
+ ss.button("post data", onclick=postdata)
57
+
58
+ ```
59
+ ''')
60
+
61
+ ss.write("Plugin/html/js端代码")
62
+
63
+ ss.md('''
64
+ ```html
65
+ <html>
66
+
67
+ <head>
68
+ <script src="pybridge.js"></script>
69
+ </head>
70
+
71
+ <body style="height:100px">
72
+ <input id="myinput" value="" autocomplete="off" placeholder="输入内容,并按回车" />
73
+ </body>
74
+
75
+ <script>
76
+ var myInput = document.getElementById("myinput");
77
+
78
+ myInput.addEventListener("change", function() {
79
+ ////将消息发送给Python端
80
+ sendDataToPython({
81
+ value: myInput.value,
82
+ });
83
+ })
84
+
85
+ //接受来自Python端的消息消息
86
+ window.addEventListener("message", onDataFromPython);
87
+
88
+ function onDataFromPython(event) {
89
+ var data = event.data.arg;
90
+ if (event.data.type !== "ss:render") return;
91
+ myInput.value = data.my_input_value; // Access values sent from Python here!
92
+ }
93
+
94
+ //如果系统设置失败,可以手工设置高度
95
+ //setFrameHeight(200);
96
+ </script>
97
+
98
+ </html>
99
+
100
+ ```
101
+ ''')
locales/zh/pages/006 Advanced Usage/demo_loadvue.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### ss.loadvue 加载VUE SFC
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.loadvue 加载VUE SFC")
5
+
6
+ ss.space()
7
+ ss.md("在SimpleStart中,可以通过ss.loadvue加载自定义的vue单文件组件,实现属性和数据交互。")
8
+
9
+ ss.space()
10
+
11
+ ss.space()
12
+ ss.md('''
13
+ #### 🔅 示例
14
+
15
+ 在这里例子中,我们定义一个简单的前端组件,组件里定义了一个"ontest"事件,当用户点击"handle on server"按钮时,
16
+ Python端的ontest事件处理函数会处理,并且接受前端组件传递的数据。同时,当点击Python端的 "修改数据"
17
+ 按钮时,前端组件会响应改变显示内容。
18
+
19
+ ''')
20
+
21
+ ss.space("mt-8")
22
+ ss.md("---")
23
+ ss.space("mt-8")
24
+
25
+ tagid = 0
26
+ tags = ["Python", "Java", "Javascript"]
27
+ data = {"count":0, "language":"C++"}
28
+ global myvue
29
+
30
+ #trigger event on server from client side
31
+ def ontest(event):
32
+ ss.message(event.value)
33
+
34
+ #change data in client component on server side
35
+ def changedata(event):
36
+ global tagid
37
+ myvue.data["language"] = tags[tagid]
38
+ myvue.update()
39
+
40
+ tagid = (tagid+1) % 3
41
+
42
+ ss.text("Python 端")
43
+ ss.button("修改数据", onclick=changedata)
44
+
45
+ ss.space()
46
+ sec = ss.section()
47
+
48
+ def onPageLoad():
49
+ global myvue
50
+ #load code from file
51
+ with sec:
52
+ ss.text("组件端")
53
+ myvue = ss.loadvue(path = "components/mycomponent.vue", data = data, handlers = {"ontest":ontest})
54
+
55
+
56
+ ss.space()
57
+ ss.write("Python端 代码")
58
+
59
+ ss.md('''
60
+ ```python
61
+ import simplestart as ss
62
+
63
+ tagid = 0
64
+ global myvue
65
+
66
+ tags = ["Python", "Java", "Javascript"]
67
+ data = {"count":0, "language":"C++"}
68
+
69
+
70
+ #trigger event on server from client side
71
+ def ontest(state, value):
72
+ ss.message(value)
73
+
74
+ #change data in client component on server side
75
+ def changedata(state, value=None):
76
+ global tagid
77
+ myvue.data["language"] = tags[tagid]
78
+ tagid = (tagid+1) % 3
79
+
80
+ ss.text("Python 端")
81
+ ss.button("修改数据", onclick=changedata)
82
+
83
+
84
+ def onPageLoad():
85
+ global myvue
86
+ #load code from file
87
+ myvue = ss.loadvue(path = "components/mycomponent.vue", data = data, handlers = {"ontest":ontest})
88
+ ```
89
+ ''')
90
+
91
+
92
+ ss.space()
93
+ ss.write("Vue JS代码")
94
+
95
+ ss.md('''
96
+ ```js
97
+ <template>
98
+ <div class="my-component">
99
+ <h1>{{title}}: {{ data.language }}</h1>
100
+ <v-btn @click="testme">handle on server</v-btn>
101
+ </div>
102
+ </template>
103
+
104
+ <script>
105
+ module.exports = {
106
+ name: 'MyComponent',
107
+
108
+ data() {
109
+ return {
110
+ title:"computer",
111
+ }
112
+ },
113
+
114
+ methods: {
115
+ testme(){
116
+ this.streamsync.forwardData(this, eventname="ontest", "12345")
117
+ }
118
+ }
119
+ }
120
+ </script>
121
+
122
+ <style>
123
+ .my-component {
124
+ width:50%;
125
+ background-color: #f0f0f0;
126
+ padding: 20px;
127
+ margin:10px 0;
128
+ }
129
+ </style>
130
+
131
+ ```
132
+ ''')
locales/zh/pages/006 Advanced Usage/demo_onload.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### ss.onPageEnter 页面加载事件
2
+ import simplestart as ss
3
+ from datetime import datetime
4
+
5
+ ss.md("## onPageEnter 页面加载事件")
6
+
7
+ ss.md('''
8
+ ---
9
+ #### 🔅 示例
10
+ ''')
11
+
12
+ ss.md("每次进入这个页面的时候,onPageEnter事件函数会被调用, 上方会弹出一个message")
13
+
14
+ ss.space()
15
+
16
+ mytext = ss.text("当前时间@currentime")
17
+
18
+ def onPageEnter():
19
+ #ss.write("test")
20
+ ss.message("page enter event") ##不知道为什么不起作用
21
+
22
+ #mytext.update_cm() ###这个很重要,否则@test不会响应
23
+
24
+ # 获取当前时间
25
+ now = datetime.now()
26
+ # 格式化时间为字符串
27
+ time_str = now.strftime('%Y-%m-%d %H:%M:%S')
28
+ ss.session["currentime"] = time_str
29
+
30
+
31
+ ss.space()
32
+
33
+ ss.write('''
34
+ ---
35
+ #### 🔎 代码
36
+ ''')
37
+
38
+ ss.md('''
39
+ ```python
40
+ import simplestart as ss
41
+
42
+ def onPageEnter():
43
+ ss.message("page enter event")
44
+
45
+ ```
46
+ ''')
locales/zh/pages/006 Advanced Usage/demo_session.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### ss.session 页面会话变量
2
+ import simplestart as ss
3
+
4
+ ss.md("## ss.session session变量")
5
+
6
+ ss.space()
7
+
8
+
9
+ #in this page
10
+ ss.session["count"] = 100
11
+
12
+ mytext = ss.text("The couns is @count")
13
+
14
+
15
+ def change_count():
16
+ ss.session.count += 1
17
+
18
+ ss.button("Add Count", onclick=change_count)
19
+
20
+ def xonPageEnter():
21
+ ss.session.count = 100
22
+ #mytext.update_cm() ###对于包括@的组件,需要在这里设置,否则不变化显示值
locales/zh/pages/006 Advanced Usage/demo_template.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### ss.template 加载VUE模版
2
+
3
+ import simplestart as ss
4
+
5
+
6
+ ss.md("## ss.template 加载VUE模版")
7
+
8
+ ss.space("mt-8")
9
+ ss.md('''
10
+ 在SimpleStart中,可以通过ss.template定义简单的vue组件, 实现属性和数据交互。
11
+
12
+ #### 函数
13
+ ss.template(src, path, data, handlers)
14
+
15
+ ##### 函数说明
16
+
17
+ | 参数 | 说明 |
18
+ | --- | --- |
19
+ | src | 字符串形式的组件脚本 |
20
+ | path | 外部文件的组件的原代码路径 |
21
+ | data | 用于实现前端组件和Python端的交互数据 |
22
+ | handlers | 在Python端实现前端组件定义的事件 |
23
+
24
+ ''')
25
+
26
+ ss.space("mt-8")
27
+
28
+ ss.md('''
29
+ ---
30
+ #### 示例1
31
+ 在这里例子中,我们定义一个简单的前端组件,组件里定义了一个"myclick"事件,当用户点击"Click me"按钮时,
32
+ Python端的myclick事件处理函数会处理,并且接受前端组件传递的数据。同时,当点击Python端的 "增加数字"
33
+ 按钮时,通过state变量改变前端的数值。
34
+
35
+ ''')
36
+
37
+
38
+ template = '''
39
+ <v-card
40
+ class="mx-auto text-white"
41
+ color="#26c6da"
42
+ max-width="400"
43
+ prepend-icon="mdi-twitter"
44
+ title="Twitter"
45
+ >
46
+ <template v-slot:prepend>
47
+ <v-icon size="x-large"></v-icon>
48
+ </template>
49
+
50
+ <v-card-text class="text-h6 py-2">
51
+ "SimpleStart is a easy way to build webpage and visualize data."
52
+ </v-card-text>
53
+
54
+ <v-card-actions>
55
+ <v-list-item class="w-100">
56
+ <template v-slot:prepend>
57
+ <v-avatar
58
+ color="grey-darken-3"
59
+ image="https://avataaars.io/?avatarStyle=Transparent&topType=ShortHairShortCurly&accessoriesType=Prescription02&hairColor=Black&facialHairType=Blank&clotheType=Hoodie&clotheColor=White&eyeType=Default&eyebrowType=DefaultNatural&mouthType=Default&skinColor=Light"
60
+ ></v-avatar>
61
+ </template>
62
+
63
+ <v-list-item-title>Evan You</v-list-item-title>
64
+
65
+ <v-list-item-subtitle>Data Science Engineer</v-list-item-subtitle>
66
+
67
+ <template v-slot:append>
68
+ <div class="justify-self-end">
69
+ <v-icon class="me-1" icon="mdi-heart" \@click="onserver('myclick')"></v-icon>
70
+ <span class="subheading me-2">{{data.vote}}</span>
71
+ <span class="me-1">·</span>
72
+ <v-icon class="me-1" icon="mdi-share-variant"></v-icon>
73
+ <span class="subheading">45</span>
74
+ </div>
75
+ </template>
76
+ </v-list-item>
77
+ </v-card-actions>
78
+ </v-card>
79
+ '''
80
+
81
+ def myclick(event):
82
+ mycard.vote = mycard.vote + 1
83
+
84
+ data = {"vote":256}
85
+ mycard = ss.template(template, data = data, handlers = {"myclick":myclick})
86
+
87
+ def increment(event):
88
+ mycard.vote = mycard.vote + 1
89
+ #mycard.style = "color:red"
90
+
91
+ ss.space()
92
+ ss.button("Thumb Up", onclick=increment)
93
+
94
+ ss.space("mt-8")
95
+
96
+ ss.write('''
97
+ ---
98
+ #### 代码
99
+ ''')
100
+
101
+ ss.md('''
102
+ ```python
103
+ import simplestart as ss
104
+
105
+ def myclick(event):
106
+ mycard.vote = mycard.vote + 1
107
+
108
+ data = {"vote":256}
109
+ mycard = ss.template(template, data = data, handlers = {"myclick":myclick})
110
+
111
+ def increment(event):
112
+ mycard.vote = mycard.vote + 1
113
+ #mycard.style = "color:red"
114
+
115
+ ss.space()
116
+ ss.button("Thumb Up", onclick=increment)
117
+ ```
118
+ ''')
119
+
120
+ ss.space("mt-8")
121
+
122
+
123
+ ss.md('''
124
+ ::: tip
125
+ 组件内对于data的变化如果需要传递到后端,需要显示地调用syncdata或者onserver事件。
126
+ 如上面例子中的 onchange="syncdata", 就是当用户改变了颜色后,将data的值传到python后端。
127
+ :::
128
+ ''')
129
+
130
+ def onPageEnter():
131
+ ss.session["counter"] = 0
132
+ ss.session["xxxx"] = 1
133
+
locales/zh/pages/006 Advanced Usage/demo_when.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### ss.when 条件语句
2
+ import simplestart as ss
3
+
4
+ ss.md('''
5
+ ## ss.when 条件语句
6
+ ''')
7
+
8
+ ss.space()
9
+ ss.md('''
10
+ #### 🔅 示例
11
+ ''')
12
+
13
+ #api
14
+ def increment(event):
15
+ ss.session["counter"] += 1
16
+
17
+ def decrement(event):
18
+ ss.session["counter"] -= 1
19
+
20
+
21
+ #conditional func
22
+ def conditioner(event):
23
+ #print("event", event)
24
+ if event["flag"] == 1:
25
+ if ss.session["counter"] >= 5:
26
+ return True
27
+ else:
28
+ return False
29
+ elif event["flag"] == 2:
30
+ return (ss.session["viewcode"] == 1)
31
+
32
+
33
+ # State initialisation
34
+ ss.session["counter"] = 0
35
+ ss.session["viewcode"] = 0
36
+
37
+ #ui
38
+ ss.text("The count is @counter.")
39
+
40
+ ss.button("Increment", onclick=increment)
41
+ ss.button("Decrement", onclick=decrement)
42
+
43
+ ss.write("当counter大于5时,下面将出现新的内容")
44
+
45
+ with ss.when(conditioner, flag = 1): # Conditional rendering
46
+ ss.text("Well done on reaching 5 👋🌷🍾")
47
+
48
+ ss.write("当counter小于5时,新的内容会隐藏")
49
+
50
+
51
+ ss.space()
52
+
53
+ ss.write("#### 🔎 代码")
54
+ ss.write("---")
55
+
56
+ def viewcode():
57
+ ss.session["viewcode"] = 1
58
+
59
+ ss.button("查看", size="small", onclick = viewcode)
60
+
61
+ with ss.when(conditioner, flag = 2):
62
+ ss.md('''
63
+ ```python
64
+ import simplestart as ss
65
+
66
+ #api
67
+ def increment(event):
68
+ ss.session["counter"] += 1
69
+
70
+ def decrement(event):
71
+ ss.session["counter"] -= 1
72
+
73
+
74
+ #conditional func
75
+ def conditioner(event):
76
+ return (ss.session["counter"] >= 5)
77
+
78
+ # State initialisation
79
+ ss.session["counter"] = 0
80
+ ss.session["viewcode"] = 0
81
+
82
+ #ui
83
+ ss.text("The count is @counter.")
84
+
85
+ ss.button("Increment", onclick=increment)
86
+ ss.button("Decrement", onclick=decrement)
87
+
88
+ ss.write("当counter大于5时,下面将出现新的内容")
89
+
90
+ with ss.when(conditioner, flag = 1): # Conditional rendering
91
+ ss.text("Well done on reaching 5 👋🌷🍾")
92
+
93
+ ss.write("当counter小于5时,新的内容会隐藏")
94
+ ```
95
+ ''')
96
+
97
+ ss.md('''
98
+ ::: tip
99
+ 上面的代码查看也是用ss.when实现的
100
+ :::
101
+ ''')
locales/zh/pages/006 Advanced Usage/folder.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"alias":"高级用法"}
locales/zh/system/.ipynb_checkpoints/config-checkpoint.yaml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ title: "SimpleStart 演示"
2
+
3
+ show_sidebar: true
4
+ wide_screen_mode : true
5
+
6
+ show_header: false
7
+ app_bar_height: 59 ##default is 64
8
+
9
+ show_footer: false
10
+
11
+
12
+ locales:
13
+ - code: ""
14
+ name: "English"
15
+ - code: "zh"
16
+ name: "Chinese 中文"
locales/zh/system/config.yaml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ title: "SimpleStart 演示"
2
+
3
+ show_sidebar: true
4
+ wide_screen_mode : true
5
+
6
+ show_header: false
7
+ app_bar_height: 59 ##default is 64
8
+
9
+ show_footer: false
10
+
11
+
12
+ locales:
13
+ - code: ""
14
+ name: "English"
15
+ - code: "zh"
16
+ name: "Chinese 中文"