__main__.py 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 demos.set_env_demo import main as set_env_demo
  10. from pywebio import STATIC_PATH
  11. from pywebio.output import put_markdown, put_row, put_html, style
  12. from pywebio.platform.tornado import webio_handler
  13. from tornado.options import define, options
  14. index_md = r"""### 基本demo
  15. - [BMI计算](./?pywebio_api=bmi): 根据身高体重计算BMI指数 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/bmi.py)
  16. - [聊天室](./?pywebio_api=chat_room): 和当前所有在线的人聊天 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/chat_room.py)
  17. - [输入演示](./?pywebio_api=input_usage): 演示PyWebIO输入模块的用法 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/input_usage.py)
  18. - [输出演示](./?pywebio_api=output_usage): 演示PyWebIO输出模块的用法 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/output_usage.py)
  19. - 更多Demo请见[文档](https://pywebio.readthedocs.io)中示例代码的在线Demo
  20. ### 数据可视化demo
  21. PyWebIO还支持使用第三方库进行数据可视化
  22. - 使用`bokeh`进行数据可视化 [**demos**]({charts_demo_host}/?app=bokeh)
  23. - 使用`plotly`进行数据可视化 [**demos**]({charts_demo_host}/?app=plotly)
  24. - 使用`pyecharts`创建基于Echarts的图表 [**demos**]({charts_demo_host}/?app=pyecharts)
  25. - 使用`cutecharts.py`创建卡通风格图表 [**demos**]({charts_demo_host}/?app=cutecharts)
  26. **数据可视化demo截图**
  27. <a href="{charts_demo_host}/?app=bokeh">
  28. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/bokeh.png" alt="bokeh demo">
  29. </a>
  30. <a href="{charts_demo_host}/?app=plotly">
  31. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/plotly.png" alt="plotly demo">
  32. </a>
  33. <a href="{charts_demo_host}/?app=pyecharts">
  34. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/pyecharts.gif" alt="pyecharts demo">
  35. </a>
  36. <a href="{charts_demo_host}/?app=cutecharts">
  37. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/cutecharts.png" alt="cutecharts demo">
  38. </a>
  39. ### Links
  40. * PyWebIO Github [github.com/wang0618/PyWebIO](https://github.com/wang0618/PyWebIO)
  41. * 使用手册和实现文档见 [pywebio.readthedocs.io](https://pywebio.readthedocs.io)
  42. """.format(charts_demo_host=charts_demo_host)
  43. def index():
  44. style(put_row([
  45. put_markdown('# PyWebIO demos'),
  46. 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>')
  47. ], size='1fr auto'), 'align-items:center')
  48. put_html('<script async defer src="https://buttons.github.io/buttons.js"></script>')
  49. put_markdown(index_md)
  50. if __name__ == "__main__":
  51. define("port", default=8080, help="run on the given port", type=int)
  52. tornado.options.parse_command_line()
  53. application = tornado.web.Application([
  54. (r"/io", webio_handler(index)),
  55. (r"/bmi", webio_handler(bmi)),
  56. (r"/chat_room", webio_handler(chat_room)),
  57. (r"/input_usage", webio_handler(input_usage)),
  58. (r"/output_usage", webio_handler(output_usage)),
  59. (r"/doc_demo", webio_handler(get_doc_demo_app())),
  60. (r"/set_env_demo", webio_handler(set_env_demo)),
  61. (r"/(.*)", tornado.web.StaticFileHandler, {"path": STATIC_PATH, 'default_filename': 'index.html'})
  62. ])
  63. application.listen(port=options.port)
  64. tornado.ioloop.IOLoop.current().start()