wangweimin 4 سال پیش
والد
کامیت
590d8b704e
8فایلهای تغییر یافته به همراه47 افزوده شده و 36 حذف شده
  1. 15 11
      demos/__main__.py
  2. 5 2
      demos/bmi.py
  3. 1 1
      demos/bokeh_app.py
  4. 5 3
      demos/chat_room.py
  5. 8 14
      demos/doc_demo.py
  6. 6 2
      demos/input_usage.py
  7. 4 2
      demos/output_usage.py
  8. 3 1
      demos/set_env_demo.py

+ 15 - 11
demos/__main__.py

@@ -16,10 +16,10 @@ from tornado.options import define, options
 
 index_md = r"""### 基本demo
 
- - [BMI计算](./?pywebio_api=bmi): 根据身高体重计算BMI指数 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/bmi.py)
- - [聊天室](./?pywebio_api=chat_room): 和当前所有在线的人聊天 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/chat_room.py)
- - [输入演示](./?pywebio_api=input_usage):  演示PyWebIO输入模块的用法 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/input_usage.py)
- - [输出演示](./?pywebio_api=output_usage): 演示PyWebIO输出模块的用法 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/output_usage.py)
+ - [BMI计算](./bmi): 根据身高体重计算BMI指数 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/bmi.py)
+ - [聊天室](./chat_room): 和当前所有在线的人聊天 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/chat_room.py)
+ - [输入演示](./input_usage):  演示PyWebIO输入模块的用法 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/input_usage.py)
+ - [输出演示](./output_usage): 演示PyWebIO输出模块的用法 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/output_usage.py)
  - 更多Demo请见[文档](https://pywebio.readthedocs.io)中示例代码的在线Demo
 
 ### 数据可视化demo
@@ -56,6 +56,10 @@ PyWebIO还支持使用第三方库进行数据可视化
 
 
 def index():
+    """PyWebIO demos
+
+    PyWebIO的基本demo和数据可视化demo
+    """
     style(put_row([
         put_markdown('# PyWebIO demos'),
         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>')
@@ -70,13 +74,13 @@ if __name__ == "__main__":
     tornado.options.parse_command_line()
 
     application = tornado.web.Application([
-        (r"/io", webio_handler(index)),
-        (r"/bmi", webio_handler(bmi)),
-        (r"/chat_room", webio_handler(chat_room)),
-        (r"/input_usage", webio_handler(input_usage)),
-        (r"/output_usage", webio_handler(output_usage)),
-        (r"/doc_demo", webio_handler(get_doc_demo_app())),
-        (r"/set_env_demo", webio_handler(set_env_demo)),
+        (r"/", webio_handler(index, cdn=False)),
+        (r"/bmi", webio_handler(bmi, cdn=False)),
+        (r"/chat_room", webio_handler(chat_room, cdn=False)),
+        (r"/input_usage", webio_handler(input_usage, cdn=False)),
+        (r"/output_usage", webio_handler(output_usage, cdn=False)),
+        (r"/doc_demo", webio_handler(get_doc_demo_app(), cdn=False)),
+        (r"/set_env_demo", webio_handler(set_env_demo, cdn=False)),
         (r"/(.*)", tornado.web.StaticFileHandler, {"path": STATIC_PATH, 'default_filename': 'index.html'})
     ])
     application.listen(port=options.port)

+ 5 - 2
demos/bmi.py

@@ -13,7 +13,10 @@ from pywebio.session import set_env
 
 
 def main():
-    set_env(title="BMI Calculation")
+    """BMI Calculation
+
+    计算BMI指数的简单应用
+    """
 
     put_markdown("""# BMI指数
 
@@ -53,4 +56,4 @@ def main():
 
 
 if __name__ == '__main__':
-    start_server(main, debug=True, port=8080)
+    start_server(main, debug=True, port=8080, cdn=False)

+ 1 - 1
demos/bokeh_app.py

@@ -48,4 +48,4 @@ def main():
 
 
 if __name__ == '__main__':
-    start_server(main, port=8080, debug=True)
+    start_server(main, port=8080, debug=True, cdn=False)

+ 5 - 3
demos/chat_room.py

@@ -41,9 +41,11 @@ async def refresh_msg(my_name, msg_box):
 
 
 async def main():
