浏览代码

update doc

wangweimin 5 年之前
父节点
当前提交
84ef740be8
共有 2 个文件被更改,包括 14 次插入6 次删除
  1. 11 4
      pywebio/input.py
  2. 3 2
      pywebio/output.py

+ 11 - 4
pywebio/input.py

@@ -15,7 +15,12 @@
     ])
     ])
     print(info['name'], info['age'])
     print(info['name'], info['age'])
 
 
-输入组中需要在每一项输入函数中提供 ``name`` 参数来用于在结果中标识不同输入项
+输入组中需要在每一项输入函数中提供 ``name`` 参数来用于在结果中标识不同输入项.
+
+.. note::
+   PyWebIO 根据是否在输入函数中传入 ``name`` 参数来判断输入函数是在 `input_group` 中还是被单独调用。
+   所以当你想要单独调用一个输入函数时,请不要设置 ``name`` 参数;而在 `input_group` 中调用输入函数时,**务必提供** ``name`` 参数
+
 """
 """
 
 
 import logging
 import logging
@@ -41,10 +46,10 @@ __all__ = ['TEXT', 'NUMBER', 'FLOAT', 'PASSWORD', 'CHECKBOX', 'RADIO', 'SELECT',
 
 
 
 
 def _parse_args(kwargs):
 def _parse_args(kwargs):
-    """处理传给各类input函数的原始参数,
+    """处理传给各类输入函数的原始参数,
     :return:(spec参数,valid_func)
     :return:(spec参数,valid_func)
     """
     """
-    # 对为None的参数忽处理
+    # 对为None的参数忽处理
     kwargs = {k: v for k, v in kwargs.items() if v is not None}
     kwargs = {k: v for k, v in kwargs.items() if v is not None}
     kwargs.update(kwargs.get('other_html_attrs', {}))
     kwargs.update(kwargs.get('other_html_attrs', {}))
     kwargs.pop('other_html_attrs', None)
     kwargs.pop('other_html_attrs', None)
@@ -306,12 +311,14 @@ def input_group(label, inputs, valid_func=None):
         else:
         else:
             raise RuntimeError("Can't get kwargs from single input")
             raise RuntimeError("Can't get kwargs from single input")
 
 
+        assert all(k in input_kwargs for k in ('item_spec', 'preprocess_func', 'valid_func')), RuntimeError(
+            "`inputs` value error in `input_group`. Did you forget to add `name` parameter in input function?")
+
         input_name = input_kwargs['item_spec']['name']
         input_name = input_kwargs['item_spec']['name']
         preprocess_funcs[input_name] = input_kwargs['preprocess_func']
         preprocess_funcs[input_name] = input_kwargs['preprocess_func']
         item_valid_funcs[input_name] = input_kwargs['valid_func']
         item_valid_funcs[input_name] = input_kwargs['valid_func']
         spec_inputs.append(input_kwargs['item_spec'])
         spec_inputs.append(input_kwargs['item_spec'])
 
 
-    # def add_autofocus(spec_inputs):
     if all('auto_focus' not in i for i in spec_inputs):  # 每一个输入项都没有设置autofocus参数
     if all('auto_focus' not in i for i in spec_inputs):  # 每一个输入项都没有设置autofocus参数
         for i in spec_inputs:
         for i in spec_inputs:
             text_inputs = {TEXT, NUMBER, PASSWORD, SELECT}  # todo update
             text_inputs = {TEXT, NUMBER, PASSWORD, SELECT}  # todo update

+ 3 - 2
pywebio/output.py

@@ -122,6 +122,7 @@ def put_text(text, inline=False, anchor=None, before=None, after=None):
     输出文本内容
     输出文本内容
 
 
     :param str text: 文本内容
     :param str text: 文本内容
+    :param bool inline: 文本行末不换行。默认换行
     :param str anchor: 为当前的输出内容标记锚点
     :param str anchor: 为当前的输出内容标记锚点
     :param str before: 在给定的锚点之前输出内容
     :param str before: 在给定的锚点之前输出内容
     :param str after: 在给定的锚点之后输出内容
     :param str after: 在给定的锚点之后输出内容
@@ -335,10 +336,10 @@ def put_buttons(buttons, onclick, small=False, anchor=None, before=None, after=N
     :param callback_options: 回调函数的其他参数。根据选用的 session 实现有不同参数
     :param callback_options: 回调函数的其他参数。根据选用的 session 实现有不同参数
 
 
        CoroutineBasedSession 实现
        CoroutineBasedSession 实现
-           * mutex_mode: 互斥模式。若为 ``True`` ,则在运行回调函数过程中,无法响应当前按钮组的新点击事件,仅当 ``onclick`` 为协程函数时有效
+           * mutex_mode: 互斥模式。默认为 ``False`` 。若为 ``True`` ,则在运行回调函数过程中,无法响应当前按钮组的新点击事件,仅当 ``onclick`` 为协程函数时有效
 
 
        ThreadBasedSession 实现
        ThreadBasedSession 实现
-           * serial_mode: 串行模式模式。若为 ``True`` ,则对于同一组件的点击事件,串行执行其回调函数
+           * serial_mode: 串行模式模式。默认为 ``False`` 。若为 ``True`` ,则运行当前点击事件时,其他所有新的点击事件都将被排队等待当前点击事件时运行完成
              不开启 ``serial_mode`` 时,ThreadBasedSession 在新线程中执行回调函数。所以如果回调函数运行时间很短,
              不开启 ``serial_mode`` 时,ThreadBasedSession 在新线程中执行回调函数。所以如果回调函数运行时间很短,
              可以关闭 ``serial_mode`` 来提高性能。
              可以关闭 ``serial_mode`` 来提高性能。
     """
     """