Skip to content

Commit c13ae6d

Browse files
committed
use path_deploy() to deploy demos
1 parent 389ca81 commit c13ae6d

File tree

2 files changed

+116
-138
lines changed

2 files changed

+116
-138
lines changed

demos/__main__.py

Lines changed: 8 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,12 @@
1-
import tornado.ioloop
2-
import tornado.web
3-
4-
from demos.bmi import main as bmi
5-
from demos.chat_room import main as chat_room
6-
from demos.input_usage import main as input_usage
7-
from demos.output_usage import main as output_usage
8-
from demos.config import charts_demo_host
9-
from demos.doc_demo import get_app as get_doc_demo_app
10-
from demos.set_env_demo import main as set_env_demo
11-
from demos.markdown_previewer import main as markdown_previewer
12-
from demos.gomoku_game import main as gomoku_game
13-
14-
from pywebio import STATIC_PATH
15-
from pywebio.output import put_markdown, put_row, put_html
16-
from pywebio.platform.tornado import webio_handler
17-
from pywebio.session import info as session_info
18-
from tornado.options import define, options
19-
20-
index_md = r"""### Basic demo
21-
22-
- [BMI calculation](./bmi): Calculating Body Mass Index based on height and weight
23-
- [Online chat room](./chat_room): Chat with everyone currently online (using less than 90 lines of code)
24-
- [Markdown live preview](./markdown_previewer): The online markdown editor with live preview (using less than 40 lines of code)
25-
- [Online Gomoku game](./gomoku_game): An online shared Gomoku game (using less than 100 lines of code)
26-
- [Input demo](./input_usage): Demonstrate the usage of PyWebIO input module
27-
- [Output demo](./output_usage): Demonstrate the usage of PyWebIO output module
28-
29-
### Data visualization demo
30-
PyWebIO supports for data visualization with the third-party libraries.
31-
32-
- Use `bokeh` for data visualization [**demos**]({charts_demo_host}/?app=bokeh)
33-
- Use `plotly` for data visualization [**demos**]({charts_demo_host}/?app=plotly)
34-
- Use `pyecharts` to create Echarts-based charts in Python [**demos**]({charts_demo_host}/?app=pyecharts)
35-
- Use `pyg2plot` to create G2Plot-based charts in Python [**demos**]({charts_demo_host}/?app=pyg2plot)
36-
- Use `cutecharts.py` to create hand drawing style charts [**demos**]({charts_demo_host}/?app=cutecharts)
37-
38-
**Screenshots**
39-
40-
<a href="{charts_demo_host}/?app=bokeh">
41-
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/bokeh.png" alt="bokeh demo">
42-
</a>
43-
44-
<a href="{charts_demo_host}/?app=plotly">
45-
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/plotly.png" alt="plotly demo">
46-
</a>
47-
48-
<a href="{charts_demo_host}/?app=pyecharts">
49-
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/pyecharts.gif" alt="pyecharts demo">
50-
</a>
51-
52-
<a href="{charts_demo_host}/?app=cutecharts">
53-
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/cutecharts.png" alt="cutecharts demo">
54-
</a>
55-
56-
### Links
57-
* PyWebIO Github [github.com/wang0618/PyWebIO](https://github.com/wang0618/PyWebIO)
58-
* Document [pywebio.readthedocs.io](https://pywebio.readthedocs.io)
59-
60-
""".format(charts_demo_host=charts_demo_host)
61-
62-
63-
index_md_zh = r"""### 基本demo
64-
65-
- [BMI计算](./bmi): 根据身高体重计算BMI指数
66-
- [聊天室](./chat_room): 和当前所有在线的人聊天 (不到90行代码实现)
67-
- [Markdown实时预览](./markdown_previewer): 可以实时预览的在线Markdown编辑器 (不到40行代码实现)
68-
- [在线五子棋游戏](./gomoku_game): 多人协作对战的五子棋游戏 (不到100行代码实现)
69-
- [输入演示](./input_usage): 演示PyWebIO输入模块的用法
70-
- [输出演示](./output_usage): 演示PyWebIO输出模块的用法
71-
- 更多Demo请见[文档](https://pywebio.readthedocs.io)中示例代码的在线Demo
72-
73-
### 数据可视化demo
74-
PyWebIO还支持使用第三方库进行数据可视化
75-
76-
- 使用`bokeh`进行数据可视化 [**demos**]({charts_demo_host}/?app=bokeh)
77-
- 使用`plotly`进行数据可视化 [**demos**]({charts_demo_host}/?app=plotly)
78-
- 使用`pyecharts`创建基于Echarts的图表 [**demos**]({charts_demo_host}/?app=pyecharts)
79-
- 使用`pyg2plot`创建基于G2Plot的图表 [**demos**]({charts_demo_host}/?app=pyg2plot)
80-
- 使用`cutecharts.py`创建卡通风格图表 [**demos**]({charts_demo_host}/?app=cutecharts)
81-
82-
**数据可视化demo截图**
83-
84-
<a href="{charts_demo_host}/?app=bokeh">
85-
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/bokeh.png" alt="bokeh demo">
86-
</a>
87-
88-
<a href="{charts_demo_host}/?app=plotly">
89-
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/plotly.png" alt="plotly demo">
90-
</a>
91-
92-
<a href="{charts_demo_host}/?app=pyecharts">
93-
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/pyecharts.gif" alt="pyecharts demo">
94-
</a>
95-
96-
<a href="{charts_demo_host}/?app=cutecharts">
97-
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/cutecharts.png" alt="cutecharts demo">
98-
</a>
99-
100-
### Links
101-
* PyWebIO Github [github.com/wang0618/PyWebIO](https://github.com/wang0618/PyWebIO)
102-
* 使用手册和实现文档见 [pywebio.readthedocs.io](https://pywebio.readthedocs.io/zh_CN/latest/)
103-
104-
""".format(charts_demo_host=charts_demo_host)
105-
106-
107-
def index():
108-
"""PyWebIO demos
109-
110-
Basic demo and data visualization demo of PyWebIO.
111-
PyWebIO的基本demo和数据可视化demo
112-
"""
113-
put_row([
114-
put_markdown('# PyWebIO demos'),
115-
put_html('<a class="github-button" data-size="large" href="https://github.com/wang0618/PyWebIO" data-show-count="true" aria-label="Star wang0618/PyWebIO on GitHub">Star</a>')
116-
], size='1fr auto').style('align-items:center')
117-
put_html('<script async defer src="https://buttons.github.io/buttons.js"></script>')
118-
119-
if 'zh' in session_info.user_language:
120-
put_markdown(index_md_zh)
121-
else:
122-
put_markdown(index_md)
1+
import argparse
2+
from os import path
1233

