|
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 |
123 | 3 |
|
| 4 | +from pywebio.platform import path_deploy |
124 | 5 |
|
125 | 6 | 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() |
128 | 10 |
|
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) |
0 commit comments