-    global chat_msgs
+    """PyWebIO聊天室
 
-    set_env(title="PyWebIO Chat Room")
+    和当前所有在线的人聊天
+    """
+    global chat_msgs
 
     put_markdown("## PyWebIO聊天室\n欢迎来到聊天室,你可以和当前所有在线的人聊天。你可以在浏览器的多个标签页中打开本页面来测试聊天效果。"
     "本应用使用不到80行代码实现,源代码[链接](https://github.com/wang0618/PyWebIO/blob/dev/demos/chat_room.py)", lstrip=True)
@@ -82,4 +84,4 @@ async def main():
 
 
 if __name__ == '__main__':
-    start_server(main, debug=True, port=8080)
+    start_server(main, debug=True, port=8080, cdn=False)

+ 8 - 14
demos/doc_demo.py

@@ -8,6 +8,7 @@ from pywebio.output import *
 from pywebio.session import *
 from os import path, listdir
 from functools import partial
+from pywebio.platform import seo
 
 here_dir = path.dirname(path.abspath(__file__))
 
@@ -80,32 +81,25 @@ def handle_code(code, title):
 
 
 def get_app():
+    """PyWebIO demos from document
+
+    Run the demos from the document online.
+    """
     app = {}
     try:
         demos = listdir(path.join(here_dir, 'doc_demos'))
     except Exception:
         demos = []
 
-    demo_infos = []
     for name in demos:
         code = open(path.join(here_dir, 'doc_demos', name)).read()
         title, code = code.split('\n\n', 1)
         app[name] = partial(handle_code, code=code, title=title)
-        demo_infos.append([name, title])
-
-    index_html = "<ul>"
-    for name, title in demo_infos:
-        index_html += '''<li> <a href="javascript:WebIO.openApp('{name}', true)">{name}</a>: {desc} </li>\n'''.format(
-            name=name, desc=title)
-    index_html += "</ul>"
-
-    def index():
-        put_markdown('# PyWebIO Document Code Example Index')
-        put_html(index_html)
+        app[name] = seo('', title, app[name])
 
-    app['index'] = index
     return app
 
 
 if __name__ == '__main__':
-    start_server(get_app(), debug=True, port=8080)
+    a = get_app()
+    start_server(get_app(), debug=True, port=8080, cdn=False)

+ 6 - 2
demos/input_usage.py

@@ -12,7 +12,11 @@ from pywebio.session import set_env
 
 
 def main():
-    set_env(title="PyWebIO输入演示", auto_scroll_bottom=True)
+    """PyWebIO输入演示
+
+    演示PyWebIO支持的各种输入形式
+    """
+    set_env(auto_scroll_bottom=True)
 
     put_markdown("""# PyWebIO 输入演示
     
@@ -154,4 +158,4 @@ def main():
 
 
 if __name__ == '__main__':
-    start_server(main, debug=True, port=8080)
+    start_server(main, debug=True, port=8080, cdn=False)

+ 4 - 2
demos/output_usage.py

@@ -31,8 +31,10 @@ def code_block(code, strip_indent=4):
 
 
 async def main():
-    set_env(title="PyWebIO输出演示")
+    """PyWebIO输出演示
 
+    演示PyWebIO支持的各种输出形式
+    """
     put_markdown("""# PyWebIO 输出演示
     
     在[这里](https://github.com/wang0618/PyWebIO/blob/dev/demos/output_usage.py)可以获取本Demo的源码。
@@ -285,4 +287,4 @@ async def main():
 
 
 if __name__ == '__main__':
-    start_server(main, debug=True, port=8080)
+    start_server(main, debug=True, port=8080, cdn=False)

+ 3 - 1
demos/set_env_demo.py

@@ -11,6 +11,8 @@ import asyncio
 
 
 async def main():
+    """`pywebio.session.set_env()` demo"""
+
     set_scope('time')
     put_markdown('> 可用于观察 `output_animation` 项的动画效果')
     put_markdown('---')
@@ -50,4 +52,4 @@ async def main():
 
 
 if __name__ == '__main__':
-    start_server(main, debug=True, port=8080)
+    start_server(main, debug=True, port=8080, cdn=False)