1
0
Эх сурвалжийг харах

adjust put_buttons、table_cell_buttons、actions、select parameter format to keep code consistency

when use list[list] as those function `options`/`buttons` parameter, it's better to make first item as label and second as value
wangweimin 5 жил өмнө
parent
commit
b4ba0795a7

+ 8 - 8
pywebio/input.py

@@ -132,7 +132,7 @@ def _parse_select_options(options):
             assert 'value' in opt and 'label' in opt, 'options item must have value and label key'
             assert 'value' in opt and 'label' in opt, 'options item must have value and label key'
         elif isinstance(opt, list):
         elif isinstance(opt, list):
             assert len(opt) > 1 and len(opt) <= 4, 'options item format error'
             assert len(opt) > 1 and len(opt) <= 4, 'options item format error'
-            opt = dict(zip(('value', 'label', 'selected', 'disabled'), opt))
+            opt = dict(zip(('label', 'value', 'selected', 'disabled'), opt))
         else:
         else:
             opt = dict(value=opt, label=opt)
             opt = dict(value=opt, label=opt)
         opts_res.append(opt)
         opts_res.append(opt)
@@ -147,8 +147,8 @@ def select(label, options, *, multiple=None, valid_func=None, name=None, value=N
 
 
     :param list options: 可选项列表。列表项的可用形式有:
     :param list options: 可选项列表。列表项的可用形式有:
 
 
-        * dict: ``{value: 选项值, label:选项标签, [selected:是否默认选中,] [disabled:是否禁止选中]}``
-        * tuple or list: ``(value, label, [selected,] [disabled])``
+        * dict: ``{label:选项标签, value: 选项值, [selected:是否默认选中,] [disabled:是否禁止选中]}``
+        * tuple or list: ``(label, value, [selected,] [disabled])``
         * 单值: 此时label和value使用相同的值
         * 单值: 此时label和value使用相同的值
 
 
         注意:若 ``multiple`` 选项不为 ``True`` 则可选项列表最多仅能有一项的 ``selected`` 为 ``True``
         注意:若 ``multiple`` 选项不为 ``True`` 则可选项列表最多仅能有一项的 ``selected`` 为 ``True``
@@ -201,8 +201,8 @@ def _parse_action_buttons(buttons):
     :param label:
     :param label:
     :param actions: action 列表
     :param actions: action 列表
     action 可用形式:
     action 可用形式:
-        {value:, label:, [disabled:]}
-        (value, label, [disabled])
+        {label:, value:, [disabled:]}
+        (label, value, [disabled])
         value 单值,label等于value
         value 单值,label等于value
     :return:
     :return:
     """
     """
@@ -212,7 +212,7 @@ def _parse_action_buttons(buttons):
             assert 'value' in act and 'label' in act, 'actions item must have value and label key'
             assert 'value' in act and 'label' in act, 'actions item must have value and label key'
         elif isinstance(act, list):
         elif isinstance(act, list):
             assert len(act) in (2, 3), 'actions item format error'
             assert len(act) in (2, 3), 'actions item format error'
-            act = dict(zip(('value', 'label', 'disabled'), act))
+            act = dict(zip(('label', 'value', 'disabled'), act))
         else:
         else:
             act = dict(value=act, label=act)
             act = dict(value=act, label=act)
         act_res.append(act)
         act_res.append(act)
@@ -226,8 +226,8 @@ def actions(label, buttons, name=None, help_text=None):
 
 
     :param list buttons: 选项列表。列表项的可用形式有:
     :param list buttons: 选项列表。列表项的可用形式有:
 
 
-        * dict: ``{value:选项值, label:选项标签, [disabled:是否禁止选择]}``
-        * tuple or list: ``(value, label, [disabled])``
+        * dict: ``{label:选项标签, value:选项值, [disabled:是否禁止选择]}``
+        * tuple or list: ``(label, value, [disabled])``
         * 单值: 此时label和value使用相同的值
         * 单值: 此时label和value使用相同的值
 
 
     :param - label, name, help_text: 与 `input` 输入函数的同名参数含义一致
     :param - label, name, help_text: 与 `input` 输入函数的同名参数含义一致

+ 5 - 5
pywebio/output.py

@@ -230,8 +230,8 @@ def _format_button(buttons):
     """
     """
     格式化按钮参数
     格式化按钮参数
     :param buttons: button列表, button可用形式:
     :param buttons: button列表, button可用形式:
-        {value:, label:, }
-        (value, label,)
+        {label:, value:, }
+        (label, value, )
         value 单值,label等于value
         value 单值,label等于value
 
 
     :return: [{value:, label:, }, ...]
     :return: [{value:, label:, }, ...]
@@ -243,7 +243,7 @@ def _format_button(buttons):
             assert 'value' in btn and 'label' in btn, 'actions item must have value and label key'
             assert 'value' in btn and 'label' in btn, 'actions item must have value and label key'
         elif isinstance(btn, list):
         elif isinstance(btn, list):
             assert len(btn) == 2, 'actions item format error'
             assert len(btn) == 2, 'actions item format error'
-            btn = dict(zip(('value', 'label'), btn))
+            btn = dict(zip(('label', 'value'), btn))
         else:
         else:
             btn = dict(value=btn, label=btn)
             btn = dict(value=btn, label=btn)
         btns.append(btn)
         btns.append(btn)
@@ -285,8 +285,8 @@ def put_buttons(buttons, onclick, small=False, anchor=None, before=None, after=N
 
 
     :param list buttons: 按钮列表。列表项的可用形式有:
     :param list buttons: 按钮列表。列表项的可用形式有:
 
 
-        * dict: ``{value:选项值, label:选项标签, [disabled:是否禁止点击]}``
-        * tuple or list: ``(value, label, [disabled])``
+        * dict: ``{label:选项标签, value:选项值}``
+        * tuple or list: ``(label, value)``
         * 单值: 此时label和value使用相同的值
         * 单值: 此时label和value使用相同的值
 
 
     :type onclick: Callable or Coroutine
     :type onclick: Callable or Coroutine