wangweimin %!s(int64=5) %!d(string=hai) anos
pai
achega
5d16f1e7cf
Modificáronse 4 ficheiros con 25 adicións e 15 borrados
  1. BIN=BIN
      docs/assets/demo.gif
  2. BIN=BIN
      docs/assets/demo.png
  3. 9 1
      docs/conf.py
  4. 16 14
      docs/index.rst

BIN=BIN
docs/assets/demo.gif


BIN=BIN
docs/assets/demo.png


+ 9 - 1
docs/conf.py

@@ -9,7 +9,6 @@
 # Ensure we get the local copy of tornado instead of what's on the standard path
 import os
 import sys
-import sphinx_rtd_theme
 
 sys.path.insert(0, os.path.abspath(".."))
 import pywebio
@@ -59,3 +58,12 @@ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
 html_theme = "sphinx_rtd_theme"
 
 # -- Extension configuration -------------------------------------------------
+
+from sphinx.builders.html import StandaloneHTMLBuilder
+
+StandaloneHTMLBuilder.supported_image_types = [
+    'image/svg+xml',
+    'image/gif',
+    'image/png',
+    'image/jpeg'
+]

+ 16 - 14
docs/index.rst

@@ -30,24 +30,25 @@ Hello, world
 
 这是一个使用PywWebIO计算 `BMI指数 <https://en.wikipedia.org/wiki/Body_mass_index>`_ 的脚本::
 
-   # A simple script to calculate BMI
-   from pywebio.input import input
-   from pywebio.output import put_text
+    # A simple script to calculate BMI
+    from pywebio.input import input, FLOAT
+    from pywebio.output import put_text, set_output_fixed_height
 
-   def bmi():
-       height = input("请输入你的身高(cm):")
-       weight = input("请输入你的体重(kg):")
+    def bmi():
+        set_output_fixed_height(True)
+        height = input("请输入你的身高(cm):", type=FLOAT)
+        weight = input("请输入你的体重(kg):", type=FLOAT)
 
-       BMI = float(weight) / (float(height) / 100) ** 2
+        BMI = weight / (height / 100) ** 2
 
-       top_status = [(14.9, '极瘦'), (18.4, '偏瘦'),
-                     (22.9, '正常'), (27.5, '过重'),
-                     (40.0, '肥胖'), (float('inf'), '非常肥胖')]
+        top_status = [(14.9, '极瘦'), (18.4, '偏瘦'),
+                      (22.9, '正常'), (27.5, '过重'),
+                      (40.0, '肥胖'), (float('inf'), '非常肥胖')]
 
-       for top, status in top_status:
-           if BMI <= top:
-               put_text('你的 BMI 值: %.1f,身体状态:%s' % (BMI, status))
-               break
+        for top, status in top_status:
+            if BMI <= top:
+                put_text('你的 BMI 值: %.1f,身体状态:%s' % (BMI, status))
+                break
 
    if __name__ == '__main__':
        bmi()
@@ -55,6 +56,7 @@ Hello, world
 如果没有使用PywWebIO,这只是一个非常简单的脚本,而通过使用PywWebIO提供的输入输出函数,你可以在浏览器中与代码进行交互:
 
 .. image:: /assets/demo.*
+   :align: center
 
 将上面代码最后一行对 ``bmi()`` 的直接调用改为使用 `pywebio.start_server(bmi, port=80) <pywebio.platform.start_server>` 便可以在80端口提供 ``bmi()`` 服务。