__main__.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import tornado.ioloop
  2. import tornado.web
  3. from demos.bmi import main as bmi
  4. from demos.chat_room import main as chat_room
  5. from demos.input_usage import main as input_usage
  6. from demos.output_usage import main as output_usage
  7. from demos.config import charts_demo_host
  8. from demos.doc_demo import get_app as get_doc_demo_app
  9. from pywebio import STATIC_PATH
  10. from pywebio.output import put_markdown
  11. from pywebio.session import set_env
  12. from pywebio.platform.tornado import webio_handler
  13. from tornado.options import define, options
  14. index_md = r"""# PyWebIO demos
  15. ### 基本demo
  16. - [BMI计算](./?pywebio_api=bmi): 根据身高体重计算BMI指数 [源码](https://github.com/wang0618/PyWebIO/blob/master/demos/bmi.py)
  17. - [聊天室](./?pywebio_api=chat_room): 和当前所有在线的人聊天 [源码](https://github.com/wang0618/PyWebIO/blob/master/demos/chat_room.py)
  18. - [输入演示](./?pywebio_api=input_usage): 演示PyWebIO输入模块的用法 [源码](https://github.com/wang0618/PyWebIO/blob/master/demos/input_usage.py)
  19. - [输出演示](./?pywebio_api=output_usage): 演示PyWebIO输出模块的用法 [源码](https://github.com/wang0618/PyWebIO/blob/master/demos/output_usage.py)
  20. - 更多Demo请见[文档](https://pywebio.readthedocs.io)中示例代码的在线Demo
  21. ### 数据可视化demo
  22. PyWebIO还支持使用第三方库进行数据可视化
  23. - 使用`pyecharts`创建基于Echarts的图表 [**demos**]({charts_demo_host}/?pywebio_api=pyecharts)
  24. - 使用`cutecharts.py`创建卡通风格图表 [**demos**]({charts_demo_host}/?pywebio_api=cutecharts)
  25. - 使用`plotly`进行数据可视化 [**demos**]({charts_demo_host}/?pywebio_api=plotly)
  26. **数据可视化demo截图**
  27. ![pyecharts](https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/pyecharts.gif)
  28. ![cutecharts](https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/cutecharts.png)
  29. ![plotly](https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/plotly.png)
  30. ### Links
  31. * PyWebIO Github [github.com/wang0618/PyWebIO](https://github.com/wang0618/PyWebIO)
  32. * 使用手册和实现文档见 [pywebio.readthedocs.io](https://pywebio.readthedocs.io)
  33. """.format(charts_demo_host=charts_demo_host)
  34. def index():
  35. set_env(auto_scroll_bottom=False)
  36. put_markdown(index_md)
  37. if __name__ == "__main__":
  38. define("port", default=8080, help="run on the given port", type=int)
  39. tornado.options.parse_command_line()
  40. application = tornado.web.Application([
  41. (r"/io", webio_handler(index)),
  42. (r"/bmi", webio_handler(bmi)),
  43. (r"/chat_room", webio_handler(chat_room)),
  44. (r"/input_usage", webio_handler(input_usage)),
  45. (r"/output_usage", webio_handler(output_usage)),
  46. (r"/doc_demo", webio_handler(get_doc_demo_app())),
  47. (r"/(.*)", tornado.web.StaticFileHandler, {"path": STATIC_PATH, 'default_filename': 'index.html'})
  48. ])
  49. application.listen(port=options.port)
  50. tornado.ioloop.IOLoop.current().start()