__main__.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 pywebio.session import get_info
  14. from tornado.options import define, options
  15. index_md = r"""### Basic demo
  16. - [BMI calculation](./bmi): Calculating Body Mass Index based on height and weight [source](https://github.com/wang0618/PyWebIO/blob/dev/demos/bmi.py)
  17. - [Online chat room](./chat_room): Chat with everyone currently online [source](https://github.com/wang0618/PyWebIO/blob/dev/demos/chat_room.py)
  18. - [Input demo](./input_usage): Demonstrate various input usage supported by PyWebIO [source](https://github.com/wang0618/PyWebIO/blob/dev/demos/input_usage.py)
  19. - [Output demo](./output_usage): Demonstrate various output usage supported by PyWebIO [source](https://github.com/wang0618/PyWebIO/blob/dev/demos/output_usage.py)
  20. ### Data visualization demo
  21. PyWebIO supports for data visualization with the third-party libraries.
  22. - Use `bokeh` for data visualization [**demos**]({charts_demo_host}/?app=bokeh)
  23. - Use `plotly` for data visualization [**demos**]({charts_demo_host}/?app=plotly)
  24. - Use `pyecharts` to create Echarts-based charts in Python [**demos**]({charts_demo_host}/?app=pyecharts)
  25. - Use `pyg2plot` to create G2Plot-based charts in Python [**demos**]({charts_demo_host}/?app=pyg2plot)
  26. - Use `cutecharts.py` to create hand drawing style charts [**demos**]({charts_demo_host}/?app=cutecharts)
  27. **Screenshots**
  28. <a href="{charts_demo_host}/?app=bokeh">
  29. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/bokeh.png" alt="bokeh demo">
  30. </a>
  31. <a href="{charts_demo_host}/?app=plotly">
  32. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/plotly.png" alt="plotly demo">
  33. </a>
  34. <a href="{charts_demo_host}/?app=pyecharts">
  35. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/pyecharts.gif" alt="pyecharts demo">
  36. </a>
  37. <a href="{charts_demo_host}/?app=cutecharts">
  38. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/cutecharts.png" alt="cutecharts demo">
  39. </a>
  40. ### Links
  41. * PyWebIO Github [github.com/wang0618/PyWebIO](https://github.com/wang0618/PyWebIO)
  42. * Document [pywebio.readthedocs.io](https://pywebio.readthedocs.io)
  43. """.format(charts_demo_host=charts_demo_host)
  44. index_md_zh = r"""### 基本demo
  45. - [BMI计算](./bmi): 根据身高体重计算BMI指数 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/bmi.py)
  46. - [聊天室](./chat_room): 和当前所有在线的人聊天 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/chat_room.py)
  47. - [输入演示](./input_usage): 演示PyWebIO输入模块的用法 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/input_usage.py)
  48. - [输出演示](./output_usage): 演示PyWebIO输出模块的用法 [源码](https://github.com/wang0618/PyWebIO/blob/dev/demos/output_usage.py)
  49. - 更多Demo请见[文档](https://pywebio.readthedocs.io)中示例代码的在线Demo
  50. ### 数据可视化demo
  51. PyWebIO还支持使用第三方库进行数据可视化
  52. - 使用`bokeh`进行数据可视化 [**demos**]({charts_demo_host}/?app=bokeh)
  53. - 使用`plotly`进行数据可视化 [**demos**]({charts_demo_host}/?app=plotly)
  54. - 使用`pyecharts`创建基于Echarts的图表 [**demos**]({charts_demo_host}/?app=pyecharts)
  55. - 使用`cutecharts.py`创建卡通风格图表 [**demos**]({charts_demo_host}/?app=cutecharts)
  56. **数据可视化demo截图**
  57. <a href="{charts_demo_host}/?app=bokeh">
  58. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/bokeh.png" alt="bokeh demo">
  59. </a>
  60. <a href="{charts_demo_host}/?app=plotly">
  61. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/plotly.png" alt="plotly demo">
  62. </a>
  63. <a href="{charts_demo_host}/?app=pyecharts">
  64. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/pyecharts.gif" alt="pyecharts demo">
  65. </a>
  66. <a href="{charts_demo_host}/?app=cutecharts">
  67. <img src="https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/cutecharts.png" alt="cutecharts demo">
  68. </a>
  69. ### Links
  70. * PyWebIO Github [github.com/wang0618/PyWebIO](https://github.com/wang0618/PyWebIO)
  71. * 使用手册和实现文档见 [pywebio.readthedocs.io](https://pywebio.readthedocs.io)
  72. """.format(charts_demo_host=charts_demo_host)
  73. def index():
  74. """PyWebIO demos
  75. Basic demo and data visualization demo of PyWebIO.
  76. PyWebIO的基本demo和数据可视化demo
  77. """
  78. style(put_row([
  79. put_markdown('# PyWebIO demos'),
  80. 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>')
  81. ], size='1fr auto'), 'align-items:center')
  82. put_html('<script async defer src="https://buttons.github.io/buttons.js"></script>')
  83. if 'zh' in get_info().user_language:
  84. put_markdown(index_md_zh)
  85. else:
  86. put_markdown(index_md)
  87. if __name__ == "__main__":
  88. define("port", default=8080, help="run on the given port", type=int)
  89. tornado.options.parse_command_line()
  90. application = tornado.web.Application([
  91. (r"/", webio_handler(index, cdn=False)),
  92. (r"/bmi", webio_handler(bmi, cdn=False)),
  93. (r"/chat_room", webio_handler(chat_room, cdn=False)),
  94. (r"/input_usage", webio_handler(input_usage, cdn=False)),
  95. (r"/output_usage", webio_handler(output_usage, cdn=False)),
  96. (r"/doc_demo", webio_handler(get_doc_demo_app(), cdn=False)),
  97. (r"/set_env_demo", webio_handler(set_env_demo, cdn=False)),
  98. (r"/(.*)", tornado.web.StaticFileHandler, {"path": STATIC_PATH, 'default_filename': 'index.html'})
  99. ])
  100. application.listen(port=options.port)
  101. tornado.ioloop.IOLoop.current().start()