4+
from pywebio.platform import path_deploy
1245

1256
if __name__ == "__main__":
126-
define("port", default=8080, help="run on the given port", type=int)
127-
tornado.options.parse_command_line()
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument("-p", "--port", default=8080, help="run on the given port", type=int)
9+
args = parser.parse_args()
12810

129-
application = tornado.web.Application([
130-
(r"/", webio_handler(index, cdn=False)),
131-
(r"/bmi", webio_handler(bmi, cdn=False)),
132-
(r"/chat_room", webio_handler(chat_room, cdn=False)),
133-
(r"/input_usage", webio_handler(input_usage, cdn=False)),
134-
(r"/output_usage", webio_handler(output_usage, cdn=False)),
135-
(r"/doc_demo", webio_handler(get_doc_demo_app(), cdn=False)),
136-
(r"/set_env_demo", webio_handler(set_env_demo, cdn=False)),
137-
(r"/markdown_previewer", webio_handler(markdown_previewer, cdn=False)),
138-
(r"/gomoku_game", webio_handler(gomoku_game, cdn=False)),
139-
(r"/(.*)", tornado.web.StaticFileHandler, {"path": STATIC_PATH, 'default_filename': 'index.html'})
140-
], websocket_ping_interval=30)
141-
application.listen(port=options.port)
142-
tornado.ioloop.IOLoop.current().start()
11+
here_dir = path.dirname(path.abspath(__file__))
12+
path_deploy(here_dir, port=args.port)

