@@ -361,7 +361,8 @@ def _get_output_spec(type, scope, position, **other_spec):
361
361
return spec
362
362
363
363
364
- def put_text (* texts : Any , sep : str = ' ' , inline : bool = False , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
364
+ def put_text (* texts : Any , sep : str = ' ' , inline : bool = False , scope : str = None ,
365
+ position : int = OutputPosition .BOTTOM ) -> Output :
365
366
"""
366
367
Output plain text
367
368
@@ -397,7 +398,8 @@ def _put_message(color, contents, closable=False, scope=None, position=OutputPos
397
398
scope = scope , position = position ).enable_context_manager ()
398
399
399
400
400
- def put_info (* contents : Any , closable : bool = False , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
401
+ def put_info (* contents : Any , closable : bool = False , scope : str = None ,
402
+ position : int = OutputPosition .BOTTOM ) -> Output :
401
403
"""Output information message.
402
404
403
405
:param contents: Message contents.
@@ -410,22 +412,25 @@ def put_info(*contents: Any, closable: bool = False, scope: str = None, position
410
412
return _put_message (color = 'info' , contents = contents , closable = closable , scope = scope , position = position )
411
413
412
414
413
- def put_success (* contents : Any , closable : bool = False , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
415
+ def put_success (* contents : Any , closable : bool = False , scope : str = None ,
416
+ position : int = OutputPosition .BOTTOM ) -> Output :
414
417
"""Output success message.
415
418
.. seealso:: `put_info()`
416
419
.. versionadded:: 1.2
417
420
"""
418
421
return _put_message (color = 'success' , contents = contents , closable = closable , scope = scope , position = position )
419
422
420
423
421
- def put_warning (* contents : Any , closable : bool = False , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
424
+ def put_warning (* contents : Any , closable : bool = False , scope : str = None ,
425
+ position : int = OutputPosition .BOTTOM ) -> Output :
422
426
"""Output warning message.
423
427
.. seealso:: `put_info()`
424
428
"""
425
429
return _put_message (color = 'warning' , contents = contents , closable = closable , scope = scope , position = position )
426
430
427
431
428
- def put_error (* contents : Any , closable : bool = False , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
432
+ def put_error (* contents : Any , closable : bool = False , scope : str = None ,
433
+ position : int = OutputPosition .BOTTOM ) -> Output :
429
434
"""Output error message.
430
435
.. seealso:: `put_info()`
431
436
"""
@@ -455,7 +460,8 @@ def put_html(html: Any, sanitize: bool = False, scope: str = None, position: int
455
460
return Output (spec )
456
461
457
462
458
- def put_code (content : str , language : str = '' , rows : int = None , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
463
+ def put_code (content : str , language : str = '' , rows : int = None , scope : str = None ,
464
+ position : int = OutputPosition .BOTTOM ) -> Output :
459
465
"""
460
466
Output code block
461
467
@@ -507,7 +513,8 @@ def _left_strip_multiple_line_string_literal(s):
507
513
return '\n ' .join (lines [:1 ] + lines_ )
508
514
509
515
510
- def put_markdown (mdcontent : str , lstrip : bool = True , options : Dict [str , Union [str , bool ]] = None , sanitize : bool = True ,
516
+ def put_markdown (mdcontent : str , lstrip : bool = True , options : Dict [str , Union [str , bool ]] = None ,
517
+ sanitize : bool = True ,
511
518
scope : str = None , position : int = OutputPosition .BOTTOM , ** kwargs ) -> Output :
512
519
"""
513
520
Output Markdown
@@ -583,7 +590,8 @@ def span(content: Union[str, Output], row: int = 1, col: int = 1):
583
590
584
591
585
592
@safely_destruct_output_when_exp ('tdata' )
586
- def put_table (tdata : List [Union [List , Dict ]], header : List [Union [str , Tuple [Any , str ]]] = None , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
593
+ def put_table (tdata : List [Union [List , Dict ]], header : List [Union [str , Tuple [Any , str ]]] = None , scope : str = None ,
594
+ position : int = OutputPosition .BOTTOM ) -> Output :
587
595
"""
588
596
Output table
589
597
@@ -594,7 +602,7 @@ def put_table(tdata: List[Union[List, Dict]], header: List[Union[str, Tuple[Any,
594
602
the first item of ``tdata`` will be used as the header.
595
603
The header item can also use the :func:`span()` function to set the cell span.
596
604
597
- When ``tdata`` is list of dict, ``header`` is used to specify the order of table headers, which cannot be omitted .
605
+ When ``tdata`` is list of dict, ``header`` can be used to specify the order of table headers.
598
606
In this case, the ``header`` can be a list of dict key or a list of ``(<label>, <dict key>)``.
599
607
600
608
:param int scope, position: Those arguments have the same meaning as for `put_text()`
@@ -644,9 +652,11 @@ def put_table(tdata: List[Union[List, Dict]], header: List[Union[str, Tuple[Any,
644
652
The cell of table support ``put_xxx()`` calls.
645
653
"""
646
654
647
- # Change ``dict`` row table to list row table
648
- if tdata and isinstance (tdata [0 ], dict ):
649
- if isinstance (header [0 ], (list , tuple )):
655
+ if tdata and isinstance (tdata [0 ], dict ): # Change ``dict`` row table to list row table
656
+ if header is None :
657
+ order = list (tdata [0 ].keys ())
658
+ header_ = [str (h ).capitalize () for h in tdata [0 ].keys ()]
659
+ elif isinstance (header [0 ], (list , tuple )):
650
660
header_ = [h [0 ] for h in header ]
651
661
order = [h [- 1 ] for h in header ]
652
662
else :
@@ -657,14 +667,12 @@ def put_table(tdata: List[Union[List, Dict]], header: List[Union[str, Tuple[Any,
657
667
for row in tdata
658
668
]
659
669
header = header_
670
+ elif not tdata and isinstance (header [0 ], (list , tuple )):
671
+ header = [h [0 ] for h in header ]
660
672
else :
661
673
tdata = [list (i ) for i in tdata ] # copy data
662
674
663
675
if header :
664
- # when tdata is empty, header will not be process
665
- # see https://github.com/pywebio/PyWebIO/issues/453
666
- if isinstance (header [0 ], (list , tuple )):
667
- header = [h [0 ] for h in header ]
668
676
tdata = [header , * tdata ]
669
677
670
678
span = {}
@@ -709,8 +717,10 @@ def _format_button(buttons):
709
717
return btns , values
710
718
711
719
712
- def put_buttons (buttons : List [Union [Dict [str , Any ], Tuple [str , Any ], List , str ]], onclick : Union [Callable [[Any ], None ], SequenceType [Callable [[], None ]]],
713
- small : bool = None , link_style : bool = False , outline : bool = False , group : bool = False , scope : str = None ,
720
+ def put_buttons (buttons : List [Union [Dict [str , Any ], Tuple [str , Any ], List , str ]],
721
+ onclick : Union [Callable [[Any ], None ], SequenceType [Callable [[], None ]]],
722
+ small : bool = None , link_style : bool = False , outline : bool = False , group : bool = False ,
723
+ scope : str = None ,
714
724
position : int = OutputPosition .BOTTOM , ** callback_options ) -> Output :
715
725
"""
716
726
Output a group of buttons and bind click event
@@ -821,7 +831,8 @@ def click_callback(btn_idx):
821
831
822
832
823
833
def put_button (label : str , onclick : Callable [[], None ], color : str = None , small : bool = None , link_style : bool = False ,
824
- outline : bool = False , disabled : bool = False , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
834
+ outline : bool = False , disabled : bool = False , scope : str = None ,
835
+ position : int = OutputPosition .BOTTOM ) -> Output :
825
836
"""Output a single button and bind click event to it.
826
837
827
838
:param str label: Button label
@@ -849,7 +860,8 @@ def put_button(label: str, onclick: Callable[[], None], color: str = None, small
849
860
position = position )
850
861
851
862
852
- def put_image (src : Union [str , bytes , PILImage ], format : str = None , title : str = '' , width : str = None , height : str = None ,
863
+ def put_image (src : Union [str , bytes , PILImage ], format : str = None , title : str = '' , width : str = None ,
864
+ height : str = None ,
853
865
scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
854
866
"""Output image
855
867
@@ -896,7 +908,8 @@ def put_image(src: Union[str, bytes, PILImage], format: str = None, title: str =
896
908
return put_html (tag , scope = scope , position = position )
897
909
898
910
899
- def put_file (name : str , content : bytes , label : str = None , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
911
+ def put_file (name : str , content : bytes , label : str = None , scope : str = None ,
912
+ position : int = OutputPosition .BOTTOM ) -> Output :
900
913
"""Output a link to download a file
901
914
902
915
To show a link with the file name on the browser. When click the link, the browser automatically downloads the file.
@@ -1013,7 +1026,8 @@ def set_processbar(name: str, value: float, label: str = None):
1013
1026
run_js (js_code )
1014
1027
1015
1028
1016
- def put_loading (shape : str = 'border' , color : str = 'dark' , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
1029
+ def put_loading (shape : str = 'border' , color : str = 'dark' , scope : str = None ,
1030
+ position : int = OutputPosition .BOTTOM ) -> Output :
1017
1031
"""Output loading prompt
1018
1032
1019
1033
:param str shape: The shape of loading prompt. The available values are: `'border'` (default)、 `'grow'`
@@ -1067,7 +1081,8 @@ def after_exit():
1067
1081
1068
1082
1069
1083
@safely_destruct_output_when_exp ('content' )
1070
- def put_collapse (title : str , content : Union [str , Output , List [Union [str , Output ]]] = [], open : bool = False , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
1084
+ def put_collapse (title : str , content : Union [str , Output , List [Union [str , Output ]]] = [], open : bool = False ,
1085
+ scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
1071
1086
"""Output collapsible content
1072
1087
1073
1088
:param str title: Title of content
@@ -1111,7 +1126,8 @@ def put_collapse(title: str, content: Union[str, Output, List[Union[str, Output]
1111
1126
1112
1127
1113
1128
@safely_destruct_output_when_exp ('content' )
1114
- def put_scrollable (content : Union [str , Output , List [Union [str , Output ]]] = [], height : Union [int , Tuple [int , int ]] = 400 , keep_bottom : bool = False , border : bool = True ,
1129
+ def put_scrollable (content : Union [str , Output , List [Union [str , Output ]]] = [],
1130
+ height : Union [int , Tuple [int , int ]] = 400 , keep_bottom : bool = False , border : bool = True ,
1115
1131
scope : str = None , position : int = OutputPosition .BOTTOM , ** kwargs ) -> Output :
1116
1132
"""Output a fixed height content area. scroll bar is displayed when the content exceeds the limit
1117
1133
@@ -1253,7 +1269,8 @@ def put_widget(template: str, data: Dict[str, Any], scope: str = None, position:
1253
1269
1254
1270
1255
1271
@safely_destruct_output_when_exp ('content' )
1256
- def put_row (content : List [Union [Output , None ]] = [], size : str = None , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
1272
+ def put_row (content : List [Union [Output , None ]] = [], size : str = None , scope : str = None ,
1273
+ position : int = OutputPosition .BOTTOM ) -> Output :
1257
1274
"""Use row layout to output content. The content is arranged horizontally
1258
1275
1259
1276
:param list content: Content list, the item is ``put_xxx()`` call or ``None``. ``None`` represents the space between the output
@@ -1293,7 +1310,8 @@ def put_row(content: List[Union[Output, None]] = [], size: str = None, scope: st
1293
1310
1294
1311
1295
1312
@safely_destruct_output_when_exp ('content' )
1296
- def put_column (content : List [Union [Output , None ]] = [], size : str = None , scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
1313
+ def put_column (content : List [Union [Output , None ]] = [], size : str = None , scope : str = None ,
1314
+ position : int = OutputPosition .BOTTOM ) -> Output :
1297
1315
"""Use column layout to output content. The content is arranged vertically
1298
1316
1299
1317
:param list content: Content list, the item is ``put_xxx()`` call or ``None``. ``None`` represents the space between the output
@@ -1415,7 +1433,8 @@ def put_grid(content: List[List[Union[Output, None]]], cell_width: str = 'auto',
1415
1433
1416
1434
1417
1435
@safely_destruct_output_when_exp ('content' )
1418
- def put_scope (name : str , content : Union [Output , List [Output ]] = [], scope : str = None , position : int = OutputPosition .BOTTOM ) -> Output :
1436
+ def put_scope (name : str , content : Union [Output , List [Output ]] = [], scope : str = None ,
1437
+ position : int = OutputPosition .BOTTOM ) -> Output :
1419
1438
"""Output a scope
1420
1439
1421
1440
:param str name:
@@ -1599,7 +1618,8 @@ def style(outputs: Union[Output, List[Output]], css_style: str) -> Union[Output,
1599
1618
1600
1619
1601
1620
@safely_destruct_output_when_exp ('content' )
1602
- def popup (title : str , content : Union [str , Output , List [Union [str , Output ]]] = None , size : str = PopupSize .NORMAL , implicit_close : bool = True ,
1621
+ def popup (title : str , content : Union [str , Output , List [Union [str , Output ]]] = None , size : str = PopupSize .NORMAL ,
1622
+ implicit_close : bool = True ,
1603
1623
closable : bool = True ):
1604
1624
"""
1605
1625
Show a popup.
@@ -1696,7 +1716,8 @@ def close_popup():
1696
1716
send_msg (cmd = 'close_popup' )
1697
1717
1698
1718
1699
- def toast (content : str , duration : float = 2 , position : str = 'center' , color : str = 'info' , onclick : Callable [[], None ] = None ):
1719
+ def toast (content : str , duration : float = 2 , position : str = 'center' , color : str = 'info' ,
1720
+ onclick : Callable [[], None ] = None ):
1700
1721
"""Show a notification message.
1701
1722
1702
1723
:param str content: Notification content.
0 commit comments