Răsfoiți Sursa

update doc and usage demo

wangweimin 3 ani în urmă
părinte
comite
ba01978a1b

+ 1 - 1
demos/__main__.py

@@ -136,6 +136,6 @@ if __name__ == "__main__":
         (r"/markdown_previewer", webio_handler(markdown_previewer, cdn=False)),
         (r"/gomoku_game", webio_handler(gomoku_game, cdn=False)),
         (r"/(.*)", tornado.web.StaticFileHandler, {"path": STATIC_PATH, 'default_filename': 'index.html'})
-    ])
+    ], websocket_ping_interval=30)
     application.listen(port=options.port)
     tornado.ioloop.IOLoop.current().start()

+ 31 - 20
demos/output_usage.py

@@ -175,7 +175,9 @@ async def main():
     def btn_click(btn_val):
         put_markdown("> You click `%s` button" % btn_val)
 
-    put_buttons(['A', 'B', 'C'], onclick=btn_click)
+    put_buttons(['A', 'B', 'C'], onclick=btn_click)  # a group of buttons
+
+    put_button("Click me", onclick=lambda: toast("Clicked"))  # single button
     ```
     """, strip_indent=4)
 
@@ -184,8 +186,32 @@ async def main():
         put_markdown("> You click `%s` button" % btn_val)
 
     put_buttons(['A', 'B', 'C'], onclick=btn_click)
+    put_button("Click me", onclick=lambda: toast("Clicked"))
     set_scope('button-callback')
 
+    put_markdown(t("In fact, all output can be bound to click events, not just buttons. You can call `onclick()` method after the output function (function name like `put_xxx()`) call:", "事实上,不仅是按钮,所有的输出都可以绑定点击事件。你可以在输出函数之后调用 `onclick()` 方法来绑定点击事件:")+r"""
+    ```python
+    put_image('some-image.png').onclick(lambda: toast('You click the image'))  
+
+    # set onclick in combined output
+    put_table([
+        ['Commodity', 'Price'],
+        ['Apple', put_text('5.5').onclick(lambda: toast('You click the text'))],
+    ])
+    ```
+    """, strip_indent=4)
+
+    put_image('https://www.python.org/static/img/python-logo.png').onclick(lambda: toast('You click the image'))
+    # set onclick in combined output
+    put_table([
+        ['Commodity', 'Price'],
+        ['Apple', put_text('5.5').onclick(lambda: toast('You click the text'))],
+    ])
+
+    put_markdown(t("The return value of `onclick()` method is the object itself so it can be used in combined output.",
+        "`onclick()` 方法的返回值为对象本身,所以可以继续用于组合输出中。"))
+
+
     put_markdown(t(r"""### Output Scope
     
     PyWebIO uses the scope model to give more control to the location of content output. The output area of PyWebIO can be divided into different output domains. The output domain is called Scope in PyWebIO.
@@ -307,40 +333,25 @@ async def main():
     """ % t('None represents the space between the output', 'None 表示输出之间的空白'))
 
     put_markdown(t(r"""### Style
-    If you are familiar with CSS styles, you can use the `style()` function to set a custom style for the output.
+    If you are familiar with CSS styles, you can use the `style()` method to set a custom style for the output.
 
     You can set the CSS style for a single `put_xxx()` output:
     """, r"""### 样式
     
-    如果你熟悉 CSS样式 ,你还可以使用 `style()` 函数给输出设定自定义样式。
+    如果你熟悉 CSS样式 ,你还可以使用 `style()` 方法给输出设定自定义样式。
 
     可以给单个的 `put_xxx()` 输出设定CSS样式,也可以配合组合输出使用:
     """), strip_indent=4)
 
     code_block(r"""
-    style(put_text('Red'), 'color: red')
+    put_text('Red').style('color: red')
     
     put_table([
         ['A', 'B'],
-        ['C', style(put_text('Red'), 'color: red')],
+        ['C', put_text('Red').style('color: red')],
     ])
     """, strip_indent=4)
 
-    put_markdown(t(r"`style()` also accepts a list of output calls:", r"`style()` 也接受列表作为输入:"))
-
-    code_block(r"""
-    style([
-        put_text('Red'),
-        put_markdown('~~del~~')
-    ], 'color: red')
-    
-    put_collapse('title', style([
-        put_text('text'),
-        put_markdown('~~del~~'),
-    ], 'margin-left: 20px'))
-
-    """, strip_indent=4)
-
     put_markdown(t("""----
     For more information about output of PyWebIO, please visit PyWebIO [User Guide](https://pywebio.readthedocs.io/zh_CN/latest/guide.html) and [output module documentation](https://pywebio.readthedocs.io/zh_CN/latest/output.html).
     ""","""----

+ 2 - 2
docs/conf.py

@@ -19,8 +19,8 @@ version = release = pywebio.__version__
 # -- Project information -----------------------------------------------------
 
 project = 'PyWebIO'
-copyright = 'WangWeimin'
-author = 'WangWeimin'
+copyright = 'Weimin Wang'
+author = 'Weimin Wang'
 
 # -- General configuration ---------------------------------------------------
 

+ 3 - 3
docs/guide.rst

@@ -196,7 +196,7 @@ can be called at any time during the application lifetime.
 Basic Output
 ^^^^^^^^^^^^^^
 
-PyWebIO provides a series of functions to output text, tables, images, etc:
+Using output functions, you can output a variety of content, such as text, tables, images and so on:
 
 .. exportable-codeblock::
     :name: basic-output
@@ -386,9 +386,9 @@ Of course, PyWebIO also supports outputting individual button:
     def btn_click(btn_val):
         put_text("You click %s button" % btn_val)
 
-    put_buttons(['A', 'B', 'C'], onclick=btn_click)
+    put_buttons(['A', 'B', 'C'], onclick=btn_click)  # a group of buttons
 
-    put_button("Click me", onclick=lambda: toast("Clicked"))
+    put_button("Click me", onclick=lambda: toast("Clicked"))  # single button
 
 In fact, all output can be bound to click events, not just buttons. You can call ``onclick()`` method after the output
 function (function name like ``put_xxx()``) call:

+ 1 - 1
docs/index.rst

@@ -1,7 +1,7 @@
 PyWebIO
 ==========
 
-PyWebIO provides a series of imperative functions to obtain user input and output content on the browser,
+PyWebIO provides a diverse set of imperative functions to obtain user input and output content on the browser,
 turning the browser into a "rich text terminal", and can be used to build simple web applications or browser-based
 GUI applications. Using PyWebIO, developers can write applications just like writing terminal scripts
 (interaction based on input and print function), without the need to have knowledge of HTML and JS.

+ 8 - 5
docs/locales/zh_CN/LC_MESSAGES/guide.po

@@ -7,8 +7,8 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PyWebIO 1.1.0\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2021-10-05 13:59+0800\n"
-"PO-Revision-Date: 2021-10-05 16:18+0800\n"
+"POT-Creation-Date: 2021-10-12 12:32+0800\n"
+"PO-Revision-Date: 2021-10-12 12:35+0800\n"
 "Last-Translator: WangWeimin <wang0.618@qq.com>\n"
 "Language: zh_CN\n"
 "Language-Team: \n"
@@ -294,7 +294,7 @@ msgid "Basic Output"
 msgstr "基本输出"
 
 #: ../../guide.rst:199
-msgid "PyWebIO provides a series of functions to output text, tables, images, etc:"
+msgid "Using output functions, you can output a variety of content, such as text, tables, images and so on:"
 msgstr "PyWebIO提供了一系列函数来输出文本、表格、图像等格式:"
 
 #: ../../guide.rst:201
@@ -513,9 +513,9 @@ msgid ""
 "def btn_click(btn_val):\n"
 "    put_text(\"You click %s button\" % btn_val)\n"
 "\n"
-"put_buttons(['A', 'B', 'C'], onclick=btn_click)\n"
+"put_buttons(['A', 'B', 'C'], onclick=btn_click)  # a group of buttons\n"
 "\n"
-"put_button(\"Click me\", onclick=lambda: toast(\"Clicked\"))"
+"put_button(\"Click me\", onclick=lambda: toast(\"Clicked\"))  # single button"
 msgstr ""
 
 #: ../../guide.rst:393
@@ -1714,3 +1714,6 @@ msgstr ""
 #~ msgstr ""
 #~ "将PyWebIO应用部署为web服务的另一种方式是使用 `path_deploy() <pywebio.platform.path_deploy>` 。`path_deploy() <pywebio.platform.path_deploy>` 可以"
 #~ "从一个目录中部署PyWebIO应用,只需要在该目录下的python文件中定义PyWebIO应用,就可以通过URL中的路径来访问这些应用了。"
+
+#~ msgid "PyWebIO provides a series of functions to output text, tables, images, etc:"
+#~ msgstr "PyWebIO提供了一系列函数来输出文本、表格、图像等格式:"

+ 6 - 6
docs/locales/zh_CN/LC_MESSAGES/index.po

@@ -7,8 +7,8 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PyWebIO 1.1.0\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2021-10-05 13:39+0800\n"
-"PO-Revision-Date: 2021-10-05 14:48+0800\n"
+"POT-Creation-Date: 2021-10-12 12:32+0800\n"
+"PO-Revision-Date: 2021-10-12 12:32+0800\n"
 "Last-Translator: WangWeimin <wang0.618@qq.com>\n"
 "Language: zh_CN\n"
 "Language-Team: \n"
@@ -33,10 +33,10 @@ msgstr "PyWebIO"
 
 #: ../../index.rst:4
 msgid ""
-"PyWebIO provides a series of imperative functions to obtain user input and output "
-"content on the browser, turning the browser into a \"rich text terminal\", and can "
-"be used to build simple web applications or browser-based GUI applications. Using "
-"PyWebIO, developers can write applications just like writing terminal scripts "
+"PyWebIO provides a diverse set of imperative functions to obtain user input and "
+"output content on the browser, turning the browser into a \"rich text terminal\", "
+"and can be used to build simple web applications or browser-based GUI applications. "
+"Using PyWebIO, developers can write applications just like writing terminal scripts "
 "(interaction based on input and print function), without the need to have knowledge "
 "of HTML and JS. PyWebIO can also be easily integrated into existing Web services. "
 "PyWebIO is very suitable for quickly building applications that do not require "

+ 9 - 9
docs/locales/zh_CN/LC_MESSAGES/platform.po

@@ -7,8 +7,8 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PyWebIO 1.1.0\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2021-10-05 16:10+0800\n"
-"PO-Revision-Date: 2021-10-05 16:11+0800\n"
+"POT-Creation-Date: 2021-10-12 12:32+0800\n"
+"PO-Revision-Date: 2021-10-12 12:36+0800\n"
 "Last-Translator: WangWeimin <wang0.618@qq.com>\n"
 "Language: zh_CN\n"
 "Language-Team: \n"
@@ -159,12 +159,12 @@ msgstr "你可以在文件夹中创建一个 `index.py` PyWebIO应用文件来
 msgid ""
 "Directory to store the application static files. The files in this directory can "
 "be accessed via ``http://<host>:<port>/static/files``. For example, if there is a "
-"``A/B.jpg`` file in ``http_static_dir`` path, it can be accessed via ``http://"
-"<host>:<port>/static/A/B.jpg``."
+"``A/B.jpg`` file in ``static_dir`` path, it can be accessed via ``http://<host>:"
+"<port>/static/A/B.jpg``."
 msgstr ""
 "应用静态文件目录。目录下的文件可以通过 ``http://<host>:<port>/static/files`` 访问。"
-"例如 ``http_static_dir`` 路径下存在文件 ``A/B.jpg`` ,则其URL为 ``http://<host>:"
-"<port>/static/A/B.jpg``。"
+"例如 ``static_dir`` 路径下存在文件 ``A/B.jpg`` ,则其URL为 ``http://<host>:<port>/"
+"static/A/B.jpg``。"
 
 #: of pywebio.platform.path_deploy.path_deploy:17
 #: pywebio.platform.tornado.start_server:31
@@ -347,12 +347,12 @@ msgstr ""
 msgid ""
 "The directory to store the application static files. The files in this directory "
 "can be accessed via ``http://<host>:<port>/static/files``. For example, if there "
-"is a ``A/B.jpg`` file in ``http_static_dir`` path, it can be accessed via ``http://"
+"is a ``A/B.jpg`` file in ``static_dir`` path, it can be accessed via ``http://"
 "<host>:<port>/static/A/B.jpg``."
 msgstr ""
 "应用静态文件目录。目录下的文件可以通过 ``http://<host>:<port>/static/files`` 访问。"
-"例如 ``http_static_dir`` 路径下存在文件 ``A/B.jpg`` ,则其URL为 ``http://<host>:"
-"<port>/static/A/B.jpg``。"
+"例如 ``static_dir`` 路径下存在文件 ``A/B.jpg`` ,则其URL为 ``http://<host>:<port>/"
+"static/A/B.jpg``。"
 
 #: of pywebio.platform.tornado.start_server:27
 msgid ""