浏览代码

add code comment

wangweimin 5 年之前
父节点
当前提交
d889d9208a
共有 3 个文件被更改,包括 12 次插入5 次删除
  1. 2 2
      pywebio/io_ctrl.py
  2. 9 3
      pywebio/output.py
  3. 1 0
      pywebio/session/asyncbased.py

+ 2 - 2
pywebio/io_ctrl.py

@@ -144,6 +144,6 @@ def input_event_handle(item_valid_funcs, form_valid_funcs, preprocess_funcs):
     return data
     return data
 
 
 
 
-def output_register_callback(callback, mutex_mode):
-    coro_id = get_current_session().register_callback(callback, mutex_mode)
+def output_register_callback(callback, **options):
+    coro_id = get_current_session().register_callback(callback, **options)
     return coro_id
     return coro_id

+ 9 - 3
pywebio/output.py

@@ -279,7 +279,7 @@ def table_cell_buttons(buttons, onclick, mutex_mode=False):
     return ' '.join(btns_html)
     return ' '.join(btns_html)
 
 
 
 
-def put_buttons(buttons, onclick, small=False, mutex_mode=False, anchor=None, before=None, after=None):
+def put_buttons(buttons, onclick, small=False, anchor=None, before=None, after=None, **callback_options):
     """
     """
     输出一组按钮
     输出一组按钮
 
 
@@ -294,12 +294,18 @@ def put_buttons(buttons, onclick, small=False, mutex_mode=False, anchor=None, be
         函数签名为 ``onclick(btn_value)``.
         函数签名为 ``onclick(btn_value)``.
         当按钮组中的按钮被点击时,``onclick`` 被调用,并传入被点击的按钮的 ``value`` 值。
         当按钮组中的按钮被点击时,``onclick`` 被调用,并传入被点击的按钮的 ``value`` 值。
         可以使用 ``functools.partial`` 来在 ``onclick`` 中保存更多上下文信息,见 `td_buttons` :ref:`代码示例 <td_buttons-code-sample>` 。
         可以使用 ``functools.partial`` 来在 ``onclick`` 中保存更多上下文信息,见 `td_buttons` :ref:`代码示例 <td_buttons-code-sample>` 。
-    :param bool mutex_mode: 互斥模式。若为 ``True`` ,则在运行回调函数过程中,无法响应当前按钮组的新点击事件,仅当 `onclick`` 为协程函数时有效
     :param str anchor, before, after: 与 `put_text` 函数的同名参数含义一致
     :param str anchor, before, after: 与 `put_text` 函数的同名参数含义一致
+    :param callback_options: 回调函数的其他参数。根据选用的 session 实现有不同参数
+
+        AsyncBasedSession 实现
+            * mutex_mode: 互斥模式。若为 ``True`` ,则在运行回调函数过程中,无法响应当前按钮组的新点击事件,仅当 ``onclick`` 为协程函数时有效
+
+        ThreadBasedWebIOSession 实现
+            * serial_mode: 串行模式模式。若为 ``True`` ,则对于同一组件的点击事件,串行执行其回调函数
     """
     """
     assert not (before and after), "Parameter 'before' and 'after' cannot be specified at the same time"
     assert not (before and after), "Parameter 'before' and 'after' cannot be specified at the same time"
     btns = _format_button(buttons)
     btns = _format_button(buttons)
-    callback_id = output_register_callback(onclick, mutex_mode)
+    callback_id = output_register_callback(onclick, **callback_options)
     _put_content('buttons', callback_id=callback_id, buttons=btns, small=small, anchor=anchor, before=before,
     _put_content('buttons', callback_id=callback_id, buttons=btns, small=small, anchor=anchor, before=before,
                  after=after)
                  after=after)
 
 

+ 1 - 0
pywebio/session/asyncbased.py

@@ -159,6 +159,7 @@ class AsyncBasedSession(AbstractSession):
 
 
         :type callback: Callable or Coroutine
         :type callback: Callable or Coroutine
         :param callback: 回调函数. 可以是普通函数或者协程函数. 函数签名为 ``callback(data)``.
         :param callback: 回调函数. 可以是普通函数或者协程函数. 函数签名为 ``callback(data)``.
+        :param bool mutex_mode: 互斥模式。若为 ``True`` ,则在运行回调函数过程中,无法响应同一组件的新点击事件,仅当 ``callback`` 为协程函数时有效
         :return str: 回调id.
         :return str: 回调id.
             AsyncBasedSession保证当收到前端发送的事件消息 ``{event: "callback",coro_id: 回调id, data:...}`` 时,
             AsyncBasedSession保证当收到前端发送的事件消息 ``{event: "callback",coro_id: 回调id, data:...}`` 时,
             ``callback`` 回调函数被执行, 并传入事件消息中的 ``data`` 字段值作为参数
             ``callback`` 回调函数被执行, 并传入事件消息中的 ``data`` 字段值作为参数