Skip to content

Commit 159b041

Browse files
committed
migrate demo to pywebio v1.4
1 parent 5277a15 commit 159b041

File tree

9 files changed

+19
-74
lines changed

9 files changed

+19
-74
lines changed

demos/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +0,0 @@
1-
r"""
2-
.. automodule:: demos.bmi
3-
.. automodule:: demos.input_usage
4-
.. automodule:: demos.output_usage
5-
.. automodule:: demos.chat_room
6-
.. automodule:: demos.markdown_previewer
7-
.. automodule:: demos.gomoku_game
8-
"""

demos/bmi.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
"""
2-
BMI calculation
3-
^^^^^^^^^^^^^^^
4-
5-
Simple application for calculating `Body Mass Index <https://en.wikipedia.org/wiki/Body_mass_index>`_
6-
7-
:demo_host:`Demo </bmi>`, `Source code <https://github.com/wang0618/PyWebIO/blob/dev/demos/bmi.py>`_
8-
"""
91
from pywebio import start_server
102
from pywebio.input import *
113
from pywebio.output import *

demos/chat_room.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
"""
2-
Online chat room
3-
^^^^^^^^^^^^^^^^^^^
4-
Chat with everyone currently online
5-
6-
:demo_host:`Demo </chat_room>`, `Source code <https://github.com/wang0618/PyWebIO/blob/dev/demos/chat_room.py>`_
7-
8-
* Use coroutine-based sessions
9-
* Use `run_async() <pywebio.session.run_async>` to start background coroutine
10-
"""
111
import asyncio
122

133
from pywebio import start_server

demos/doc_demo.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
"""
44
from functools import partial
55
from os import path, listdir
6-
import time
76

87
from pywebio import start_server
9-
from pywebio.output import *
8+
from pywebio.platform import config
9+
from pywebio.session import local as session_local, info as session_info
10+
11+
##########################################
12+
# Pre-import modules for demo
13+
import time
1014
from pywebio.input import *
11-
from pywebio.pin import *
12-
from pywebio.platform import seo
15+
from pywebio.output import *
1316
from pywebio.session import *
14-
from pywebio.session import local as session_local
17+
from pywebio.pin import *
18+
##########################################
1519

1620

1721
def t(eng, chinese):
1822
"""return English or Chinese text according to the user's browser language"""
19-
return chinese if 'zh' in get_info().user_language else eng
23+
return chinese if 'zh' in session_info.user_language else eng
2024

2125

2226
here_dir = path.dirname(path.abspath(__file__))
@@ -45,18 +49,21 @@ def run_code(code, scope):
4549
toast('Exception occurred: "%s:%s"' % (type(e).__name__, e), color='error')
4650

4751

48-
IMPORT_CODE = """from pywebio.input import *
52+
IMPORT_CODE = """from pywebio import start_server
53+
from pywebio.input import *
4954
from pywebio.output import *
5055
from pywebio.session import *
5156
from pywebio.pin import *
5257
58+
def main():
59+
%s
60+
61+
start_server(main, port=8080, debug=True)
5362
"""
5463

5564

5665
def copytoclipboard(code):
57-
code = IMPORT_CODE + code
58-
if 'put_buttons(' in code or 'put_file(' in code:
59-
code += '\n\nhold() # keep session alive'
66+
code = IMPORT_CODE % code.replace('\n', '\n ')
6067
run_js("writeText(text)", text=code)
6168
toast('The code has been copied to the clipboard')
6269

@@ -93,8 +100,6 @@ def handle_code(code, title):
93100

94101
put_markdown('----')
95102

96-
hold()
97-
98103

99104
def get_app():
100105
"""PyWebIO demos from document
@@ -111,7 +116,7 @@ def get_app():
111116
code = open(path.join(here_dir, 'doc_demos', name)).read()
112117
title, code = code.split('\n\n', 1)
113118
app[name] = partial(handle_code, code=code, title=title)
114-
app[name] = seo('', title, app[name])
119+
app[name] = config(title=name, description=title)(app[name])
115120

116121
return app
117122

demos/gomoku_game.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
"""
2-
Online Shared Gomoku Game
3-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
All online players are assigned to two groups (black and white) and play same Gomoku game together.
5-
6-
:demo_host:`Demo </gomoku_game>`, `Source code <https://github.com/wang0618/PyWebIO/blob/dev/demos/gomoku_game.py>`_
7-
"""
81
import pywebio, time
92
from pywebio.output import *
103
from pywebio.session import *

demos/input_usage.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
"""
2-
Input demo
3-
^^^^^^^^^^^^^^^
4-
Demonstrate various input usage supported by PyWebIO
5-
6-
:demo_host:`Demo </input_usage>`, `Source code <https://github.com/wang0618/PyWebIO/blob/dev/demos/input_usage.py>`_
7-
"""
81
import json
92

103
from pywebio import start_server

demos/markdown_previewer.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
"""
2-
Markdown Live Preview
3-
^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
The online markdown editor with live preview.
5-
6-
:demo_host:`Demo </markdown_previewer>`, `Source code <https://github.com/wang0618/PyWebIO/blob/dev/demos/markdown_previewer.py>`_
7-
"""
81
from pywebio import start_server
92

103
from pywebio.output import *

demos/output_usage.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
"""
2-
Output demo
3-
^^^^^^^^^^^^^^
4-
Demonstrate various output usage supported by PyWebIO
5-
6-
:demo_host:`Demo </output_usage>`, `Source code <https://github.com/wang0618/PyWebIO/blob/dev/demos/output_usage.py>`_
7-
"""
81
from pywebio import start_server
92
from pywebio.output import *
10-
from pywebio.session import hold, info as session_info
3+
from pywebio.session import info as session_info
114
from functools import partial
125

136

@@ -354,8 +347,6 @@ def btn_click(btn_val):
354347
PyWebIO的输出演示到这里就结束了,更多内容请访问PyWebIO[用户指南](https://pywebio.readthedocs.io/zh_CN/latest/guide.html)和[output模块文档](https://pywebio.readthedocs.io/zh_CN/latest/output.html)。
355348
"""), lstrip=True)
356349

357-
await hold()
358-
359350

360351
if __name__ == '__main__':
361352
start_server(main, debug=True, port=8080, cdn=False)

demos/set_env_demo.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
"""
2-
`pywebio.session.set_env()` demo
3-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
"""
51
from pywebio import start_server
62
from pywebio.input import *
73
from pywebio.output import *

0 commit comments

Comments
 (0)