demos/index.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from demos.config import charts_demo_host
2+
3+
from pywebio.output import put_markdown, put_row, put_html
4+
from pywebio.session import info as session_info
5+
6+
index_md = r"""### Basic demo
7+
8+
- [BMI calculation](./bmi): Calculating Body Mass Index based on height and weight
9+
- [Online chat room](./chat_room): Chat with everyone currently online (using less than 90 lines of code)
10+
- [Markdown live preview](./markdown_previewer): The online markdown editor with live preview (using less than 40 lines of code)
11+
- [Online Gomoku game](./gomoku_game): An online shared Gomoku game (using less than 100 lines of code)
12+
- [Input demo](./input_usage): Demonstrate the usage of PyWebIO input module
13+
- [Output demo](./output_usage): Demonstrate the usage of PyWebIO output module
14+
15+
### Data visualization demo
16+
PyWebIO supports for data visualization with the third-party libraries.
17+
18+
- Use `bokeh` for data visualization [**demos**]({charts_demo_host}/?app=bokeh)
19+
- Use `plotly` for data visualization [**demos**]({charts_demo_host}/?app=plotly)
20+
- Use `pyecharts` to create Echarts-based charts in Python [**demos**]({charts_demo_host}/?app=pyecharts)
21+
- Use `pyg2plot` to create G2Plot-based charts in Python [**demos**]({charts_demo_host}/?app=pyg2plot)
22+
- Use `cutecharts.py` to create hand drawing style charts [**demos**]({charts_demo_host}/?app=cutecharts)
23+
24+
**Screenshots**
25+
26+
<a href="{charts_demo_host}/?app=bokeh">
27+
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/bokeh.png" alt="bokeh demo">
28+
</a>
29+
30+
<a href="{charts_demo_host}/?app=plotly">
31+
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/plotly.png" alt="plotly demo">
32+
</a>
33+
34+
<a href="{charts_demo_host}/?app=pyecharts">
35+
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/pyecharts.gif" alt="pyecharts demo">
36+
</a>
37+
38+
<a href="{charts_demo_host}/?app=cutecharts">
39+
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/cutecharts.png" alt="cutecharts demo">
40+
</a>
41+
42+
### Links
43+
* PyWebIO Github [github.com/wang0618/PyWebIO](https://github.com/wang0618/PyWebIO)
44+
* Document [pywebio.readthedocs.io](https://pywebio.readthedocs.io)
45+
46+
""".format(charts_demo_host=charts_demo_host)
47+
48+
index_md_zh = r"""### 基本demo
49+
50+
- [BMI计算](./bmi): 根据身高体重计算BMI指数
51+
- [聊天室](./chat_room): 和当前所有在线的人聊天 (不到90行代码实现)
52+
- [Markdown实时预览](./markdown_previewer): 可以实时预览的在线Markdown编辑器 (不到40行代码实现)
53+
- [在线五子棋游戏](./gomoku_game): 多人协作对战的五子棋游戏 (不到100行代码实现)
54+
- [输入演示](./input_usage): 演示PyWebIO输入模块的用法
55+
- [输出演示](./output_usage): 演示PyWebIO输出模块的用法
56+
- 更多Demo请见[文档](https://pywebio.readthedocs.io)中示例代码的在线Demo
57+
58+
### 数据可视化demo
59+
PyWebIO还支持使用第三方库进行数据可视化
60+
61+
- 使用`bokeh`进行数据可视化 [**demos**]({charts_demo_host}/?app=bokeh)
62+
- 使用`plotly`进行数据可视化 [**demos**]({charts_demo_host}/?app=plotly)
63+
- 使用`pyecharts`创建基于Echarts的图表 [**demos**]({charts_demo_host}/?app=pyecharts)
64+
- 使用`pyg2plot`创建基于G2Plot的图表 [**demos**]({charts_demo_host}/?app=pyg2plot)
65+
- 使用`cutecharts.py`创建卡通风格图表 [**demos**]({charts_demo_host}/?app=cutecharts)
66+
67+
**数据可视化demo截图**
68+
69+
<a href="{charts_demo_host}/?app=bokeh">
70+
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/bokeh.png" alt="bokeh demo">
71+
</a>
72+
73+
<a href="{charts_demo_host}/?app=plotly">
74+
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/plotly.png" alt="plotly demo">
75+
</a>
76+
77+
<a href="{charts_demo_host}/?app=pyecharts">
78+
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/pyecharts.gif" alt="pyecharts demo">
79+
</a>
80+
81+
<a href="{charts_demo_host}/?app=cutecharts">
82+
<img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery/assets/cutecharts.png" alt="cutecharts demo">
83+
</a>
84+
85+
### Links
86+
* PyWebIO Github [github.com/wang0618/PyWebIO](https://github.com/wang0618/PyWebIO)
87+
* 使用手册和实现文档见 [pywebio.readthedocs.io](https://pywebio.readthedocs.io/zh_CN/latest/)
88+
89+
""".format(charts_demo_host=charts_demo_host)
90+
91+
92+
def main():
93+
"""PyWebIO demos
94+
95+
Basic demo and data visualization demo of PyWebIO.
96+
PyWebIO的基本demo和数据可视化demo
97+
"""
98+
put_row([
99+
put_markdown('# PyWebIO demos'),
100+
put_html(
101+
'<a class="github-button" data-size="large" href="https://github.com/wang0618/PyWebIO" data-show-count="true" aria-label="Star wang0618/PyWebIO on GitHub">Star</a>')
102+
], size='1fr auto').style('align-items:center')
103+
put_html('<script async defer src="https://buttons.github.io/buttons.js"></script>')
104+
105+
if 'zh' in session_info.user_language:
106+
put_markdown(index_md_zh)
107+
else:
108+
put_markdown(index_md)

0 commit comments

Comments
 (0)