__main__.py 2.7 KB

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