edifice.GridView#

class edifice.GridView(layout='', key_to_code=None, **kwargs)[source]#

Bases: QtWidgetElement[QWidget]

Grid layout widget for rendering children on a 2D rectangular grid.

Grid Layout Element.

Props

All props for QtWidgetElement plus:

Parameters:
  • layout (str) – Declaration of layout as described below.

  • key_to_code (Optional[Mapping[str, str]]) – Optional Mapping from Element key to a single character representing that child in the layout string.

Usage

Children will be laid out according to the layout argument. Each child is assigned a character code (by default, the first character of the key; this can be changed via the key_to_code prop). The layout argument describes pictorially where the child should be laid out. For example:

aabc
aabd
effg

describes a layout of 7 children (labeled a to g) in a 3x4 grid. Child a occupies the top left 2x2 portion of the grid, child b occupies a 2x1 portion of the grid starting from the third column of the first row, etc.

You can also leave certain spots empty using ‘_’:

aa__
aabc
GridView Example#
def render(self):
    return ed.GridView(layout='''
        789+
        456-
        123*
        00./
    ''')(
        ed.Button("7").set_key("7"), ed.Button("8").set_key("8"), ed.Button("9").set_key("9"), ed.Button("+").set_key("+"),
        ed.Button("4").set_key("4"), ed.Button("5").set_key("5"), ed.Button("6").set_key("6"), ed.Button("-").set_key("-"),
        ed.Button("1").set_key("1"), ed.Button("2").set_key("2"), ed.Button("3").set_key("3"), ed.Button("*").set_key("*"),
        ed.Button("0").set_key("0"),                              ed.Button(".").set_key("."), ed.Button("*").set_key("/"),
    )

Methods

__init__([layout, key_to_code])

register_ref(reference)

Registers provided Reference to this Element.

set_key(key)

Set the key of an Element.

Attributes

children

The children of this Element.

props

The props of this Element.

underlying

The underlying QWidget, which may not exist if this Element has not rendered.