MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / put_grid

Function put_grid

pywebio/output.py:1372–1455  ·  view source on GitHub ↗

Output content using grid layout :param content: Content of grid, which is a two-dimensional list. The item of list is ``put_xxx()`` call or ``None``. ``None`` represents the space between the output. The item can use the `span()` to set the cell span. :param str cell_width: The widt

(content: List[List[Union[Output, None]]], cell_width: str = 'auto', cell_height: str = 'auto',
             cell_widths: str = None, cell_heights: str = None, direction: str = 'row', scope: str = None,
             position: int = OutputPosition.BOTTOM)

Source from the content-addressed store, hash-verified

1370
1371@safely_destruct_output_when_exp('content')
1372def put_grid(content: List[List[Union[Output, None]]], cell_width: str = 'auto', cell_height: str = 'auto',
1373 cell_widths: str = None, cell_heights: str = None, direction: str = 'row', scope: str = None,
1374 position: int = OutputPosition.BOTTOM) -> Output:
1375 """Output content using grid layout
1376
1377 :param content: Content of grid, which is a two-dimensional list. The item of list is ``put_xxx()`` call or ``None``.
1378 ``None`` represents the space between the output. The item can use the `span()` to set the cell span.
1379 :param str cell_width: The width of grid cell.
1380 :param str cell_height: The height of grid cell.
1381 :param str cell_widths: The width of each column of the grid. The width values are separated by a space.
1382 Can not use ``cell_widths`` and ``cell_width`` at the same time
1383 :param str cell_heights: The height of each row of the grid. The height values are separated by a space.
1384 Can not use ``cell_heights`` and ``cell_height`` at the same time
1385 :param str direction: Controls how auto-placed items get inserted in the grid.
1386 Can be ``'row'``(default) or ``'column'`` .
1387
1388 | ``'row'`` : Places items by filling each row
1389 | ``'column'`` : Places items by filling each column
1390
1391 :param int scope, position: Those arguments have the same meaning as for `put_text()`
1392
1393 The format of width/height value in ``cell_width``,``cell_height``,``cell_widths``,``cell_heights``
1394 can refer to the ``size`` parameter of the `put_row()` function.
1395
1396 Example:
1397
1398 .. exportable-codeblock::
1399 :name: put_grid
1400 :summary: `put_grid()` usage
1401
1402 put_grid([
1403 [put_text('A'), put_text('B'), put_text('C')],
1404 [None, span(put_text('D'), col=2, row=1)],
1405 [put_text('E'), put_text('F'), put_text('G')],
1406 ], cell_width='100px', cell_height='100px')
1407 """
1408 assert direction in ('row', 'column'), '"direction" parameter must be "row" or "column"'
1409
1410 lens = [0] * len(content)
1411 for x in range(len(content)):
1412 for y in range(len(content[x])):
1413 cell = content[x][y]
1414 if isinstance(cell, span_):
1415 for i in range(cell.row):
1416 lens[x + i] += cell.col
1417
1418 css = 'grid-row-start: span {row}; grid-column-start: span {col};'.format(row=cell.row, col=cell.col)
1419 elem = put_html('<div></div>') if cell.content is None else cell.content
1420 content[x][y] = elem.style(css)
1421 else:
1422 lens[x] += 1
1423
1424 if content[x][y] is None:
1425 content[x][y] = put_html('<div></div>')
1426
1427 # 为长度不足的行添加空元素
1428 # Add empty elements for rows with insufficient length
1429 m = max(lens)

Callers 6

pyechartsFunction · 0.85
cutechartsFunction · 0.85
plotlyFunction · 0.85
basic_outputFunction · 0.85
output_widgetsFunction · 0.85
mainFunction · 0.85

Calls 3

put_htmlFunction · 0.85
put_widgetFunction · 0.85
styleMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…