test2023h5 commited on
Commit
2eb7877
·
verified ·
1 Parent(s): b087ad4

Delete pages

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. pages/.DS_Store +0 -0
  2. pages/002 Form Component/demo_button.py +0 -149
  3. pages/002 Form Component/demo_checkbox.py +0 -77
  4. pages/002 Form Component/demo_dialog.py +0 -78
  5. pages/002 Form Component/demo_expander.py +0 -29
  6. pages/002 Form Component/demo_menu.py +0 -100
  7. pages/002 Form Component/demo_radio.py +0 -94
  8. pages/002 Form Component/demo_selectbox.py +0 -78
  9. pages/002 Form Component/demo_slider.py +0 -35
  10. pages/002 Form Component/demo_textarea.py +0 -45
  11. pages/002 Form Component/demo_textinput.py +0 -65
  12. pages/002 Form Component/demo_upload.py +0 -40
  13. pages/003 Content Display/demo_audio.py +0 -39
  14. pages/003 Content Display/demo_html.py +0 -49
  15. pages/003 Content Display/demo_image.py +0 -92
  16. pages/003 Content Display/demo_markdown.py +0 -57
  17. pages/003 Content Display/demo_message.py +0 -37
  18. pages/003 Content Display/demo_sqlite.py +0 -39
  19. pages/003 Content Display/demo_table.py +0 -249
  20. pages/003 Content Display/demo_text.py +0 -35
  21. pages/003 Content Display/demo_video.py +0 -36
  22. pages/003 Content Display/demo_write.py +0 -78
  23. pages/004 Chart Data/demo_bokeh.py +0 -128
  24. pages/004 Chart Data/demo_pyplot.py +0 -130
  25. pages/005 Layout Related/demo_columns.py +0 -100
  26. pages/005 Layout Related/demo_row.py +0 -102
  27. pages/005 Layout Related/demo_section.py +0 -81
  28. pages/005 Layout Related/demo_sidebar.py +0 -53
  29. pages/005 Layout Related/demo_style.py +0 -64
  30. pages/005 Layout Related/demo_tabs.py +0 -35
  31. pages/006 Advanced Usage/demo_component.py +0 -101
  32. pages/006 Advanced Usage/demo_loadvue.py +0 -131
  33. pages/006 Advanced Usage/demo_onload.py +0 -46
  34. pages/006 Advanced Usage/demo_session.py +0 -21
  35. pages/006 Advanced Usage/demo_template.py +0 -158
  36. pages/006 Advanced Usage/demo_when.py +0 -101
  37. pages/Advanced_Usage/demo_chat.py +0 -33
  38. pages/Advanced_Usage/demo_component.py +0 -104
  39. pages/Advanced_Usage/demo_loadvue.py +0 -134
  40. pages/Advanced_Usage/demo_onload.py +0 -49
  41. pages/Advanced_Usage/demo_session.py +0 -134
  42. pages/Advanced_Usage/demo_template.py +0 -160
  43. pages/Advanced_Usage/demo_when.py +0 -104
  44. pages/Advanced_Usage/folder.yaml +0 -2
  45. pages/Chart_Data/demo_bokeh.py +0 -132
  46. pages/Chart_Data/demo_pyplot.py +0 -134
  47. pages/Chart_Data/folder.yaml +0 -2
  48. pages/Content_Display/demo_audio.py +0 -76
  49. pages/Content_Display/demo_html.py +0 -52
  50. pages/Content_Display/demo_image.py +0 -103
pages/.DS_Store DELETED
Binary file (8.2 kB)
 
