76
76
import logging
77
77
import os .path
78
78
from collections .abc import Mapping
79
+ from typing import Any , Callable , Dict , List , Optional , Tuple , Union
79
80
80
- from .io_ctrl import single_input , input_control , output_register_callback , send_msg , single_input_kwargs
81
+ from .io_ctrl import input_control , output_register_callback , send_msg , single_input , single_input_kwargs
81
82
from .platform import page as platform_setting
82
83
from .session import get_current_session , get_current_task_id
83
- from .utils import Setter , parse_file_size , check_dom_name_value
84
+ from .utils import Setter , check_dom_name_value , parse_file_size
84
85
85
86
logger = logging .getLogger (__name__ )
86
87
99
100
SELECT = 'select'
100
101
TEXTAREA = 'textarea'
101
102
102
- __all__ = ['TEXT' , 'NUMBER' , 'FLOAT' , 'PASSWORD' , 'URL' , 'DATE' , 'TIME' , 'COLOR' , 'DATETIME_LOCAL' , 'input' , 'textarea' ,
103
- 'select' ,
104
- 'checkbox' , 'radio' , 'actions' , 'file_upload' , 'slider' , 'input_group' , 'input_update' ]
103
+ __all__ = ['TEXT' , 'NUMBER' , 'FLOAT' , 'PASSWORD' , 'URL' , 'DATE' ,
104
+ 'TIME' , 'COLOR' , 'DATETIME_LOCAL' , 'input' , 'textarea' ,
105
+ 'select' , 'checkbox' , 'radio' , 'actions' , 'file_upload' ,
106
+ 'slider' , 'input_group' , 'input_update' ]
105
107
106
108
107
109
def _parse_args (kwargs , excludes = ()):
@@ -131,8 +133,9 @@ def _parse_args(kwargs, excludes=()):
131
133
return kwargs , valid_func , onchange_func
132
134
133
135
134
- def input (label = '' , type = TEXT , * , validate = None , name = None , value = None , action = None , onchange = None , placeholder = None ,
135
- required = None , readonly = None , datalist = None , help_text = None , ** other_html_attrs ):
136
+ def input (label : str = '' , type : str = TEXT , * , validate : Callable [[Any ], Optional [str ]] = None , name : str = None , value : str = None ,
137
+ action : Tuple [str , Callable [[Callable ], None ]] = None , onchange : Callable [[Any ], None ] = None , placeholder : str = None , required : bool = None ,
138
+ readonly : bool = None , datalist : List [str ] = None , help_text : str = None , ** other_html_attrs ):
136
139
r"""Text input
137
140
138
141
:param str label: Label of input field.
@@ -260,8 +263,9 @@ def preprocess_func(d): # Convert the original data submitted by the user
260
263
return single_input (item_spec , valid_func , preprocess_func , onchange_func )
261
264
262
265
263
- def textarea (label = '' , * , rows = 6 , code = None , maxlength = None , minlength = None , validate = None , name = None , value = None ,
264
- onchange = None , placeholder = None , required = None , readonly = None , help_text = None , ** other_html_attrs ):
266
+ def textarea (label : str = '' , * , rows : int = 6 , code : Union [bool , Dict ] = None , maxlength : int = None , minlength : int = None ,
267
+ validate : Callable [[Any ], Optional [str ]] = None , name : str = None , value : str = None , onchange : Callable [[Any ], None ] = None ,
268
+ placeholder : str = None , required : bool = None , readonly : bool = None , help_text : str = None , ** other_html_attrs ):
265
269
r"""Text input area (multi-line text input)
266
270
267
271
:param int rows: The number of visible text lines for the input area. Scroll bar will be used when content exceeds.
@@ -326,8 +330,9 @@ def _set_options_selected(options, value):
326
330
return options
327
331
328
332
329
- def select (label = '' , options = None , * , multiple = None , validate = None , name = None , value = None , onchange = None , required = None ,
330
- help_text = None , ** other_html_attrs ):
333
+ def select (label : str = '' , options : List [Union [Dict [str , Any ], Tuple , List , str ]] = None , * , multiple : bool = None , validate : Callable [[Any ], Optional [str ]] = None ,
334
+ name : str = None , value : Union [List , str ] = None , onchange : Callable [[Any ], None ] = None , required : bool = None ,
335
+ help_text : str = None , ** other_html_attrs ):
331
336
r"""Drop-down selection
332
337
333
338
By default, only one option can be selected at a time, you can set ``multiple`` parameter to enable multiple selection.
@@ -371,8 +376,9 @@ def select(label='', options=None, *, multiple=None, validate=None, name=None, v
371
376
return single_input (item_spec , valid_func = valid_func , preprocess_func = lambda d : d , onchange_func = onchange_func )
372
377
373
378
374
- def checkbox (label = '' , options = None , * , inline = None , validate = None , name = None , value = None , onchange = None ,
375
- help_text = None , ** other_html_attrs ):
379
+ def checkbox (label : str = '' , options : List [Union [Dict [str , Any ], Tuple , List , str ]] = None , * , inline : bool = None , validate : Callable [[Any ], Optional [str ]] = None ,
380
+ name : str = None , value : List = None , onchange : Callable [[Any ], None ] = None , help_text : str = None ,
381
+ ** other_html_attrs ):
376
382
r"""A group of check box that allowing single values to be selected/deselected.
377
383
378
384
:param list options: List of options. The format is the same as the ``options`` parameter of the `select()` function
@@ -393,8 +399,9 @@ def checkbox(label='', options=None, *, inline=None, validate=None, name=None, v
393
399
return single_input (item_spec , valid_func , lambda d : d , onchange_func )
394
400
395
401
396
- def radio (label = '' , options = None , * , inline = None , validate = None , name = None , value = None , onchange = None , required = None ,
397
- help_text = None , ** other_html_attrs ):
402
+ def radio (label : str = '' , options : List [Union [Dict [str , Any ], Tuple , List , str ]] = None , * , inline : bool = None , validate : Callable [[Any ], Optional [str ]] = None ,
403
+ name : str = None , value : str = None , onchange : Callable [[Any ], None ] = None , required : bool = None ,
404
+ help_text : str = None , ** other_html_attrs ):
398
405
r"""A group of radio button. Only a single button can be selected.
399
406
400
407
:param list options: List of options. The format is the same as the ``options`` parameter of the `select()` function
@@ -457,7 +464,7 @@ def _parse_action_buttons(buttons):
457
464
return act_res
458
465
459
466
460
- def actions (label = '' , buttons = None , name = None , help_text = None ):
467
+ def actions (label : str = '' , buttons : List [ Union [ Dict [ str , Any ], Tuple , List , str ]] = None , name : str = None , help_text : str = None ):
461
468
r"""Actions selection
462
469
463
470
It is displayed as a group of buttons on the page. After the user clicks the button of it,
@@ -557,8 +564,9 @@ def actions(label='', buttons=None, name=None, help_text=None):
557
564
return single_input (item_spec , valid_func , lambda d : d , onchange_func )
558
565
559
566
560
- def file_upload (label = '' , accept = None , name = None , placeholder = 'Choose file' , multiple = False , max_size = 0 ,
561
- max_total_size = 0 , required = None , help_text = None , ** other_html_attrs ):
567
+ def file_upload (label : str = '' , accept : Union [List , str ] = None , name : str = None , placeholder : str = 'Choose file' ,
568
+ multiple : bool = False , max_size : Union [int , str ] = 0 , max_total_size : Union [int , str ] = 0 ,
569
+ required : bool = None , help_text : str = None , ** other_html_attrs ):
562
570
r"""File uploading
563
571
564
572
:param accept: Single value or list, indicating acceptable file types. The available formats of file types are:
@@ -590,14 +598,14 @@ def file_upload(label='', accept=None, name=None, placeholder='Choose file', mul
590
598
'mime_type': MIME type of the file,
591
599
'last_modified': Last modified time (timestamp) of the file
592
600
}
593
-
601
+
594
602
If there is no file uploaded, return ``None``.
595
603
596
604
When ``multiple=True``, a list is returned. The format of the list item is the same as the return value when ``multiple=False`` above.
597
605
If the user does not upload a file, an empty list is returned.
598
606
599
607
.. note::
600
-
608
+
601
609
If uploading large files, please pay attention to the file upload size limit setting of the web framework.
602
610
When using :func:`start_server() <pywebio.platform.tornado.start_server>` or
603
611
:func:`path_deploy() <pywebio.platform.path_deploy>` to start the PyWebIO application,
@@ -639,8 +647,9 @@ def read_file(data):
639
647
return single_input (item_spec , valid_func , read_file , onchange_func )
640
648
641
649
642
- def slider (label = '' , * , name = None , value = 0 , min_value = 0 , max_value = 100 , step = 1 , validate = None , onchange = None ,
643
- required = None , help_text = None , ** other_html_attrs ):
650
+ def slider (label : str = '' , * , name : str = None , value : Union [int , float ] = 0 , min_value : Union [int , float ] = 0 ,
651
+ max_value : Union [int , float ] = 100 , step : int = 1 , validate : Callable [[Any ], Optional [str ]] = None ,
652
+ onchange : Callable [[Any ], None ] = None , required : bool = None , help_text : str = None , ** other_html_attrs ):
644
653
r"""Range input.
645
654
646
655
:param int/float value: The initial value of the slider.
@@ -661,7 +670,7 @@ def slider(label='', *, name=None, value=0, min_value=0, max_value=100, step=1,
661
670
return single_input (item_spec , valid_func , lambda d : d , onchange_func )
662
671
663
672
664
- def input_group (label = '' , inputs = None , validate = None , cancelable = False ):
673
+ def input_group (label : str = '' , inputs : List = None , validate : Callable [[ Dict ], Optional [ Tuple [ str , str ]]] = None , cancelable : bool = False ):
665
674
r"""Input group. Request a set of inputs from the user at once.
666
675
667
676
:param str label: Label of input group.
@@ -747,7 +756,7 @@ def parse_input_update_spec(spec):
747
756
return attributes
748
757
749
758
750
- def input_update (name = None , ** spec ):
759
+ def input_update (name : str = None , ** spec ):
751
760
"""Update attributes of input field.
752
761
This function can only be called in ``onchange`` callback of input functions.
753
762
0 commit comments