Skip to content

Commit ba01978

Browse files
committed
update doc and usage demo
1 parent de46507 commit ba01978

File tree

8 files changed

+61
-47
lines changed

8 files changed

+61
-47
lines changed

demos/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,6 @@ def index():
136136
(r"/markdown_previewer", webio_handler(markdown_previewer, cdn=False)),
137137
(r"/gomoku_game", webio_handler(gomoku_game, cdn=False)),
138138
(r"/(.*)", tornado.web.StaticFileHandler, {"path": STATIC_PATH, 'default_filename': 'index.html'})
139-
])
139+
], websocket_ping_interval=30)
140140
application.listen(port=options.port)
141141
tornado.ioloop.IOLoop.current().start()

demos/output_usage.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ def edit_row(choice, row):
175175
def btn_click(btn_val):
176176
put_markdown("> You click `%s` button" % btn_val)
177177
178-
put_buttons(['A', 'B', 'C'], onclick=btn_click)
178+
put_buttons(['A', 'B', 'C'], onclick=btn_click) # a group of buttons
179+
180+
put_button("Click me", onclick=lambda: toast("Clicked")) # single button
179181
```
180182
""", strip_indent=4)
181183

@@ -184,8 +186,32 @@ def btn_click(btn_val):
184186
put_markdown("> You click `%s` button" % btn_val)
185187

186188
put_buttons(['A', 'B', 'C'], onclick=btn_click)
189+
put_button("Click me", onclick=lambda: toast("Clicked"))
187190
set_scope('button-callback')
188191

192+
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"""
193+
```python
194+
put_image('some-image.png').onclick(lambda: toast('You click the image'))
195+
196+
# set onclick in combined output
197+
put_table([
198+
['Commodity', 'Price'],
199+
['Apple', put_text('5.5').onclick(lambda: toast('You click the text'))],
200+
])
201+
```
202+
""", strip_indent=4)
203+
204+
put_image('https://www.python.org/static/img/python-logo.png').onclick(lambda: toast('You click the image'))
205+
# set onclick in combined output
206+
put_table([
207+
['Commodity', 'Price'],
208+
['Apple', put_text('5.5').onclick(lambda: toast('You click the text'))],
209+
])
210+
211+
put_markdown(t("The return value of `onclick()` method is the object itself so it can be used in combined output.",
212+
"`onclick()` 方法的返回值为对象本身,所以可以继续用于组合输出中。"))
213+
214+
189215
put_markdown(t(r"""### Output Scope
190216
191217
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 @@ def btn_click(btn_val):
307333
""" % t('None represents the space between the output', 'None 表示输出之间的空白'))
308334

309335
put_markdown(t(r"""### Style
310-
If you are familiar with CSS styles, you can use the `style()` function to set a custom style for the output.
336+
If you are familiar with CSS styles, you can use the `style()` method to set a custom style for the output.
311337
312338
You can set the CSS style for a single `put_xxx()` output:
313339
""", r"""### 样式
314340
315-
如果你熟悉 CSS样式 ,你还可以使用 `style()` 函数给输出设定自定义样式
341+
如果你熟悉 CSS样式 ,你还可以使用 `style()` 方法给输出设定自定义样式
316342
317343
可以给单个的 `put_xxx()` 输出设定CSS样式,也可以配合组合输出使用:
318344
"""), strip_indent=4)
319345

320346
code_block(r"""
321-
style(put_text('Red'), 'color: red')
347+
put_text('Red').style('color: red')
322348
323349
put_table([
324350
['A', 'B'],
325-
['C', style(put_text('Red'), 'color: red')],
351+
['C', put_text('Red').style('color: red')],
326352
])
327353
""", strip_indent=4)
328354

329-
put_markdown(t(r"`style()` also accepts a list of output calls:", r"`style()` 也接受列表作为输入:"))
330-
331-
code_block(r"""
332-
style([
333-
put_text('Red'),
334-
put_markdown('~~del~~')
335-
], 'color: red')
336-
337-
put_collapse('title', style([
338-
put_text('text'),
339-
put_markdown('~~del~~'),
340-
], 'margin-left: 20px'))
341-
342-
""", strip_indent=4)
343-
344355
put_markdown(t("""----
345356
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).
346357
""","""----

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
# -- Project information -----------------------------------------------------
2020

2121
project = 'PyWebIO'
22-
copyright = 'WangWeimin'
23-
author = 'WangWeimin'
22+
copyright = 'Weimin Wang'
23+
author = 'Weimin Wang'
2424

2525
# -- General configuration ---------------------------------------------------
2626

docs/guide.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ can be called at any time during the application lifetime.
196196
Basic Output
197197
^^^^^^^^^^^^^^
198198

199-
PyWebIO provides a series of functions to output text, tables, images, etc:
199+
Using output functions, you can output a variety of content, such as text, tables, images and so on:
200200

201201
.. exportable-codeblock::
202202
:name: basic-output
@@ -386,9 +386,9 @@ Of course, PyWebIO also supports outputting individual button:
386386
def btn_click(btn_val):
387387
put_text("You click %s button" % btn_val)
388388

389-
put_buttons(['A', 'B', 'C'], onclick=btn_click)
389+
put_buttons(['A', 'B', 'C'], onclick=btn_click) # a group of buttons
390390

391-
put_button("Click me", onclick=lambda: toast("Clicked"))
391+
put_button("Click me", onclick=lambda: toast("Clicked")) # single button
392392

393393
In fact, all output can be bound to click events, not just buttons. You can call ``onclick()`` method after the output
394394
function (function name like ``put_xxx()``) call:

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PyWebIO
22
==========
33

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

docs/locales/zh_CN/LC_MESSAGES/guide.po

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: PyWebIO 1.1.0\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2021-10-05 13:59+0800\n"
11-
"PO-Revision-Date: 2021-10-05 16:18+0800\n"
10+
"POT-Creation-Date: 2021-10-12 12:32+0800\n"
11+
"PO-Revision-Date: 2021-10-12 12:35+0800\n"
1212
"Last-Translator: WangWeimin <[email protected]>\n"
1313
"Language: zh_CN\n"
1414
"Language-Team: \n"
@@ -294,7 +294,7 @@ msgid "Basic Output"
294294
msgstr "基本输出"
295295

296296
#: ../../guide.rst:199
297-
msgid "PyWebIO provides a series of functions to output text, tables, images, etc:"
297+
msgid "Using output functions, you can output a variety of content, such as text, tables, images and so on:"
298298
msgstr "PyWebIO提供了一系列函数来输出文本、表格、图像等格式:"
299299

300300
#: ../../guide.rst:201
@@ -513,9 +513,9 @@ msgid ""
513513
"def btn_click(btn_val):\n"
514514
" put_text(\"You click %s button\" % btn_val)\n"
515515
"\n"
516-
"put_buttons(['A', 'B', 'C'], onclick=btn_click)\n"
516+
"put_buttons(['A', 'B', 'C'], onclick=btn_click) # a group of buttons\n"
517517
"\n"
518-
"put_button(\"Click me\", onclick=lambda: toast(\"Clicked\"))"
518+
"put_button(\"Click me\", onclick=lambda: toast(\"Clicked\")) # single button"
519519
msgstr ""
520520

521521
#: ../../guide.rst:393
@@ -1714,3 +1714,6 @@ msgstr ""
17141714
#~ msgstr ""
17151715
#~ "将PyWebIO应用部署为web服务的另一种方式是使用 `path_deploy() <pywebio.platform.path_deploy>` 。`path_deploy() <pywebio.platform.path_deploy>` 可以"
17161716
#~ "从一个目录中部署PyWebIO应用,只需要在该目录下的python文件中定义PyWebIO应用,就可以通过URL中的路径来访问这些应用了。"
1717+
1718+
#~ msgid "PyWebIO provides a series of functions to output text, tables, images, etc:"
1719+
#~ msgstr "PyWebIO提供了一系列函数来输出文本、表格、图像等格式:"

docs/locales/zh_CN/LC_MESSAGES/index.po

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: PyWebIO 1.1.0\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2021-10-05 13:39+0800\n"
11-
"PO-Revision-Date: 2021-10-05 14:48+0800\n"
10+
"POT-Creation-Date: 2021-10-12 12:32+0800\n"
11+
"PO-Revision-Date: 2021-10-12 12:32+0800\n"
1212
"Last-Translator: WangWeimin <[email protected]>\n"
1313
"Language: zh_CN\n"
1414
"Language-Team: \n"
@@ -33,10 +33,10 @@ msgstr "PyWebIO"
3333

3434
#: ../../index.rst:4
3535
msgid ""
36-
"PyWebIO provides a series of imperative functions to obtain user input and output "
37-
"content on the browser, turning the browser into a \"rich text terminal\", and can "
38-
"be used to build simple web applications or browser-based GUI applications. Using "
39-
"PyWebIO, developers can write applications just like writing terminal scripts "
36+
"PyWebIO provides a diverse set of imperative functions to obtain user input and "
37+
"output content on the browser, turning the browser into a \"rich text terminal\", "
38+
"and can be used to build simple web applications or browser-based GUI applications. "
39+
"Using PyWebIO, developers can write applications just like writing terminal scripts "
4040
"(interaction based on input and print function), without the need to have knowledge "
4141
"of HTML and JS. PyWebIO can also be easily integrated into existing Web services. "
4242
"PyWebIO is very suitable for quickly building applications that do not require "

docs/locales/zh_CN/LC_MESSAGES/platform.po

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: PyWebIO 1.1.0\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2021-10-05 16:10+0800\n"
11-
"PO-Revision-Date: 2021-10-05 16:11+0800\n"
10+
"POT-Creation-Date: 2021-10-12 12:32+0800\n"
11+
"PO-Revision-Date: 2021-10-12 12:36+0800\n"
1212
"Last-Translator: WangWeimin <[email protected]>\n"
1313
"Language: zh_CN\n"
1414
"Language-Team: \n"
@@ -159,12 +159,12 @@ msgstr "你可以在文件夹中创建一个 `index.py` PyWebIO应用文件来
159159
msgid ""
160160
"Directory to store the application static files. The files in this directory can "
161161
"be accessed via ``http://<host>:<port>/static/files``. For example, if there is a "
162-
"``A/B.jpg`` file in ``http_static_dir`` path, it can be accessed via ``http://"
163-
"<host>:<port>/static/A/B.jpg``."
162+
"``A/B.jpg`` file in ``static_dir`` path, it can be accessed via ``http://<host>:"
163+
"<port>/static/A/B.jpg``."
164164
msgstr ""
165165
"应用静态文件目录。目录下的文件可以通过 ``http://<host>:<port>/static/files`` 访问。"
166-
"例如 ``http_static_dir`` 路径下存在文件 ``A/B.jpg`` ,则其URL为 ``http://<host>:"
167-
"<port>/static/A/B.jpg``。"
166+
"例如 ``static_dir`` 路径下存在文件 ``A/B.jpg`` ,则其URL为 ``http://<host>:<port>/"
167+
"static/A/B.jpg``。"
168168

169169
#: of pywebio.platform.path_deploy.path_deploy:17
170170
#: pywebio.platform.tornado.start_server:31
@@ -347,12 +347,12 @@ msgstr ""
347347
msgid ""
348348
"The directory to store the application static files. The files in this directory "
349349
"can be accessed via ``http://<host>:<port>/static/files``. For example, if there "
350-
"is a ``A/B.jpg`` file in ``http_static_dir`` path, it can be accessed via ``http://"
350+
"is a ``A/B.jpg`` file in ``static_dir`` path, it can be accessed via ``http://"
351351
"<host>:<port>/static/A/B.jpg``."
352352
msgstr ""
353353
"应用静态文件目录。目录下的文件可以通过 ``http://<host>:<port>/static/files`` 访问。"
354-
"例如 ``http_static_dir`` 路径下存在文件 ``A/B.jpg`` ,则其URL为 ``http://<host>:"
355-
"<port>/static/A/B.jpg``。"
354+
"例如 ``static_dir`` 路径下存在文件 ``A/B.jpg`` ,则其URL为 ``http://<host>:<port>/"
355+
"static/A/B.jpg``。"
356356

357357
#: of pywebio.platform.tornado.start_server:27
358358
msgid ""

0 commit comments

Comments
 (0)