pages/002 Form Component/demo_button.py DELETED
@@ -1,149 +0,0 @@
1
- ### Button
2
- import simplestart as ss
3
-
4
- ss.md('''
5
- ## ss.button
6
- ''')
7
- ss.md('''
8
- [Online Help](https://www.simplestart.cc/doc_form/ss-button.html)
9
- ''')
10
- ss.space()
11
- ss.md('''
12
- #### 🔅 Example
13
- ''')
14
-
15
-
16
- def testme():
17
- #ss.openpage("002 Form Component/demo_button", lang="zh")
18
- #ss.openpage("main", lang="zh")
19
- ss.send_message("change_locale", {"locale":"zh"});
20
-
21
- ss.button("testme", onclick = testme)
22
-
23
- #Custom Function
24
- def myclick():
25
- mytext.text = "You clicked "
26
-
27
- def reset():
28
- mytext.text = "This is button"
29
- but1.type = ""
30
- ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
31
- ss.getcm().components[but1.id]["content"]["options"]["endicon"] = ""
32
- ss.getcm().components[but1.id]["content"]["options"]["icon_color"] = "mediumseagreen"
33
- ss.getcm().components[but1.id]["content"]["options"]["style"] = "background-color:initial;color:initial"
34
- ss.session["iconstr"] = ''
35
- ss.session["style_str"] = ''
36
- ss.session["style"] = ''
37
-
38
-
39
- #Basic Usage
40
- cols = ss.columns([40,"flex:60"], design=True)
41
- with cols[0]:
42
- mytext = ss.text("This is button")
43
- but1 = ss.button("Click it", icon = "mdi-account-circle", onclick=myclick)
44
-
45
- def onradiochange(event):
46
- value = event.value
47
- if value == "default":
48
- but1.type = ""
49
- ss.session["buttonstyle"] = ""
50
- elif value == "outlined":
51
- but1.type = "outlined"
52
- ss.session["buttonstyle"] = 'type = "outlined\",'
53
- elif value == "flat":
54
- but1.type = "tonal"
55
- ss.session["buttonstyle"] = 'type = "flat\",'
56
- elif value == "text":
57
- but1.type = "text"
58
- ss.session["buttonstyle"] = 'type = "text\",'
59
- elif value == "plain":
60
- but1.type = "plain"
61
- ss.session["buttonstyle"] = 'type = "plain\",'
62
-
63
- def oncheckbox_change(state, value):
64
- if value == True:
65
- ss.getcm().components[but1.id]["content"]["options"]["icon"] = "aim"
66
- ss.session["iconstr"] = ' icon="search",'
67
- else:
68
- ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
69
- ss.session["iconstr"] = ''
70
- but1.update()
71
-
72
- def onradiochange2(event):
73
- index = event.index
74
-
75
- if index == 0:
76
- ss.getcm().components[but1.id]["content"]["options"]["icon"] = "mdi-account-circle"
77
- ss.getcm().components[but1.id]["content"]["options"]["endIcon"] = ""
78
- ss.session["iconstr"] = ' icon="mdi-account-circle",'
79
- elif index == 1:
80
- ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
81
- ss.getcm().components[but1.id]["content"]["options"]["endIcon"] = "mdi-alert"
82
- ss.session["iconstr"] = ' endIcon="mdi-alert",'
83
- else:
84
- ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
85
- ss.getcm().components[but1.id]["content"]["options"]["endIcon"] = ""
86
- ss.session["iconstr"] = ''
87
- but1.update()
88
-
89
-
90
- def changeColor(bkcolor):
91
- ss.getcm().components[but1.id]["content"]["options"]["style"] = f"background-color:{bkcolor}; color:white"
92
- ss.getcm().components[but1.id]["content"]["options"]["icon_color"] = "white"
93
- ss.session["style_str"] = f'style="background-color:{bkcolor}, color:white"'
94
- ss.session["style"] = 'style=style,'
95
- but1.update()
96
-
97
-
98
- with cols[1]:
99
- ss.text("Test")
100
-
101
- ss.write("---")
102
- ss.radio(["default", "outlined", "flat", "text", "plain"], "default", inline = True, onchange=onradiochange)
103
-
104
- ss.write("---")
105
- ss.radio([(1, "Icon(Prepend)"), (2, "Icon(Append)"), (3, "No Icon")], inline = True, onchange=onradiochange2)
106
-
107
-
108
- ss.write("---")
109
- ss.button("", type = "flat", size = "small", style="background-color:#409eff", onclick=lambda:changeColor('#409eff'))
110
- ss.button("", type = "flat", size = "small", style="background-color:#67c23a", onclick=lambda:changeColor('#67c23a'))
111
- ss.button("", type = "flat", size = "small", style="background-color:#e6a23c", onclick=lambda:changeColor('#e6a23c'))
112
- ss.button("", type = "flat", size = "small", style="background-color:#f56c6c", onclick=lambda:changeColor('#f56c6c'))
113
- ss.button("", type = "flat", size = "small", style="background-color:#909399", onclick=lambda:changeColor('#909399'))
114
-
115
-
116
- ss.space()
117
- ss.button("Reset", onclick=reset)
118
-
119
-
120
- ss.space("mt-8")
121
-
122
- ss.write("#### 🔎 Code")
123
-
124
- ss.md('''
125
- ```python
126
- import simplestart as ss
127
-
128
- def clickme():
129
- mytext.text = "You clicked"
130
-
131
- mytext = ss.text("This is button")
132
- @style_str
133
- ss.button("Click it", @buttonstyle @iconstr @style onclick=clickme)
134
- ```
135
- ''')
136
-
137
- ss.md('''
138
- ::: tip
139
- Function Call
140
- ss.button(label, type, color, size, icon, onclick)
141
- :::
142
- ''')
143
-
144
- def onPageLoad():
145
- ss.session["buttonstyle"] = ""
146
- ss.session["iconstr"] = ""
147
- ss.session["style"] = ""
148
- ss.session["style_str"] = ""
149
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/002 Form Component/demo_checkbox.py DELETED
@@ -1,77 +0,0 @@
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
- #### 🔅 Example 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
- #### 🔎 Code
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
- #### 🔅 Example 2
46
- Get the status of the checkbox
47
- ''')
48
-
49
- mycheck = ss.checkbox("check me", onchange = onchange)
50
-
51
- def myclick():
52
- ss.message(mycheck.value)
53
-
54
- ss.button("Get Status", onclick = myclick)
55
-
56
- ss.space()
57
- ss.write('''
58
- ---
59
- #### 🔎 Code
60
- ''')
61
-
62
-
63
- ss.md('''
64
- ```python
65
- import simplestart as ss
66
-
67
- mycheck = ss.checkbox("check me", onchange = onchange)
68
-
69
- def myclick():
70
- ss.message(mycheck.value)
71
-
72
- ss.button("获取状态", onclick = myclick)
73
-
74
- ''')
75
-
76
- def onPageLoad():
77
- ss.session["checked_value"] = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/002 Form Component/demo_dialog.py DELETED
@@ -1,78 +0,0 @@
1
- ### Dialog
2
- import simplestart as ss
3
-
4
- ss.md("## ss.dialog")
5
-
6
- ss.space()
7
-
8
- ss.md('''
9
- ---
10
- #### 🔅 Example
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("Dialog Title", 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("Dialog Options")
46
- ss.checkbox("Fullscreen", onchange=mycheck)
47
-
48
- ss.space()
49
- ss.write('''
50
- ---
51
- #### 🔎 Code
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="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
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/002 Form Component/demo_expander.py DELETED
@@ -1,29 +0,0 @@
1
- ### Expander
2
- import streamsync as ss
3
-
4
- ss.md("## ss.expander")
5
-
6
- ss.md('''
7
- #### 🔅 Example
8
- ''')
9
-
10
- with ss.expander("About SimpleStart", expanded=True):
11
- ss.text("Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi, ratione debitis quis est labore voluptatibus! \
12
- Eaque cupiditate minima, at placeat totam, magni doloremque veniam neque porro libero rerum unde voluptatem!", style="padding:10px")
13
-
14
- ss.space()
15
- ss.write('''
16
- ---
17
- #### 🔎 Code
18
- ''')
19
-
20
- ss.md('''
21
- ```python
22
- import simplestart as ss
23
-
24
- with ss.expander("About SimpleStart"):
25
- ss.text("Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi, ratione debitis quis est labore voluptatibus! \
26
- Eaque cupiditate minima, at placeat totam, magni doloremque veniam neque porro libero rerum unde voluptatem!")
27
-
28
- ```
29
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/002 Form Component/demo_menu.py DELETED
@@ -1,100 +0,0 @@
1
- ### Menu
2
- import streamsync as ss
3
-
4
- ss.md("## ss.menu")
5
-
6
- ss.md('''
7
- #### 🔅 Example
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("### Horiontal Menu")
42
- ss.menu(data, direction = "horizontal", onselect = menu_select)
43
-
44
- ss.space()
45
- ss.md("### Vertical Menu")
46
-
47
- ss.menu(data, direction = "vertical", dark = True, onselect = menu_select)
48
-
49
-
50
- ss.space()
51
- ss.write('''
52
- ---
53
- #### 🔎 Code
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
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/002 Form Component/demo_radio.py DELETED
@@ -1,94 +0,0 @@
1
- ### Radio
2
- import simplestart as ss
3
-
4
- ss.md("## ss.radio")
5
-
6
- ss.space()
7
-
8
- ss.md('''
9
- #### 🔅 Example
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("#### 🔎 Code")
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
- #### 🔅 Example - Get State Value
63
- ''')
64
-
65
- def myclick1():
66
- ss.message(myradio.value)
67
-
68
- ss.button("Get State Value", onclick=myclick1)
69
-
70
- def myclick2():
71
- ss.message(myradio.index)
72
-
73
- ss.button("Get State Index", onclick=myclick2)
74
-
75
- ss.write("---")
76
- ss.write("#### 🔎 Code Snippet")
77
-
78
- ss.md('''
79
- ```python
80
- #...
81
- def myclick1():
82
- ss.message(myradio.value)
83
-
84
- ss.button("Get State Value", onclick=myclick1)
85
-
86
- def myclick2():
87
- ss.message(myradio.index)
88
-
89
- ss.button("Get State Index", onclick=myclick2)
90
- ''')
91
-
92
-
93
- def onPageLoad():
94
- ss.session["options_value"] = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/002 Form Component/demo_selectbox.py DELETED
@@ -1,78 +0,0 @@
1
- ### Selectbox
2
- import simplestart as ss
3
-
4
- ss.md("## ss.selectbox")
5
-
6
- ss.space()
7
- ss.md('''
8
- #### 🔅 Example 1
9
- Create a selectbox with a title and 3 options on the page.
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("#### 🔎 Code")
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
- #### 🔅 Example 2
43
- Get the current option of the selectbox. In addition to obtaining the user's selected option information through the event's index and value in the selectbox's onchange event, you can also get the user's selection information via the selectbox variable.
44
- ''')
45
- ss.space()
46
-
47
- def onclick1():
48
- ss.message(select1.value)
49
-
50
- ss.button("Current Option Value", onclick=onclick1)
51
-
52
- def onclick2():
53
- ss.message(select1.index)
54
-
55
- ss.button("Current Option Index", onclick=onclick2)
56
-
57
- ss.space()
58
-
59
- ss.write("#### 🔎 Code Snippet")
60
-
61
-
62
- ss.md("""
63
- ```python
64
-
65
- #...
66
-
67
- def onclick1():
68
- ss.message(select1.value)
69
-
70
- ss.button("Current Option Value", onclick = onclick1)
71
-
72
- def onclick2():
73
- ss.message(select1.index)
74
-
75
- ss.button("Current Option Index", onclick = onclick2)
76
-
77
- ```
78
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/002 Form Component/demo_slider.py DELETED
@@ -1,35 +0,0 @@
1
- ### Slider
2
- import simplestart as ss
3
-
4
- ss.md("## ss.slider")
5
-
6
- ss.space()
7
-
8
- ss.md('''
9
- #### 🔅 Example
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("#### 🔎 Code")
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
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/002 Form Component/demo_textarea.py DELETED
@@ -1,45 +0,0 @@
1
- ### Textarea
2
- import streamsync as ss
3
-
4
- ss.md("## ss.textarea")
5
-
6
- ss.space()
7
- ss.md("#### 🔅 Example")
8
-
9
- ss.md("---")
10
-
11
- # Basic usage
12
- # test = ss.text_input("hello, world", type="textarea")
13
- mytext = ss.textarea("hello, world")
14
-
15
- ss.write("---")
16
- ss.write("#### 🔎 Code")
17
-
18
- ss.md('''
19
- ```python
20
- import simplestart as ss
21
-
22
- mytext = ss.textarea("hello, world")
23
-
24
- ''')
25
-
26
- ss.space()
27
- ss.md("#### 🔅 Get the text value of the textarea")
28
- ss.md("---")
29
-
30
- def myclick():
31
- ss.message(mytext.value)
32
-
33
- ss.button("Get Text", onclick=myclick)
34
-
35
- ss.write("---")
36
- ss.write("#### 🔎 Code Snippet")
37
-
38
- ss.md('''
39
- ```python
40
- #...
41
- def myclick():
42
- ss.message(mytext.value)
43
-
44
- ss.button("Get Text", onclick=myclick)
45
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/002 Form Component/demo_textinput.py DELETED
@@ -1,65 +0,0 @@
1
- ### Text_input
2
- import streamsync as ss
3
-
4
-
5
- ss.md("## ss.text_input")
6
-
7
- ss.space()
8
- ss.md("#### 🔅 Example")
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">Get Input Value</span>')
49
- ss.button("Get Text Value", onclick=myevent, eventTag="but1")
50
-
51
-
52
-
53
- ss.write("---")
54
- ss.write("#### 🔎 Code")
55
-
56
- ss.md('''
57
- ```python
58
- import simplestart as ss
59
-
60
- myinput = ss.text_input("Hello SimpleStart", clearable=True)
61
-
62
- #Or
63
- #ss.text_input("hello", type="text", variant = "filled")
64
-
65
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/002 Form Component/demo_upload.py DELETED
@@ -1,40 +0,0 @@
1
- ### File Upload
2
- import streamsync as ss
3
- import pandas as pd
4
-
5
- ss.md("## ss.upload File Upload")
6
-
7
-
8
- ss.space()
9
- ss.md("#### 🔅 Example - Upload Image")
10
- ss.space()
11
-
12
-
13
- def onsucess(event):
14
- filename = event.value
15
- path = f'{ss.baseinfo["package_path"]}/uploads/{filename}'
16
- myimage.image = path
17
-
18
- ss.upload("Upload Image ...", accept="image/png, image/jpeg, image/bmp", icon="mdi-camera", onsucess = onsucess)
19
-
20
- myimage = ss.image()
21
-
22
- ss.space()
23
- ss.write("---")
24
- ss.write("#### 🔎 Code")
25
-
26
- ss.md('''
27
- ```python
28
- import simplestart as ss
29
-
30
- def onsucess(event):
31
- filename = event.value
32
- path = f'{ss.baseinfo["package_path"]}/uploads/{filename}'
33
-
34
- myimage.image = path
35
-
36
- ss.upload(label = "Upload Image ...", accept="image/png, image/jpeg, image/bmp", icon="mdi-camera", onsucess = onsucess)
37
-
38
- myimage = ss.image()
39
-
40
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/003 Content Display/demo_audio.py DELETED
@@ -1,39 +0,0 @@
1
- ### Audio Playback
2
- import streamsync as ss
3
-
4
- ss.md("## ss.audio")
5
-
6
-
7
- ss.space()
8
- ss.md('''
9
- #### 🔅 Example
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
- #### 🔎 Code
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 supports audio formats including wav, mp3, etc.
38
- :::
39
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/003 Content Display/demo_html.py DELETED
@@ -1,49 +0,0 @@
1
- ### Html Hypertext
2
- import streamsync as ss
3
-
4
-
5
- ss.md("## ss.html")
6
-
7
- ss.space("")
8
-
9
- ss.md('''
10
- #### 🔅 Example
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
- #### 🔎 Code
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
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/003 Content Display/demo_image.py DELETED
@@ -1,92 +0,0 @@
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
- #### 🔅 Example
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
- #### 🔎 Code
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\""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/003 Content Display/demo_markdown.py DELETED
@@ -1,57 +0,0 @@
1
- ### Markdown
2
- import simplestart as ss
3
-
4
- ss.md("## ss.markdown")
5
-
6
- ss.space()
7
-
8
- ss.md('''
9
- #### 🔅 Example
10
- ''')
11
-
12
- ss.space()
13
-
14
- ss.markdown("- 19^th^")
15
- ss.markdown("# Heading 1")
16
- ss.markdown("## Heading 2")
17
- ss.markdown("### Heading 3")
18
-
19
- #Horizontal Divider
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
- #### 🔎 Code
37
- ''')
38
-
39
- ss.md('''
40
- ```python
41
- import simplestart as ss
42
-
43
- ss.markdown("# Heading 1")
44
- ss.markdown("## Heading 2")
45
- ss.markdown("### Heading 3")
46
-
47
- #Horizontal Divider
48
- ss.markdown("---")
49
-
50
- ss.markdown(\'''
51
- - list item1
52
- - list item2
53
- - list item3
54
- \''')
55
-
56
- ```
57
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/003 Content Display/demo_message.py DELETED
@@ -1,37 +0,0 @@
1
- ### Message
2
- import simplestart as ss
3
-
4
- ss.md("## ss.message Popup Message")
5
-
6
- ss.space()
7
-
8
-
9
- ss.md('''
10
- #### 🔅 Example
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
- #### 🔎 Code
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
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/003 Content Display/demo_sqlite.py DELETED
@@ -1,39 +0,0 @@
1
- ### Sqlite Database
2
- import simplestart as ss
3
-
4
- ss.md("## ss.sqlite Database")
5
-
6
- ss.space()
7
- ss.md('''
8
- Provides simple operations for the SQLite database.
9
- ''')
10
-
11
- ss.space()
12
- ss.md('''
13
- #### 🔅 Example
14
- ''')
15
-
16
- ss.md('''
17
- ::: tip
18
- This example reads the Iris dataset from the SQLite database and displays it in a CSV table format.
19
- For SQLite management, simplestart offers a built-in tool for simple create, read, update, and delete operations.
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("#### Code")
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
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/003 Content Display/demo_table.py DELETED
@@ -1,249 +0,0 @@
1
- ### Table
2
- import simplestart as ss
3
- import pandas as pd
4
-
5
- ss.md("## ss.table Table Data")
6
-
7
- ss.md("Display data in table format.")
8
-
9
- ss.space()
10
-
11
- ss.md('''
12
- #### 🔅 Example
13
- ''')
14
-
15
- def onchange_index(event):
16
- value = event.value
17
-
18
- if value == True:
19
- ss.getcm().components[mytable.id]["content"]["index"] = True
20
- ss.session["showIndex"] = ', index = True'
21
- else:
22
- ss.getcm().components[mytable.id]["content"]["index"] = False
23
- ss.session["showIndex"] = ''
24
- mytable.update()
25
-
26
- def onchange_border(event):
27
- value = event.value
28
-
29
- if value == True:
30
- ss.getcm().components[mytable.id]["content"]["border"] = True
31
- ss.session["showBorder"] = ', border = True'
32
- else:
33
- ss.getcm().components[mytable.id]["content"]["border"] = False
34
- ss.session["showBorder"] = ''
35
- mytable.update()
36
-
37
-
38
- def onchange_sortable(event):
39
- value = event.value
40
-
41
- if value == True:
42
- ss.getcm().components[mytable.id]["content"]["sortable"] = True
43
- ss.session["sortable"] = ', sortable = True'
44
- else:
45
- ss.getcm().components[mytable.id]["content"]["sortable"] = False
46
- ss.session["sortable"] = ''
47
- mytable.update()
48
-
49
- def onchange_searchable(event):
50
- value = event.value
51
-
52
- if value == True:
53
- ss.getcm().components[mytable.id]["content"]["searchable"] = True
54
- ss.session["searchable"] = ', searchable = True'
55
- else:
56
- ss.getcm().components[mytable.id]["content"]["searchable"] = False
57
- ss.session["searchable"] = ''
58
- mytable.update()
59
-
60
-
61
- def onchange_selectable(event):
62
- value = event.value
63
-
64
- if value == True:
65
- ss.getcm().components[mytable.id]["content"]["selectable"] = True
66
- ss.session["selectable"] = ', selectable = True'
67
- else:
68
- ss.getcm().components[mytable.id]["content"]["selectable"] = False
69
- ss.session["selectable"] = ''
70
- mytable.update()
71
-
72
- def onchange_editable(event):
73
- value = event.value
74
-
75
- if value == True:
76
- ss.getcm().components[mytable.id]["content"]["editable"] = True
77
- ss.session["editable"] = ', editable = True'
78
- else:
79
- ss.getcm().components[mytable.id]["content"]["editable"] = False
80
- ss.session["editable"] = ''
81
- mytable.update()
82
-
83
-
84
- def current_change(state, value):
85
- ss.session["row_selected"] = value["index"]
86
-
87
- def selection_change(state, value):
88
- ss.session["selection_change"] = value["selected"]
89
-
90
-
91
- # Create a dataset with three columns
92
- data = {'name': ['👧🏻 Alice', '👦🏻 Bob', '👦🏻 Charlie'],
93
- 'age': [25, 30, 35],
94
- 'city': ['New York', 'San Francisco', 'Los Angeles'],
95
- 'health':[90,80,90]
96
- }
97
-
98
- df = pd.DataFrame(data)
99
-
100
- def rowclicked(event):
101
- #ss.message("row clicked")
102
- #ss.write("event", event)
103
- ss.session["itemname"] = event.value["name"]
104
-
105
-
106
- cols = ss.columns([70,"flex:30; border-left:1px solid lightgray"], design=True, style="border:1px solid lightgray")
107
- with cols[0]:
108
- mytable = ss.table(df, handlers={"click:row": rowclicked})
109
- ss.md("#### Events")
110
- ss.write("Row clicked: @itemname")
111
-
112
-
113
- with cols[1]:
114
- ss.text("setting")
115
- ss.checkbox("Index", onchange = onchange_index)
116
- ss.space()
117
- ss.checkbox("Border", onchange = onchange_border)
118
- ss.space()
119
- ss.checkbox("Sort", onchange = onchange_sortable)
120
- ss.space()
121
- ss.checkbox("Select", onchange = onchange_selectable)
122
- ss.space()
123
- ss.checkbox("Search", onchange = onchange_searchable)
124
- ss.space()
125
- ss.checkbox("Edit", onchange = onchange_editable)
126
-
127
- ss.space("mt-8")
128
-
129
- ss.write('''
130
- ---
131
- #### 🔎 Code
132
- ''')
133
-
134
- ss.md('''
135
- ```python
136
- import simplestart as ss
137
-
138
- def current_change(state, value):
139
- ss.session["row_selected"] = value["index"]
140
-
141
- def selection_change(state, value):
142
- ss.session["selection_change"] = value["selected"]
143
-
144
- data = {'name': ['Alice', 'Bob', 'Charlie'],
145
- 'age': [25, 30, 35],
146
- 'city': ['New York', 'San Francisco', 'Los Angeles']}
147
- df = pd.DataFrame(data)
148
-
149
- ss.table(df, handlers={\"current-change\":current_change, \"selection-change\":selection_change})
150
- ss.md(\"#### Events\")
151
- ss.write(\"Row selected: \")
152
- ss.write(\"Selection changed: \")
153
-
154
- def onPageLoad():
155
- ss.session["row_selected"] = ''
156
- ss.session["selection_change"] = ''
157
-
158
- ```
159
- ''')
160
-
161
-
162
- ss.md('''
163
- ---
164
- #### 🔅 Example - Custom column.
165
- ''')
166
-
167
-
168
- data = {'name': ['👧🏻 Alice', '👦🏻 Bob', '👦🏻 Charlie'],
169
- 'age': [25, 30, 35],
170
- 'city': [':sunny: New York', ':cloud: San Francisco', ':sunny: Los Angeles'],
171
- 'health':[90,80,90]
172
- }
173
-
174
- df = pd.DataFrame(data)
175
-
176
- cols = ss.columns([70,"flex:30; border-left:1px solid lightgray"], design=True, style="border:1px solid lightgray")
177
-
178
-
179
- vuecode = '''
180
- <template>
181
- <v-clip>123</v-clip>
182
- </template>
183
- '''
184
-
185
- vuecode = "../components/mycell.vue"
186
-
187
- #mytable_ex = ss.table(df, custom_columns = ["city"], custom_columns_template = vuestr)
188
- with cols[0]:
189
- mytable_ex = ss.table(df, custom_columns = ["city"], vue_columns = ["health"], vue_code = vuecode)
190
- with cols[1]:
191
- ss.write("Each column can be customized for display.")
192
-
193
- ss.space("mt-8")
194
-
195
- ss.write('''
196
- ---
197
- #### 🔎 代码
198
- ''')
199
-
200
- ss.md('''
201
- ```python
202
- import simplestart as ss
203
-
204
- data = {'name': ['👧🏻 Alice', '👦🏻 Bob', '👦🏻 Charlie'],
205
- 'age': [25, 30, 35],
206
- 'city': [':sunny: New York', ':cloud: San Francisco', ':sunny: Los Angeles'],
207
- 'health':[90,80,90]
208
- }
209
- df = pd.DataFrame(data)
210
-
211
- vuestr = \'''
212
- <template>
213
- <v-row>
214
- <v-rating
215
- v-model="rating" density="compact" color="orange" half-increments></v-rating>
216
- <v-chip variant="text">{{item.value}}</v-chip>
217
- </v-row>
218
- </template>
219
-
220
- <script>
221
-
222
- module.exports = {
223
- props:["item"],
224
-
225
- data () {
226
- return {
227
- rating: 3
228
- }
229
- },
230
- methods: {
231
- //todo
232
- },
233
- mounted: function () {
234
- this.rating = this.item.value/20
235
- },
236
- }
237
- </script>
238
- \'''
239
-
240
- ss.table(df, custom_columns = ["city"], vue_columns = ["health"], vue_code = vuecode)
241
- ```
242
- ''')
243
-
244
- def onPageLoad():
245
- ss.session["show_border"] = ''
246
- ss.session["selectable"] = ''
247
- ss.session["sortable"] = ''
248
- ss.session["row_selected"] = ''
249
- ss.session["selection_change"] = ''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/003 Content Display/demo_text.py DELETED
@@ -1,35 +0,0 @@
1
- ### Text
2
- import streamsync as ss
3
-
4
- ss.md("## ss.text Text")
5
- ss.md("Supports the style parameter.")
6
-
7
-
8
- ss.space()
9
- ss.space()
10
- ss.md('''
11
- #### 🔅 Example
12
- ''')
13
-
14
- ss.md("---")
15
-
16
- #Basic usage
17
- test = ss.text("hello, world")
18
-
19
- #Change color
20
- ss.text("This is a red string", style="color:red")
21
-
22
- ss.space()
23
- ss.write("#### 🔎 Code")
24
-
25
- ss.md('''
26
- ```python
27
- import simplestart as ss
28
-
29
- #Basic usage
30
- test = ss.text("hello, world")
31
-
32
- #Change color
33
- ss.text("This is a red string", style="color:red")
34
- ```
35
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/003 Content Display/demo_video.py DELETED
@@ -1,36 +0,0 @@
1
- ### Video Playback
2
- import streamsync as ss
3
-
4
- ss.md("## ss.video Video Playback")
5
-
6
- ss.md("Supports playing videos in formats like mp4.")
7
-
8
- ss.md('''
9
- #### 🔅 Example
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("Source: https://media.w3.org/2010/05/sintel/trailer.mp4", style="color:gray")
17
-
18
- ss.space("mt-8")
19
-
20
- ss.write('''
21
- ---
22
- #### 🔎 Code
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
- #Change video source
34
- #player.src = "..."
35
- ```
36
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/003 Content Display/demo_write.py DELETED
@@ -1,78 +0,0 @@
1
- ### Write
2
-
3
- import streamsync as ss
4
- import pandas as pd
5
-
6
- ss.md("## ss.write Output Data")
7
-
8
- ss.md("ss.write is similar to print; it can output text, lists, and other types, making testing and output easy.")
9
-
10
- ss.space()
11
-
12
- ss.md('''
13
- #### 🔅 Example
14
- ''')
15
-
16
-
17
- ss.md("#### 1. Output Text")
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. Output Multiple Variables")
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. Output List")
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. Output Table")
58
- # 创建数据
59
- data = {'name': ['Alice', 'Bob', 'Charlie', 'David'],
60
- 'age': [25, 30, 35, 40],
61
- 'city': ['New York', 'Paris', 'London', 'Sydney']}
62
-
63
- # Convert data to DataFrame format
64
- df = pd.DataFrame(data)
65
- ss.write(df)
66
-
67
- ss.md('''
68
- ```python
69
- # Create data
70
- data = {'name': ['Alice', 'Bob', 'Charlie', 'David'],
71
- 'age': [25, 30, 35, 40],
72
- 'city': ['New York', 'Paris', 'London', 'Sydney']}
73
-
74
- # Convert data to DataFrame format
75
- df = pd.DataFrame(data)
76
- ss.write(df)
77
- ```
78
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/004 Chart Data/demo_bokeh.py DELETED
@@ -1,128 +0,0 @@
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
- # Load the Iris dataset
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
- # Create the data source and figure object
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
- # Create a Bokeh scatter plot
27
- p = figure(title="Iris Dataset Scatter Plot", x_axis_label='Sepal Length (cm)', y_axis_label='Sepal Width (cm)',
28
- tools="pan,wheel_zoom,box_zoom,reset,hover,save", width=800)
29
-
30
- # Set different colors based on species
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
- # Embed the Bokeh figure into SimpleStart
46
- html = file_html(p, CDN, "Iris Dataset Scatter Plot")
47
-
48
- #ui
49
- ss.md('''
50
- ## simplestart Chart Demo - Bokeh
51
- ''')
52
-
53
- ss.space()
54
- ss.md('''
55
- #### 🔅 Example
56
- An interactive scatter plot of the Iris data using Bokeh
57
- ''')
58
-
59
- ss.space()
60
- ss.htmlview(html, border = False)
61
-
62
- ss.space()
63
- ss.write("#### 🔎 Code")
64
-
65
- def viewcode():
66
- ss.session["viewcode"] = 1
67
-
68
- ss.session["viewcode"] = 0
69
- ss.button("View Code", 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
- # Load the Iris dataset
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
- # Create the data source and figure object
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
- # Create a Bokeh scatter plot
102
- p = figure(title="Iris Dataset Scatter Plot", x_axis_label='Sepal Length (cm)', y_axis_label='Sepal Width (cm)',
103
- tools="pan,wheel_zoom,box_zoom,reset,hover,save", width=800)
104
-
105
- # Set different colors based on species
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
- # Embed the Bokeh figure into SimpleStart
121
- html = file_html(p, CDN, "Iris Dataset Scatter Plot")
122
-
123
- #ui
124
- ss.htmlview(html, border = False)
125
- '''
126
-
127
- with ss.when(conditioner):
128
- ss.md(code)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/004 Chart Data/demo_pyplot.py DELETED
@@ -1,130 +0,0 @@
1
- import streamsync as ss
2
-
3
- import seaborn as sns
4
- import matplotlib as mpl
5
- import matplotlib.pyplot as plt
6
-
7
-
8
- #下载不了,所以加一个参数data_home
9
- data_home = "./data/seaborn"
10
-
11
- ss.md('''
12
- ## ss.pyplot Drawing
13
- ''')
14
-
15
-
16
- ss.space()
17
- ss.md('''
18
- #### 🔅 Example
19
- ''')
20
-
21
- ss.write("#### 1. Draw a Line Plot")
22
-
23
- sns.set_style("whitegrid")
24
- titanic = sns.load_dataset("titanic", data_home=data_home)
25
- sns.lineplot(x="age", y="fare", hue="sex", data=titanic)
26
- plt.show()
27
-
28
- fig = plt.gcf()
29
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
30
-
31
- ss.write("#### 2. Draw a Scatter Plot")
32
-
33
- sns.set_style("whitegrid")
34
- tips = sns.load_dataset("tips", data_home=data_home)
35
- sns.scatterplot(x="total_bill", y="tip", data=tips)
36
- plt.show()
37
-
38
- fig = plt.gcf()
39
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
40
-
41
- ss.write("#### 3. Draw a Bar Plot")
42
-
43
- sns.set_style("whitegrid")
44
- titanic = sns.load_dataset("titanic",data_home=data_home)
45
- sns.barplot(x="class", y="survived", data=titanic)
46
- plt.show()
47
-
48
- fig = plt.gcf()
49
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
50
-
51
-
52
- ss.write("#### 4. Draw a Histogram")
53
- sns.set_style("whitegrid")
54
- titanic = sns.load_dataset("titanic",data_home=data_home)
55
- sns.histplot(x="age", data=titanic)
56
- plt.show()
57
-
58
- fig = plt.gcf()
59
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
60
-
61
-
62
- ss.space()
63
-
64
- ss.write("#### 🔎 Code")
65
- ss.write("---")
66
-
67
- def viewcode():
68
- ss.session["viewcode"] = 1
69
-
70
- ss.button("View Code", size="small", onclick = viewcode)
71
-
72
-
73
- def conditioner(event):
74
- return ss.session["viewcode"] == 1
75
-
76
- with ss.when(conditioner):
77
- ss.md('''
78
- ```python
79
- import streamsync as ss
80
-
81
- import seaborn as sns
82
- import matplotlib as mpl
83
- import matplotlib.pyplot as plt
84
-
85
-
86
- data_home = "./data/seaborn"
87
-
88
-
89
- ss.write("#### 1. Draw a Line Plot")
90
-
91
- sns.set_style("whitegrid")
92
- titanic = sns.load_dataset("titanic", data_home=data_home)
93
- sns.lineplot(x="age", y="fare", hue="sex", data=titanic)
94
- plt.show()
95
-
96
- fig = plt.gcf()
97
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
98
-
99
- ss.write("#### 2. Draw a Scatter Plot")
100
-
101
- sns.set_style("whitegrid")
102
- tips = sns.load_dataset("tips", data_home=data_home)
103
- sns.scatterplot(x="total_bill", y="tip", data=tips)
104
- plt.show()
105
-
106
- fig = plt.gcf()
107
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
108
-
109
- ss.write("#### 3. Draw a Bar Plot")
110
-
111
- sns.set_style("whitegrid")
112
- titanic = sns.load_dataset("titanic",data_home=data_home)
113
- sns.barplot(x="class", y="survived", data=titanic)
114
- plt.show()
115
-
116
- fig = plt.gcf()
117
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
118
-
119
-
120
- ss.write("#### 4. Draw a Histogram")
121
- sns.set_style("whitegrid")
122
- titanic = sns.load_dataset("titanic",data_home=data_home)
123
- sns.histplot(x="age", data=titanic)
124
- plt.show()
125
-
126
- fig = plt.gcf()
127
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
128
- ```
129
- ''')
130
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/005 Layout Related/demo_columns.py DELETED
@@ -1,100 +0,0 @@
1
- ### Columns Layout
2
- import streamsync as ss
3
-
4
- ss.md("## ss.columns Columns Layout")
5
-
6
- ss.space()
7
- ss.md("#### 🔅 Example")
8
-
9
- ss.space()
10
-
11
- ss.md("### Average Spacing")
12
-
13
- def onchange1(event):
14
- #cols_ex1.design = True
15
- cols_ex1_id = cols1[0].id
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("#### 🔎 Code")
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
- ss.md("### Proportional Spacing")
56
-
57
-
58
- def onchange2(event):
59
- #cols_ex1.design = True
60
- cols_ex2_id = cols2[0].id
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("#### 🔎 Code")
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"] = ''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/005 Layout Related/demo_row.py DELETED
@@ -1,102 +0,0 @@
1
- ### Row Layout
2
-
3
- import streamsync as ss
4
-
5
- ss.md("## ss.row Row Layout")
6
-
7
- ss.space()
8
- ss.md("#### 🔅 Example")
9
- ss.write("Use ss.row to constrain two buttons to display on the same line, while using ss.spacer to adjust the layout of the buttons.")
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("#### 🔎 Code")
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 adds spacing, while ss.spacer is used to fill gaps to modify the layout.
101
- :::
102
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/005 Layout Related/demo_section.py DELETED
@@ -1,81 +0,0 @@
1
- ### Section
2
- import simplestart as ss
3
-
4
- ss.md("## ss.section Container")
5
-
6
- ss.md("The section parent container can hold other components and supports the style parameter.")
7
-
8
-
9
- ss.space()
10
- ss.md('''
11
- #### 🔅 Example
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("#### 🔎 Code")
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
- In addition to adding components using the with syntax, you can also directly add components within the container using section.text(), section.button(), etc.
80
- :::
81
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/005 Layout Related/demo_sidebar.py DELETED
@@ -1,53 +0,0 @@
1
- ### Sidebar
2
- import simplestart as ss
3
-
4
- ss.md("## ss.sidebar")
5
-
6
- ss.md("Display various components in the sidebar on the left side of the screen, such as data controls and some settings.")
7
-
8
- ss.md('''
9
- #### 🔅 Example
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("#### 🔎 Code")
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
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/005 Layout Related/demo_style.py DELETED
@@ -1,64 +0,0 @@
1
- ### Style
2
- import simplestart as ss
3
-
4
- ss.md("## ss.style Style Settings")
5
-
6
- ss.space()
7
- ss.md("#### 🔅 Example")
8
- ss.write("nject CSS styles into the HTML document.")
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("#### 🔎 Code")
35
-
36
-
37
- ss.space()
38
-
39
-
40
- ss.md('''
41
- ```python
42
- import simplestart as ss
43
-
44
- ss.html(\'''
45
- <div class="test1">this is a sample1</div>
46
- <div class="test2">this is a sample2</div>
47
- \''')
48
-
49
- ss.style(\'''
50
- .test1{
51
- background-color:lightgray;
52
- padding:5px;
53
- width:150px;
54
- margin-bottom:10px;
55
- border:1px solid lightblue
56
- }
57
- .test2{
58
- color:red;
59
- border:1px solid lightgreen;
60
- padding:5px;
61
- width:150px;
62
- }
63
- \''')
64
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/005 Layout Related/demo_tabs.py DELETED
@@ -1,35 +0,0 @@
1
- ### Tabs
2
- import simplestart as ss
3
-
4
- ss.md("## ss.tabs")
5
-
6
- ss.space("mt-16")
7
- ss.md("#### 🔅 Example")
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("#### 🔎 Code")
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
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/006 Advanced Usage/demo_component.py DELETED
@@ -1,101 +0,0 @@
1
- ### ss.component
2
- import simplestart as ss
3
-
4
- ss.md("### ss.component Custom Component")
5
- ss.md("You can customize components using HTML, JS, and CSS, implemented through an iframe.")
6
-
7
- ss.space()
8
- ss.md('''
9
- #### 🔅 Example
10
- ''')
11
- ss.space()
12
-
13
- def testme(state, value):
14
- mytext.text = "Data received from the frontend UI: " + value["value"]
15
-
16
- # By default, the <iframe> width is 300 pixels and the height is 150 pixels.
17
- ss.text("Enter content in the text box and press Enter.")
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("Data received from the frontend UI: ")
26
-
27
- ss.markdown("---")
28
- ss.space()
29
- ss.text("Click the button to send data to the frontend UI.")
30
- ss.button("post data", onclick=postdata)
31
-
32
- ss.space()
33
-
34
- ss.write("Python Side Code")
35
-
36
- ss.md('''
37
- ```python
38
- import simplestart as ss
39
-
40
- def testme(state, value):
41
- mytext.text = "Data received from the frontend UI: " + value["value"]
42
-
43
- ss.text("Enter content in the text box and press Enter.")
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("Data received from the frontend UI: ")
51
-
52
- ss.markdown("---")
53
-
54
- ss.space()
55
- ss.text("Click the button to send data to the frontend UI.")
56
- ss.button("post data", onclick=postdata)
57
-
58
- ```
59
- ''')
60
-
61
- ss.write("Plugin/HTML/JS Side Code")
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="Enter content and press Enter" />
73
- </body>
74
-
75
- <script>
76
- var myInput = document.getElementById("myinput");
77
-
78
- myInput.addEventListener("change", function() {
79
- //// Send message to the Python side
80
- sendDataToPython({
81
- value: myInput.value,
82
- });
83
- })
84
-
85
- //Receive messages from the Python side
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
- // If system height setting fails, you can manually set the height
95
- //setFrameHeight(200);
96
- </script>
97
-
98
- </html>
99
-
100
- ```
101
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/006 Advanced Usage/demo_loadvue.py DELETED
@@ -1,131 +0,0 @@
1
- ### ss.loadvue
2
- import simplestart as ss
3
-
4
- ss.md("## ss.loadvue Load Vue SFC")
5
-
6
- ss.space()
7
- ss.md("In SimpleStart, you can load custom Vue Single File Components using ss.loadvue, enabling property and data interaction.")
8
-
9
- ss.space()
10
-
11
- ss.space()
12
- ss.md('''
13
- #### 🔅 Example
14
-
15
- In this example, we define a simple frontend component that includes an "ontest" event. When the user clicks the "handle on server" button,
16
- the Python side's ontest event handler will process it and receive data passed from the frontend component. Meanwhile, when the "Modify Data"
17
- button on the Python side is clicked, the frontend component will respond by changing the displayed content.
18
- ''')
19
-
20
- ss.space("mt-8")
21
- ss.md("---")
22
- ss.space("mt-8")
23
-
24
- tagid = 0
25
- tags = ["Python", "Java", "Javascript"]
26
- data = {"count":0, "language":"C++"}
27
- global myvue
28
-
29
- #trigger event on server from client side
30
- def ontest(event):
31
- ss.message(event.value)
32
-
33
- #change data in client component on server side
34
- def changedata(event):
35
- global tagid
36
- myvue.data["language"] = tags[tagid]
37
- myvue.update()
38
-
39
- tagid = (tagid+1) % 3
40
-
41
- ss.text("Python Side")
42
- ss.button("Modify Data", onclick=changedata)
43
-
44
- ss.space()
45
- sec = ss.section()
46
-
47
- def onPageLoad():
48
- global myvue
49
- #load code from file
50
- with sec:
51
- ss.text("Component Side")
52
- myvue = ss.loadvue(path = "components/mycomponent.vue", data = data, handlers = {"ontest":ontest})
53
-
54
-
55
- ss.space()
56
- ss.write("Python Side Code")
57
-
58
- ss.md('''
59
- ```python
60
- import simplestart as ss
61
-
62
- tagid = 0
63
- global myvue
64
-
65
- tags = ["Python", "Java", "Javascript"]
66
- data = {"count":0, "language":"C++"}
67
-
68
-
69
- #trigger event on server from client side
70
- def ontest(state, value):
71
- ss.message(value)
72
-
73
- #change data in client component on server side
74
- def changedata(state, value=None):
75
- global tagid
76
- myvue.data["language"] = tags[tagid]
77
- tagid = (tagid+1) % 3
78
-
79
- ss.text("Python Side")
80
- ss.button("Modify Data", onclick=changedata)
81
-
82
-
83
- def onPageLoad():
84
- global myvue
85
- #load code from file
86
- myvue = ss.loadvue(path = "components/mycomponent.vue", data = data, handlers = {"ontest":ontest})
87
- ```
88
- ''')
89
-
90
-
91
- ss.space()
92
- ss.write("Vue JS Code")
93
-
94
- ss.md('''
95
- ```js
96
- <template>
97
- <div class="my-component">
98
- <h1>{{title}}: {{ data.language }}</h1>
99
- <v-btn @click="testme">handle on server</v-btn>
100
- </div>
101
- </template>
102
-
103
- <script>
104
- module.exports = {
105
- name: 'MyComponent',
106
-
107
- data() {
108
- return {
109
- title:"computer",
110
- }
111
- },
112
-
113
- methods: {
114
- testme(){
115
- this.streamsync.forwardData(this, eventname="ontest", "12345")
116
- }
117
- }
118
- }
119
- </script>
120
-
121
- <style>
122
- .my-component {
123
- width:50%;
124
- background-color: #f0f0f0;
125
- padding: 20px;
126
- margin:10px 0;
127
- }
128
- </style>
129
-
130
- ```
131
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/006 Advanced Usage/demo_onload.py DELETED
@@ -1,46 +0,0 @@
1
- ### ss.onPageEnter
2
- import simplestart as ss
3
- from datetime import datetime
4
-
5
- ss.md("## onPageEnter Page Load Event")
6
-
7
- ss.md('''
8
- ---
9
- #### 🔅 Example
10
- ''')
11
-
12
- ss.md("Every time you enter this page, the onPageEnter event function will be called, and a message will pop up above.")
13
-
14
-
15
- ss.space()
16
-
17
- mytext = ss.text("Current Time @currentime")
18
-
19
- def onPageEnter():
20
- #ss.write("test")
21
- ss.message("page enter event")
22
-
23
-
24
- # Get current time
25
- now = datetime.now()
26
- # Format time as a string
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
- #### 🔎 Code
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
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/006 Advanced Usage/demo_session.py DELETED
@@ -1,21 +0,0 @@
1
- ### ss.session
2
- import simplestart as ss
3
-
4
- ss.md("## ss.session Session Variables")
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 onPageEnter():
21
- ss.session.count = 100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/006 Advanced Usage/demo_template.py DELETED
@@ -1,158 +0,0 @@
1
- ### ss.template
2
-
3
- import simplestart as ss
4
-
5
- ss.md("## ss.template Load VUE Template")
6
-
7
- ss.space("mt-8")
8
- ss.md('''
9
- In SimpleStart, you can define simple Vue components using ss.template to achieve property and data interaction.
10
-
11
- #### Function
12
- ss.template(src, path, data, handlers)
13
-
14
- ##### Function Description
15
-
16
- | Parameter | Description |
17
- | --- | --- |
18
- | src | Component script in string format |
19
- | path | Path to the original code of the external component file |
20
- | data | Data used for interaction between frontend components and the Python backend |
21
- | handlers | Events defined in the frontend component, implemented on the Python side |
22
-
23
- ''')
24
-
25
- ss.space("mt-8")
26
-
27
-
28
- template = '''
29
- <v-card
30
- class="mx-auto text-white"
31
- color="#26c6da"
32
- max-width="400"
33
- prepend-icon="mdi-twitter"
34
- title="Twitter"
35
- >
36
- <template v-slot:prepend>
37
- <v-icon size="x-large"></v-icon>
38
- </template>
39
-
40
- <v-card-text class="text-h6 py-2">
41
- "SimpleStart is a easy way to build webpage and visualize data."
42
- </v-card-text>
43
-
44
- <v-card-actions>
45
- <v-list-item class="w-100">
46
- <template v-slot:prepend>
47
- <v-avatar
48
- color="grey-darken-3"
49
- 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"
50
- ></v-avatar>
51
- </template>
52
-
53
- <v-list-item-title>Evan You</v-list-item-title>
54
-
55
- <v-list-item-subtitle>Data Science Engineer</v-list-item-subtitle>
56
-
57
- <template v-slot:append>
58
- <div class="justify-self-end">
59
- <v-icon class="me-1" icon="mdi-heart" \@click="onserver('myclick')"></v-icon>
60
- <span class="subheading me-2">{{data.vote}}</span>
61
- <span class="me-1">·</span>
62
- <v-icon class="me-1" icon="mdi-share-variant"></v-icon>
63
- <span class="subheading">45</span>
64
- </div>
65
- </template>
66
- </v-list-item>
67
- </v-card-actions>
68
- </v-card>
69
- '''
70
-
71
- def myclick(event):
72
- mycard.vote = mycard.vote + 1
73
-
74
- data = {"vote":256}
75
- mycard = ss.template(template, data = data, handlers = {"myclick":myclick})
76
-
77
- def increment(event):
78
- mycard.vote = mycard.vote + 1
79
- #mycard.style = "color:red"
80
-
81
- ss.space()
82
- ss.button("Thumb Up", onclick=increment)
83
-
84
- ss.space("mt-8")
85
-
86
- ss.write('''
87
- ---
88
- #### Python Side Code
89
- ''')
90
-
91
- ss.md('''
92
- ```python
93
- import simplestart as ss
94
-
95
- template = \'''
96
- <v-card
97
- class="mx-auto text-white"
98
- color="#26c6da"
99
- max-width="400"
100
- prepend-icon="mdi-twitter"
101
- title="Twitter"
102
- >
103
- <template v-slot:prepend>
104
- <v-icon size="x-large"></v-icon>
105
- </template>
106
-
107
- <v-card-text class="text-h6 py-2">
108
- "SimpleStart is a easy way to build webpage and visualize data."
109
- </v-card-text>
110
-
111
- <v-card-actions>
112
- <v-list-item class="w-100">
113
- <template v-slot:prepend>
114
- <v-avatar
115
- color="grey-darken-3"
116
- 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"
117
- ></v-avatar>
118
- </template>
119
-
120
- <v-list-item-title>Evan You</v-list-item-title>
121
-
122
- <v-list-item-subtitle>Data Science Engineer</v-list-item-subtitle>
123
-
124
- <template v-slot:append>
125
- <div class="justify-self-end">
126
- <v-icon class="me-1" icon="mdi-heart" \@click="onserver('myclick')"></v-icon>
127
- <span class="subheading me-2">{{data.vote}}</span>
128
- <span class="me-1">·</span>
129
- <v-icon class="me-1" icon="mdi-share-variant"></v-icon>
130
- <span class="subheading">45</span>
131
- </div>
132
- </template>
133
- </v-list-item>
134
- </v-card-actions>
135
- </v-card>
136
- \'''
137
-
138
- def myclick(event):
139
- mycard.vote = mycard.vote + 1
140
-
141
- data = {"vote":256}
142
- mycard = ss.template(template, data = data, handlers = {"myclick":myclick})
143
-
144
- def increment(event):
145
- mycard.vote = mycard.vote + 1
146
- #mycard.style = "color:red"
147
-
148
- ss.space()
149
- ss.button("Thumb Up", onclick=increment)
150
- ```
151
- ''')
152
-
153
-
154
- ss.space("mt-8")
155
-
156
- def onPageEnter():
157
- ss.session["counter"] = 0
158
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/006 Advanced Usage/demo_when.py DELETED
@@ -1,101 +0,0 @@
1
- ### ss.when
2
- import simplestart as ss
3
-
4
- ss.md('''
5
- ## ss.when onditional Statements
6
- ''')
7
-
8
- ss.space()
9
- ss.md('''
10
- #### 🔅 Example
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("New content will appear below when the counter is greater than 5.")
44
-
45
- with ss.when(conditioner, flag = 1): # Conditional rendering
46
- ss.text("Well done on reaching 5 👋🌷🍾")
47
-
48
- ss.write("When the counter is less than 5, the new content will be hidden.")
49
-
50
-
51
- ss.space()
52
-
53
- ss.write("#### 🔎 Code")
54
- ss.write("---")
55
-
56
- def viewcode():
57
- ss.session["viewcode"] = 1
58
-
59
- ss.button("View Code", 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("New content will appear below when the counter is greater than 5.")
89
-
90
- with ss.when(conditioner, flag = 1): # Conditional rendering
91
- ss.text("Well done on reaching 5 👋🌷🍾")
92
-
93
- ss.write("When the counter is less than 5, the new content will be hidden.")
94
- ```
95
- ''')
96
-
97
- ss.md('''
98
- ::: tip
99
- The code view above is also implemented using ss.when.
100
- :::
101
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Advanced_Usage/demo_chat.py DELETED
@@ -1,33 +0,0 @@
1
- '''
2
- title: ollama chat demo
3
- '''
4
-
5
- import simplestart as ss
6
- import ollama
7
-
8
- ss.md("## ss.chat")
9
-
10
- setting = {
11
- "ollama_base_url": "http://localhost:11434",
12
- "model": "qwen:0.5b",
13
- "stream":False
14
- }
15
-
16
- def mychange(event):
17
- setting.update({
18
- "model":mysel.value,
19
- "stream":mycheck.value,
20
- })
21
-
22
-
23
- with ss.sidebar():
24
- ss.md("#### Models and Parameters")
25
- ss.space()
26
- models = ss.ollama.get_models()
27
-
28
- mysel = ss.selectbox(models, index = 5, label = "Choose ollama models", onchange = mychange)
29
-
30
- mycheck = ss.checkbox("Streaming Output", onchange = mychange)
31
-
32
-
33
- mychat = ss.ollama.chat(demo = False, setting = setting)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Advanced_Usage/demo_component.py DELETED
@@ -1,104 +0,0 @@
1
- '''
2
- title: component
3
- '''
4
-
5
- import simplestart as ss
6
-
7
- ss.md("### ss.component Custom Component")
8
- ss.md("You can customize components using HTML, JS, and CSS, implemented through an iframe.")
9
-
10
- ss.space()
11
- ss.md('''
12
- #### 🔅 Example
13
- ''')
14
- ss.space()
15
-
16
- def testme(state, value):
17
- mytext.text = "Data received from the frontend UI: " + value["value"]
18
-
19
- # By default, the <iframe> width is 300 pixels and the height is 150 pixels.
20
- ss.text("Enter content in the text box and press Enter.")
21
-
22
- myplugin = ss.component(path = f"components/index.html", onData = testme) ###style="border:none")
23
-
24
- def postdata():
25
- data = {"my_input_value":"text from python"}
26
- myplugin.postMessage(data)
27
-
28
- mytext = ss.text("Data received from the frontend UI: ")
29
-
30
- ss.markdown("---")
31
- ss.space()
32
- ss.text("Click the button to send data to the frontend UI.")
33
- ss.button("post data", onclick=postdata)
34
-
35
- ss.space()
36
-
37
- ss.write("Python Side Code")
38
-
39
- ss.md('''
40
- ```python
41
- import simplestart as ss
42
-
43
- def testme(state, value):
44
- mytext.text = "Data received from the frontend UI: " + value["value"]
45
-
46
- ss.text("Enter content in the text box and press Enter.")
47
- myplugin = ss.component(path = f"components/index.html", onData = testme)
48
-
49
- def postdata():
50
- data = {"my_input_value":"text from python"}
51
- myplugin.postMessage(data)
52
-
53
- mytext = ss.text("Data received from the frontend UI: ")
54
-
55
- ss.markdown("---")
56
-
57
- ss.space()
58
- ss.text("Click the button to send data to the frontend UI.")
59
- ss.button("post data", onclick=postdata)
60
-
61
- ```
62
- ''')
63
-
64
- ss.write("Plugin/HTML/JS Side Code")
65
-
66
- ss.md('''
67
- ```html
68
- <html>
69
-
70
- <head>
71
- <script src="pybridge.js"></script>
72
- </head>
73
-
74
- <body style="height:100px">
75
- <input id="myinput" value="" autocomplete="off" placeholder="Enter content and press Enter" />
76
- </body>
77
-
78
- <script>
79
- var myInput = document.getElementById("myinput");
80
-
81
- myInput.addEventListener("change", function() {
82
- //// Send message to the Python side
83
- sendDataToPython({
84
- value: myInput.value,
85
- });
86
- })
87
-
88
- //Receive messages from the Python side
89
- window.addEventListener("message", onDataFromPython);
90
-
91
- function onDataFromPython(event) {
92
- var data = event.data.arg;
93
- if (event.data.type !== "ss:render") return;
94
- myInput.value = data.my_input_value; // Access values sent from Python here!
95
- }
96
-
97
- // If system height setting fails, you can manually set the height
98
- //setFrameHeight(200);
99
- </script>
100
-
101
- </html>
102
-
103
- ```
104
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Advanced_Usage/demo_loadvue.py DELETED
@@ -1,134 +0,0 @@
1
- '''
2
- title: loadvue
3
- '''
4
-
5
- import simplestart as ss
6
-
7
- ss.md("## ss.loadvue Load Vue SFC")
8
-
9
- ss.space()
10
- ss.md("In SimpleStart, you can load custom Vue Single File Components using ss.loadvue, enabling property and data interaction.")
11
-
12
- ss.space()
13
-
14
- ss.space()
15
- ss.md('''
16
- #### 🔅 Example
17
-
18
- In this example, we define a simple frontend component that includes an "ontest" event. When the user clicks the "handle on server" button,
19
- the Python side's ontest event handler will process it and receive data passed from the frontend component. Meanwhile, when the "Modify Data"
20
- button on the Python side is clicked, the frontend component will respond by changing the displayed content.
21
- ''')
22
-
23
- ss.space("mt-8")
24
- ss.md("---")
25
- ss.space("mt-8")
26
-
27
- tagid = 0
28
- tags = ["Python", "Java", "Javascript"]
29
- data = {"count":0, "language":"C++"}
30
- global myvue
31
-
32
- #trigger event on server from client side
33
- def ontest(event):
34
- ss.message(event.value)
35
-
36
- #change data in client component on server side
37
- def changedata(event):
38
- global tagid
39
- myvue.data["language"] = tags[tagid]
40
- myvue.update()
41
-
42
- tagid = (tagid+1) % 3
43
-
44
- ss.text("Python Side")
45
- ss.button("Modify Data", onclick=changedata)
46
-
47
- ss.space()
48
- sec = ss.section()
49
-
50
- def onPageLoad():
51
- global myvue
52
- #load code from file
53
- with sec:
54
- ss.text("Component Side")
55
- myvue = ss.loadvue(path = "components/mycomponent.vue", data = data, handlers = {"ontest":ontest})
56
-
57
-
58
- ss.space()
59
- ss.write("Python Side Code")
60
-
61
- ss.md('''
62
- ```python
63
- import simplestart as ss
64
-
65
- tagid = 0
66
- global myvue
67
-
68
- tags = ["Python", "Java", "Javascript"]
69
- data = {"count":0, "language":"C++"}
70
-
71
-
72
- #trigger event on server from client side
73
- def ontest(state, value):
74
- ss.message(value)
75
-
76
- #change data in client component on server side
77
- def changedata(state, value=None):
78
- global tagid
79
- myvue.data["language"] = tags[tagid]
80
- tagid = (tagid+1) % 3
81
-
82
- ss.text("Python Side")
83
- ss.button("Modify Data", onclick=changedata)
84
-
85
-
86
- def onPageLoad():
87
- global myvue
88
- #load code from file
89
- myvue = ss.loadvue(path = "components/mycomponent.vue", data = data, handlers = {"ontest":ontest})
90
- ```
91
- ''')
92
-
93
-
94
- ss.space()
95
- ss.write("Vue JS Code")
96
-
97
- ss.md('''
98
- ```js
99
- <template>
100
- <div class="my-component">
101
- <h1>{{title}}: {{ data.language }}</h1>
102
- <v-btn @click="testme">handle on server</v-btn>
103
- </div>
104
- </template>
105
-
106
- <script>
107
- module.exports = {
108
- name: 'MyComponent',
109
-
110
- data() {
111
- return {
112
- title:"computer",
113
- }
114
- },
115
-
116
- methods: {
117
- testme(){
118
- this.streamsync.forwardData(this, eventname="ontest", "12345")
119
- }
120
- }
121
- }
122
- </script>
123
-
124
- <style>
125
- .my-component {
126
- width:50%;
127
- background-color: #f0f0f0;
128
- padding: 20px;
129
- margin:10px 0;
130
- }
131
- </style>
132
-
133
- ```
134
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Advanced_Usage/demo_onload.py DELETED
@@ -1,49 +0,0 @@
1
- '''
2
- title: onPageEnter
3
- '''
4
-
5
- import simplestart as ss
6
- from datetime import datetime
7
-
8
- ss.md("## onPageEnter Page Load Event")
9
-
10
- ss.md('''
11
- ---
12
- #### 🔅 Example
13
- ''')
14
-
15
- ss.md("Every time you enter this page, the onPageEnter event function will be called, and a message will pop up above.")
16
-
17
-
18
- ss.space()
19
-
20
- mytext = ss.text("Current Time @currentime")
21
-
22
- def onPageEnter():
23
- #ss.write("test")
24
- ss.message("page enter event")
25
-
26
-
27
- # Get current time
28
- now = datetime.now()
29
- # Format time as a string
30
- time_str = now.strftime('%Y-%m-%d %H:%M:%S')
31
- ss.session["currentime"] = time_str
32
-
33
-
34
- ss.space()
35
-
36
- ss.write('''
37
- ---
38
- #### 🔎 Code
39
- ''')
40
-
41
- ss.md('''
42
- ```python
43
- import simplestart as ss
44
-
45
- def onPageEnter():
46
- ss.message("page enter event")
47
-
48
- ```
49
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Advanced_Usage/demo_session.py DELETED
@@ -1,134 +0,0 @@
1
- '''
2
- title: session
3
- '''
4
-
5
- import simplestart as ss
6
-
7
- ss.md("## ss.session - reactive session variables")
8
- ss.md("By modifying the session variable, the view can be automatically re-rendered")
9
-
10
- ss.space()
11
-
12
- ss.md('''
13
- ---
14
- #### 🔅 Example 1 - Basic
15
- ''')
16
-
17
-
18
- #in this page
19
- ss.session["count"] = 100
20
-
21
- mytext = ss.text("The couns is @count")
22
-
23
-
24
- def change_count():
25
- ss.session.count += 1
26
-
27
- ss.button("Add Count", onclick=change_count)
28
-
29
- ss.write('''
30
- ---
31
- #### 🔎 Code
32
- ''')
33
-
34
- ss.md('''
35
- ```python
36
- import simplestart as ss
37
-
38
- ss.session["count"] = 100
39
-
40
- mytext = ss.text("The couns is @count")
41
-
42
-
43
- def change_count():
44
- ss.session.count += 1
45
-
46
- ss.button("Add Count", onclick=change_count)
47
-
48
- ```
49
- ''')
50
-
51
- ss.space()
52
-
53
- ss.md('''
54
- ---
55
- #### 🔅 Example 2 - Dict
56
- ''')
57
-
58
- student = {
59
- "name":"Sam",
60
- "age":18,
61
- "gender":"Male",
62
- "favorite": "Sport, movie"
63
- }
64
-
65
- ss.session.data = student
66
-
67
- ss.markdown('''
68
- ### Student Info
69
- **Name:** @data.name
70
- **Age:** @data.age
71
- **Gender:** @data.gender
72
- **Favorite:** @data.favorite
73
- ''')
74
-
75
- def change_student(event):
76
- student = {
77
- "name":"Jane",
78
- "age":17,
79
- "gender":"Female",
80
- "favorite": "Music, painting"
81
- }
82
- ss.session.data = student
83
-
84
- def change_info(event):
85
- ss.session.data["name"] = "Sally"
86
-
87
- ss.button("Change Student", onclick = change_student)
88
- ss.button("Change Info", onclick = change_info)
89
-
90
- ss.write('''
91
- ---
92
- #### 🔎 Code
93
- ''')
94
-
95
- ss.md('''
96
- ```python
97
- import simplestart as ss
98
-
99
- student = {
100
- "name":"Sam",
101
- "age":18,
102
- "gender":"Male",
103
- "favorite": "Sport, movie"
104
- }
105
-
106
- ss.session.data = student
107
-
108
- ss.markdown(\'''
109
- ### Student Info
110
- **Name:** \@data.name
111
- **Age:** \@data.age
112
- **Gender:** \@data.gender
113
- **Favorite:** \@data.favorite
114
- \''')
115
-
116
- def change_student(event):
117
- student = {
118
- "name":"Jane",
119
- "age":17,
120
- "gender":"Female",
121
- "image":"",
122
- "favorite": "Music, painting"
123
- }
124
- ss.session.data = student
125
-
126
- def change_info(event):
127
- ss.session.data["name"] = "Sally"
128
-
129
- ss.button("Change Student", onclick = change_student)
130
- ss.button("Change Info", onclick = change_info)
131
-
132
- ```
133
- ''')
134
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Advanced_Usage/demo_template.py DELETED
@@ -1,160 +0,0 @@
1
- '''
2
- title: template
3
- '''
4
-
5
- import simplestart as ss
6
-
7
- ss.md("## ss.template Load VUE Template")
8
-
9
- ss.space("mt-8")
10
- ss.md('''
11
- In SimpleStart, you can define simple Vue components using ss.template to achieve property and data interaction.
12
-
13
- #### Function
14
- ss.template(src, path, data, handlers)
15
-
16
- ##### Function Description
17
-
18
- | Parameter | Description |
19
- | --- | --- |
20
- | src | Component script in string format |
21
- | path | Path to the original code of the external component file |
22
- | data | Data used for interaction between frontend components and the Python backend |
23
- | handlers | Events defined in the frontend component, implemented on the Python side |
24
-
25
- ''')
26
-
27
- ss.space("mt-8")
28
-
29
-
30
- template = '''
31
- <v-card
32
- class="mx-auto text-white"
33
- color="#26c6da"
34
- max-width="400"
35
- prepend-icon="mdi-twitter"
36
- title="Twitter"
37
- >
38
- <template v-slot:prepend>
39
- <v-icon size="x-large"></v-icon>
40
- </template>
41
-
42
- <v-card-text class="text-h6 py-2">
43
- "SimpleStart is a easy way to build webpage and visualize data."
44
- </v-card-text>
45
-
46
- <v-card-actions>
47
- <v-list-item class="w-100">
48
- <template v-slot:prepend>
49
- <v-avatar
50
- color="grey-darken-3"
51
- 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"
52
- ></v-avatar>
53
- </template>
54
-
55
- <v-list-item-title>Evan You</v-list-item-title>
56
-
57
- <v-list-item-subtitle>Data Science Engineer</v-list-item-subtitle>
58
-
59
- <template v-slot:append>
60
- <div class="justify-self-end">
61
- <v-icon class="me-1" icon="mdi-heart" \@click="onserver('myclick')"></v-icon>
62
- <span class="subheading me-2">{{data.vote}}</span>
63
- <span class="me-1">·</span>
64
- <v-icon class="me-1" icon="mdi-share-variant"></v-icon>
65
- <span class="subheading">45</span>
66
- </div>
67
- </template>
68
- </v-list-item>
69
- </v-card-actions>
70
- </v-card>
71
- '''
72
-
73
- def myclick(event):
74
- mycard.vote = mycard.vote + 1
75
-
76
- data = {"vote":256}
77
- mycard = ss.template(template, data = data, handlers = {"myclick":myclick})
78
-
79
- def increment(event):
80
- mycard.vote = mycard.vote + 1
81
- #mycard.style = "color:red"
82
-
83
- ss.space()
84
- ss.button("Thumb Up", onclick=increment)
85
-
86
- ss.space("mt-8")
87
-
88
- ss.write('''
89
- ---
90
- #### Python Side Code
91
- ''')
92
-
93
- ss.md('''
94
- ```python
95
- import simplestart as ss
96
-
97
- template = \'''
98
- <v-card
99
- class="mx-auto text-white"
100
- color="#26c6da"
101
- max-width="400"
102
- prepend-icon="mdi-twitter"
103
- title="Twitter"
104
- >
105
- <template v-slot:prepend>
106
- <v-icon size="x-large"></v-icon>
107
- </template>
108
-
109
- <v-card-text class="text-h6 py-2">
110
- "SimpleStart is a easy way to build webpage and visualize data."
111
- </v-card-text>
112
-
113
- <v-card-actions>
114
- <v-list-item class="w-100">
115
- <template v-slot:prepend>
116
- <v-avatar
117
- color="grey-darken-3"
118
- 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"
119
- ></v-avatar>
120
- </template>
121
-
122
- <v-list-item-title>Evan You</v-list-item-title>
123
-
124
- <v-list-item-subtitle>Data Science Engineer</v-list-item-subtitle>
125
-
126
- <template v-slot:append>
127
- <div class="justify-self-end">
128
- <v-icon class="me-1" icon="mdi-heart" \@click="onserver('myclick')"></v-icon>
129
- <span class="subheading me-2">{{data.vote}}</span>
130
- <span class="me-1">·</span>
131
- <v-icon class="me-1" icon="mdi-share-variant"></v-icon>
132
- <span class="subheading">45</span>
133
- </div>
134
- </template>
135
- </v-list-item>
136
- </v-card-actions>
137
- </v-card>
138
- \'''
139
-
140
- def myclick(event):
141
- mycard.vote = mycard.vote + 1
142
-
143
- data = {"vote":256}
144
- mycard = ss.template(template, data = data, handlers = {"myclick":myclick})
145
-
146
- def increment(event):
147
- mycard.vote = mycard.vote + 1
148
- #mycard.style = "color:red"
149
-
150
- ss.space()
151
- ss.button("Thumb Up", onclick=increment)
152
- ```
153
- ''')
154
-
155
-
156
- ss.space("mt-8")
157
-
158
- def onPageEnter():
159
- ss.session["counter"] = 0
160
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Advanced_Usage/demo_when.py DELETED
@@ -1,104 +0,0 @@
1
- '''
2
- title: when
3
- '''
4
-
5
- import simplestart as ss
6
-
7
- ss.md('''
8
- ## ss.when onditional Statements
9
- ''')
10
-
11
- ss.space()
12
- ss.md('''
13
- #### 🔅 Example
14
- ''')
15
-
16
- #api
17
- def increment(event):
18
- ss.session["counter"] += 1
19
-
20
- def decrement(event):
21
- ss.session["counter"] -= 1
22
-
23
-
24
- #conditional func
25
- def conditioner(event):
26
- #print("event", event)
27
- if event["flag"] == 1:
28
- if ss.session["counter"] >= 5:
29
- return True
30
- else:
31
- return False
32
- elif event["flag"] == 2:
33
- return (ss.session["viewcode"] == 1)
34
-
35
-
36
- # State initialisation
37
- ss.session["counter"] = 0
38
- ss.session["viewcode"] = 0
39
-
40
- #ui
41
- ss.text("The count is @counter.")
42
-
43
- ss.button("Increment", onclick=increment)
44
- ss.button("Decrement", onclick=decrement)
45
-
46
- ss.write("New content will appear below when the counter is greater than 5.")
47
-
48
- with ss.when(conditioner, flag = 1): # Conditional rendering
49
- ss.text("Well done on reaching 5 👋🌷🍾")
50
-
51
- ss.write("When the counter is less than 5, the new content will be hidden.")
52
-
53
-
54
- ss.space()
55
-
56
- ss.write("#### 🔎 Code")
57
- ss.write("---")
58
-
59
- def viewcode():
60
- ss.session["viewcode"] = 1
61
-
62
- ss.button("View Code", size="small", onclick = viewcode)
63
-
64
- with ss.when(conditioner, flag = 2):
65
- ss.md('''
66
- ```python
67
- import simplestart as ss
68
-
69
- #api
70
- def increment(event):
71
- ss.session["counter"] += 1
72
-
73
- def decrement(event):
74
- ss.session["counter"] -= 1
75
-
76
-
77
- #conditional func
78
- def conditioner(event):
79
- return (ss.session["counter"] >= 5)
80
-
81
- # State initialisation
82
- ss.session["counter"] = 0
83
- ss.session["viewcode"] = 0
84
-
85
- #ui
86
- ss.text("The count is @counter.")
87
-
88
- ss.button("Increment", onclick=increment)
89
- ss.button("Decrement", onclick=decrement)
90
-
91
- ss.write("New content will appear below when the counter is greater than 5.")
92
-
93
- with ss.when(conditioner, flag = 1): # Conditional rendering
94
- ss.text("Well done on reaching 5 👋🌷🍾")
95
-
96
- ss.write("When the counter is less than 5, the new content will be hidden.")
97
- ```
98
- ''')
99
-
100
- ss.md('''
101
- ::: tip
102
- The code view above is also implemented using ss.when.
103
- :::
104
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Advanced_Usage/folder.yaml DELETED
@@ -1,2 +0,0 @@
1
- alias: Advantage Usage
2
- order_name: "005"
 
 
 
pages/Chart_Data/demo_bokeh.py DELETED
@@ -1,132 +0,0 @@
1
- '''
2
- title: chart bokeh
3
- '''
4
-
5
- import simplestart as ss
6
-
7
- from bokeh.plotting import figure
8
- from bokeh.models import ColumnDataSource
9
- from bokeh.resources import CDN
10
- from bokeh.embed import file_html
11
- from sklearn.datasets import load_iris
12
- import pandas as pd
13
-
14
- # Load the Iris dataset
15
- iris = load_iris()
16
- df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
17
- df['species'] = iris.target
18
- df['species'] = df['species'].map({0: 'setosa', 1: 'versicolor', 2: 'virginica'})
19
-
20
-
21
- # Create the data source and figure object
22
- source = ColumnDataSource(data=dict(
23
- sepal_length=df['sepal length (cm)'],
24
- sepal_width=df['sepal width (cm)'],
25
- petal_length=df['petal length (cm)'],
26
- petal_width=df['petal width (cm)'],
27
- species=df['species']
28
- ))
29
-
30
- # Create a Bokeh scatter plot
31
- p = figure(title="Iris Dataset Scatter Plot", x_axis_label='Sepal Length (cm)', y_axis_label='Sepal Width (cm)',
32
- tools="pan,wheel_zoom,box_zoom,reset,hover,save", width=800)
33
-
34
- # Set different colors based on species
35
- colors = {'setosa': 'blue', 'versicolor': 'green', 'virginica': 'red'}
36
-
37
- for species, color in colors.items():
38
- df_species = df[df['species'] == species]
39
- source_species = ColumnDataSource(data=dict(
40
- sepal_length=df_species['sepal length (cm)'],
41
- sepal_width=df_species['sepal width (cm)']
42
- ))
43
- p.scatter('sepal_length', 'sepal_width', source=source_species, legend_label=species, color=color,
44
- size=10, alpha=0.5)
45
-
46
- p.legend.title = 'Species'
47
- p.legend.location = 'top_left'
48
-
49
- # Embed the Bokeh figure into SimpleStart
50
- html = file_html(p, CDN, "Iris Dataset Scatter Plot")
51
-
52
- #ui
53
- ss.md('''
54
- ## simplestart Chart Demo - Bokeh
55
- ''')
56
-
57
- ss.space()
58
- ss.md('''
59
- #### 🔅 Example
60
- An interactive scatter plot of the Iris data using Bokeh
61
- ''')
62
-
63
- ss.space()
64
- ss.htmlview(html, border = False)
65
-
66
- ss.space()
67
- ss.write("#### 🔎 Code")
68
-
69
- def viewcode():
70
- ss.session["viewcode"] = 1
71
-
72
- ss.session["viewcode"] = 0
73
- ss.button("View Code", size="small", onclick = viewcode)
74
-
75
- def conditioner(event):
76
- return (ss.session["viewcode"] == 1)
77
-
78
- code = '''
79
- ```python
80
- import simplestart as ss
81
-
82
- from bokeh.plotting import figure
83
- from bokeh.models import ColumnDataSource
84
- from bokeh.resources import CDN
85
- from bokeh.embed import file_html
86
- from sklearn.datasets import load_iris
87
- import pandas as pd
88
-
89
- # Load the Iris dataset
90
- iris = load_iris()
91
- df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
92
- df['species'] = iris.target
93
- df['species'] = df['species'].map({0: 'setosa', 1: 'versicolor', 2: 'virginica'})
94
-
95
-
96
- # Create the data source and figure object
97
- source = ColumnDataSource(data=dict(
98
- sepal_length=df['sepal length (cm)'],
99
- sepal_width=df['sepal width (cm)'],
100
- petal_length=df['petal length (cm)'],
101
- petal_width=df['petal width (cm)'],
102
- species=df['species']
103
- ))
104
-
105
- # Create a Bokeh scatter plot
106
- p = figure(title="Iris Dataset Scatter Plot", x_axis_label='Sepal Length (cm)', y_axis_label='Sepal Width (cm)',
107
- tools="pan,wheel_zoom,box_zoom,reset,hover,save", width=800)
108
-
109
- # Set different colors based on species
110
- colors = {'setosa': 'blue', 'versicolor': 'green', 'virginica': 'red'}
111
-
112
- for species, color in colors.items():
113
- df_species = df[df['species'] == species]
114
- source_species = ColumnDataSource(data=dict(
115
- sepal_length=df_species['sepal length (cm)'],
116
- sepal_width=df_species['sepal width (cm)']
117
- ))
118
- p.scatter('sepal_length', 'sepal_width', source=source_species, legend_label=species, color=color,
119
- size=10, alpha=0.5)
120
-
121
- p.legend.title = 'Species'
122
- p.legend.location = 'top_left'
123
-
124
- # Embed the Bokeh figure into SimpleStart
125
- html = file_html(p, CDN, "Iris Dataset Scatter Plot")
126
-
127
- #ui
128
- ss.htmlview(html, border = False)
129
- '''
130
-
131
- with ss.when(conditioner):
132
- ss.md(code)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Chart_Data/demo_pyplot.py DELETED
@@ -1,134 +0,0 @@
1
- '''
2
- title: chart pyplot
3
- '''
4
-
5
- import streamsync as ss
6
-
7
- import seaborn as sns
8
- import matplotlib as mpl
9
- import matplotlib.pyplot as plt
10
-
11
-
12
- #下载不了,所以加一个参数data_home
13
- data_home = "./data/seaborn"
14
-
15
- ss.md('''
16
- ## ss.pyplot Drawing
17
- ''')
18
-
19
-
20
- ss.space()
21
- ss.md('''
22
- #### 🔅 Example
23
- ''')
24
-
25
- ss.write("#### 1. Draw a Line Plot")
26
-
27
- sns.set_style("whitegrid")
28
- titanic = sns.load_dataset("titanic", data_home=data_home)
29
- sns.lineplot(x="age", y="fare", hue="sex", data=titanic)
30
- plt.show()
31
-
32
- fig = plt.gcf()
33
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
34
-
35
- ss.write("#### 2. Draw a Scatter Plot")
36
-
37
- sns.set_style("whitegrid")
38
- tips = sns.load_dataset("tips", data_home=data_home)
39
- sns.scatterplot(x="total_bill", y="tip", data=tips)
40
- plt.show()
41
-
42
- fig = plt.gcf()
43
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
44
-
45
- ss.write("#### 3. Draw a Bar Plot")
46
-
47
- sns.set_style("whitegrid")
48
- titanic = sns.load_dataset("titanic",data_home=data_home)
49
- sns.barplot(x="class", y="survived", data=titanic)
50
- plt.show()
51
-
52
- fig = plt.gcf()
53
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
54
-
55
-
56
- ss.write("#### 4. Draw a Histogram")
57
- sns.set_style("whitegrid")
58
- titanic = sns.load_dataset("titanic",data_home=data_home)
59
- sns.histplot(x="age", data=titanic)
60
- plt.show()
61
-
62
- fig = plt.gcf()
63
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
64
-
65
-
66
- ss.space()
67
-
68
- ss.write("#### 🔎 Code")
69
- ss.write("---")
70
-
71
- def viewcode():
72
- ss.session["viewcode"] = 1
73
-
74
- ss.button("View Code", size="small", onclick = viewcode)
75
-
76
-
77
- def conditioner(event):
78
- return ss.session["viewcode"] == 1
79
-
80
- with ss.when(conditioner):
81
- ss.md('''
82
- ```python
83
- import streamsync as ss
84
-
85
- import seaborn as sns
86
- import matplotlib as mpl
87
- import matplotlib.pyplot as plt
88
-
89
-
90
- data_home = "./data/seaborn"
91
-
92
-
93
- ss.write("#### 1. Draw a Line Plot")
94
-
95
- sns.set_style("whitegrid")
96
- titanic = sns.load_dataset("titanic", data_home=data_home)
97
- sns.lineplot(x="age", y="fare", hue="sex", data=titanic)
98
- plt.show()
99
-
100
- fig = plt.gcf()
101
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
102
-
103
- ss.write("#### 2. Draw a Scatter Plot")
104
-
105
- sns.set_style("whitegrid")
106
- tips = sns.load_dataset("tips", data_home=data_home)
107
- sns.scatterplot(x="total_bill", y="tip", data=tips)
108
- plt.show()
109
-
110
- fig = plt.gcf()
111
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
112
-
113
- ss.write("#### 3. Draw a Bar Plot")
114
-
115
- sns.set_style("whitegrid")
116
- titanic = sns.load_dataset("titanic",data_home=data_home)
117
- sns.barplot(x="class", y="survived", data=titanic)
118
- plt.show()
119
-
120
- fig = plt.gcf()
121
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
122
-
123
-
124
- ss.write("#### 4. Draw a Histogram")
125
- sns.set_style("whitegrid")
126
- titanic = sns.load_dataset("titanic",data_home=data_home)
127
- sns.histplot(x="age", data=titanic)
128
- plt.show()
129
-
130
- fig = plt.gcf()
131
- ss.pyplot(fig, style="border:1px solid gray; width:600px")
132
- ```
133
- ''')
134
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Chart_Data/folder.yaml DELETED
@@ -1,2 +0,0 @@
1
- alias: Chart Data
2
- order_name: "003"
 
 
 
pages/Content_Display/demo_audio.py DELETED
@@ -1,76 +0,0 @@
1
- '''
2
- title: Audio Playback
3
- '''
4
-
5
- import streamsync as ss
6
-
7
- ss.md("## ss.audio")
8
-
9
-
10
- ss.space()
11
- ss.md('''
12
- #### 🔅 Example
13
- ''')
14
-
15
- ss.space()
16
-
17
- audiosrc = "media/test.wav"
18
- player = ss.audio(audiosrc)
19
-
20
-
21
- ss.space("mt-8")
22
-
23
- ss.write('''
24
- ---
25
- #### 🔎 Code
26
- ''')
27
-
28
- ss.md('''
29
- ```python
30
- import simplestart as ss
31
-
32
- audiosrc = "media/davide_quatela--breathing_barcelona.mp3"
33
- player = ss.audio(audiosrc)
34
- ```
35
- ''')
36
-
37
- def playaudio(event):
38
- if event.tag == "play":
39
- player.play()
40
- elif event.tag == "pause":
41
- player.pause()
42
- elif event.tag == "change":
43
- player.src = "media/davide_quatela--breathing_barcelona.mp3"
44
- elif event.tag == "seek":
45
- player.seek(3)
46
-
47
- ss.button("play", onclick = playaudio, eventTag = "play")
48
- ss.button("pause", onclick = playaudio, eventTag = "pause")
49
- ss.button("change source", onclick = playaudio, eventTag = "change")
50
- ss.button("seek", onclick = playaudio, eventTag = "seek")
51
-
52
- ss.md('''
53
- ```python
54
- def playaudio(event):
55
- if event.tag == "play":
56
- player.play()
57
- elif event.tag == "pause":
58
- player.pause()
59
- elif event.tag == "change":
60
- player.src = "media/davide_quatela--breathing_barcelona.mp3"
61
- elif event.tag == "seek":
62
- player.seek(3)
63
-
64
- ss.button("play", onclick = playaudio, eventTag = "play")
65
- ss.button("pause", onclick = playaudio, eventTag = "pause")
66
- ss.button("change source", onclick = playaudio, eventTag = "change")
67
- ss.button("seek", onclick = playaudio, eventTag = "seek")
68
- ```
69
- ''')
70
-
71
- ss.md('''
72
- ::: tip
73
- ss.audio supports audio formats including wav, mp3, etc.
74
- :::
75
- ''')
76
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Content_Display/demo_html.py DELETED
@@ -1,52 +0,0 @@
1
- '''
2
- title: Html Hypertext
3
- '''
4
-
5
- import streamsync as ss
6
-
7
-
8
- ss.md("## ss.html")
9
-
10
- ss.space("")
11
-
12
- ss.md('''
13
- #### 🔅 Example
14
- ''')
15
-
16
-
17
- ss.md("### html")
18
-
19
- ss.html(f"""
20
- <p>This is a piece of rich text content, which contains <strong>bold</strong> and <em>italic</em> text.</p>
21
- <style>
22
- .testclass{{
23
- color:red;
24
- font-weight:bold;
25
- }}
26
- </style>
27
- <div class="testclass">this is red</div>
28
- """)
29
-
30
- ss.space("mt-8")
31
-
32
- ss.write('''
33
- ---
34
- #### 🔎 Code
35
- ''')
36
-
37
- ss.md('''
38
- ```python
39
- import simplestart as ss
40
-
41
- ss.html(f"""
42
- <p>This is a piece of rich text content, which contains <strong>bold</strong> and <em>italic</em> text.</p>
43
- <style>
44
- .testclass{{
45
- color:red;
46
- font-weight:bold;
47
- }}
48
- </style>
49
- <div class="testclass">this is red</div>
50
- """)
51
- ```
52
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/Content_Display/demo_image.py DELETED
@@ -1,103 +0,0 @@
1
- '''
2
- title: Image
3
- '''
4
-
5
- import simplestart as ss
6
-
7
- import cv2
8
- from PIL import Image
9
- import os
10
-
11
- ss.md("## ss.image")
12
-
13
- ss.md('''
14
- #### 🔅 Example
15
- ''')
16
-
17
- ss.space()
18
-
19
- img = "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
20
-
21
- cols = ss.columns([60,"flex:40"], border=True)
22
- with cols[0]:
23
- mytext = ss.text("This is image")
24
- ss.space()
25
- myimg = ss.image(img, fit="contain", width=300, height=300)
26
- ss.text("Image fit mode: @fit_str")
27
-
28
- def onradiochange(event):
29
- #ss.message(event.value)
30
-
31
- ss.session["fit_str"] = event.value
32
- myimg.fit = event.value
33
-
34
-
35
- def onradiochange2(event):
36
- value = event.value
37
- index = event.index
38
-
39
- source = ["Http", "PIL", "OpenCV", "Local"]
40
- ss.session["source_str"] = source[index]
41
-
42
-
43
- if index == 0:
44
- img = "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
45
- ss.session["image_path"] = "\"https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg\""
46
- myimg.image = img
47
- if index == 1:
48
- image = Image.open('./media/image/dalao.jpeg')
49
- ss.session["image_path"] = "Image.open('./media/image/dalao.jpeg')"
50
- myimg["image"] = image
51
- if index == 2:
52
- img = cv2.imread('./media/image/cat.jpeg',cv2.IMREAD_COLOR)
53
- ss.session["image_path"] = "cv2.imread('./media/image/cat.jpeg',cv2.IMREAD_COLOR)"
54
- myimg.image = img
55
- if index == 3:
56
- file_path = './media/image/dog.jpeg'
57
- ss.session["image_path"] = "\"./media/image/dog.jpeg\""
58
- myimg.image = file_path
59
-
60
- def sel_change(event):
61
- myimg.border = "border" in event.value
62
-
63
- if "title" in event.value:
64
- myimg.title = "Title of image"
65
- else:
66
- myimg.title = ""
67
-
68
- if "elevation" in event.value:
69
- myimg.elevation = 12
70
- else:
71
- myimg.elevation = 0
72
-
73
- with cols[1]:
74
- ss.text("Image fit mode")
75
- ss.radio(["fill", "contain", "cover", "none", "scale-down"], index = 1, inline = True, onchange=onradiochange)
76
- ss.space()
77
- ss.text("Image source")
78
- ss.radio(["Http image","PIL image", "OpenCV image", "Local image"], index = 0, inline = True, onchange=onradiochange2)
79
-
80
- ss.md("---")
81
- ss.selectbox(["border", "title", "elevation"], label = "Others", multiple = True, onchange = sel_change)
82
-
83
- ss.space()
84
-
85
- ss.write('''
86
- #### 🔎 Code
87
- ''')
88
-
89
- ss.md('''
90
- ```python
91
- import simplestart as ss
92
- import cv2
93
- from PIL import Image
94
-
95
- img = @image_path
96
- ss.image(img, fit="@fit_str")
97
- ```
98
- ''')
99
-
100
- def onPageLoad():
101
- ss.session["fit_str"] = "contain"
102
- ss.session["source_str"] = "Http"
103
- ss.session["image_path"] = "\"https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg\""