class Grid(QObject):
| Method | __init__ |
Examples |
| Instance Variable | layout |
Composed QGridLayout object. Will be cleared |
| Instance Variable | wh |
Composed _WriteHead object |
| Instance Variable | colgaps |
Composed _ColumnGaps object |
| Instance Variable | spans |
Composed _Spans object |
| Instance Variable | cells |
Composed _Cells object |
| Instance Variable | expand_left |
Boolean. If True, a far left column with expanders are applied |
| Instance Variable | expand_right |
Boolean. If True, a far right column with expanders are applied |
| Instance Variable | content_columns |
Integer >= 1. Max number of content columns |
| Instance Variable | work_up |
Boolean. If True, visual help is applied |
| Instance Variable | label_sources |
Dictionary = { "name_id1": qlabel1, "name_id2": qlabel2, ... } |
| Instance Variable | custom_lists |
Dictionary = { "list_name1": [ ], "list_name2": [ ], ... } |
| Method | set_list_names |
Prepare internal lists with given names |
| Method | set_expand_left |
Set whether or not to add a far left expanding column, influencing the grid alignment |
| Method | set_expand_right |
Set whether or not to add a far right expanding column, influencing the grid alignment |
| Method | set_content_columns |
Set maximum number of content columns |
| Method | set_column_gaps |
Interface method to _ColumnGaps.set |
| Method | set_work_up |
Set whether or not to activate the work-up mode |
| Method | set_label_source |
Store a given QLabel object as a copy source |
| Method | get_list |
Get name list of widgets as it was prepared with set_list_names |
| Method | get_list_names |
Get all custom list names as they were prepared with set_list_names |
| Method | get_content_columns |
Get max number of content columns |
| Method | get_label |
Get stored QLabel object by name_id |
| Method | add |
Add a widget to the current _WriteHead position into the grid |
| Method | add_gap |
Add a _Cell object with a _Gap object to the _WriteHead position into the grid |
| Method | add_empty_row |
Add a row gap |
| Method | add_label |
Add a _Cell object with a QLabel object at _WriteHead position into the grid |
| Method | clear |
Delete all _Cell objects and corresponding items in QGridLayout recursively |
| Method | finish |
Always call this after you added all your cells |
| Method | _set_default_label_sources |
Set label sources for "default" and "default-header" |
| Method | _get_remaining_x_span |
Get the number of remaining cells in row |
| Method | _copy_label |
Get a copy of a given label |
Examples
grid = Grid()
grid = Grid(
layout = QGridLayout(),
content_columns = 5,
expand_left = False,
expand_right = True,
work_up = True,
column_gaps = [ (1, 20), (3, None) ],
list_names = ["list1", "list2"],
)| Parameters | layout | None (default) or QGridLayout object |
| content_columns | Max int number of content columns, default 1 | |
| expand_left | boolean, default False | |
| expand_right | boolean, default False | |
| work_up | boolean, default False | |
| column_gaps | list of tuples, default [ ] | |
| list_names | list of string names pointing to lists, default [ ] |
Prepare internal lists with given names
grid.set_list_names("list1", "list2") grid.set_list_names()
clear method.get_list_names, or get_list methods to access the lists in turn.| Parameters | names | list of strings, default [ ] |
Set whether or not to add a far left expanding column, influencing the grid alignment
Can only be used before any widget is added or after calling the clear method.
| Parameters | flag | boolean, default False |
Set whether or not to add a far right expanding column, influencing the grid alignment
Can only be used before any widget is added or after calling the clear method.
| Parameters | flag | boolean, default False |
Set maximum number of content columns
grid.set_content_columns( content_columns=1 ) grid.set_content_columns( 1 )
clear method.set_column_gaps method.| Parameters | content_columns | int n with n >= 1 and n > number of _ColumnGaps.count, default 1 |
Set whether or not to activate the work-up mode
Can only be used before any widget is added or after calling the clear method.
In work up mode otherwise invisible cells are colored indicating the following meaning:
| Parameters | flag | boolean, default False |
Store a given QLabel object as a copy source
grid.set_label_source( name_id="foo", label=myLabel ) grid.set_label_source("foo", myLabel)
The name_id is the key to access the label with the add_label, or get_label methods.
| Parameters | name_id | required str name for the label |
| label | required QLabel object to store |
Get name list of widgets as it was prepared with set_list_names
The returned list contains QWidgets object added with the add or add_label methods.
for widget in grid.get_list("list1"): pass
| Parameters | name | required str name of an internal list |
| Returns | list of widgets (type: list) | |
Get all custom list names as they were prepared with set_list_names
names = grid.get_list_names() for name in names: for widget in grid.get_list( name ): pass
| Returns | list of list names (type: list) | |
Get stored QLabel object by name_id
Labels are stored with set_label_source.
| Parameters | name_id | required str id for a stored label |
| Returns | QLabel object (type: object) | |
Add a widget to the current _WriteHead position into the grid
cell = grid.add( widget=WIDGET, y_span=1, x_span=1, to_list="list_name" ) cell = grid.add( WIDGET, y_span=2, x_span=2 ) cell = grid.add( WIDGET, x_span="all" ) cell = grid.add( WIDGET )
set_list_names method.| Parameters | widget | required QWidget object to be added |
| y_span | int >= 1, default 1 | |
| x_span | int >= 1, or string "all", default 1 | |
| to_list | optional str name of an internal list | |
| Returns | _Cell object with QWidget object (type: object) | |
Add a _Cell object with a _Gap object to the _WriteHead position into the grid
cell = add_gap(direction="H", length="20", y_span=2, x_span=2) # horizontal direction cell = add_gap("H") # same as None cell = add_gap("H", 0) # same as None cell = add_gap("H", None) # explicitly empty cell = add_gap("H", 20) cell = add_gap("H", "expand") # horizontal direction is default cell = add_gap() # same as None cell = add_gap(0) # same as None cell = add_gap(None) # explicitly empty cell = add_gap(20) cell = add_gap("expand") # vertical direction cell = add_gap("V") # same as None cell = add_gap("V", 0) # same as None cell = add_gap("V", None) # explicitly empty cell = add_gap("V", 20) cell = add_gap("V", "expand")
See the set_work_up method for a list of displayed colors in work_up mode.
| Parameters | direction | None, "H" (default) , "V", "horizontal", or "vertical" |
| length | None, int >= 0, or "expand", default None | |
| y_span | int >= 1, default 1 | |
| x_span | int >= 1, default 1 | |
| Returns | _Cell object with a _Gap object (type: object) | |
Add a row gap
cell = grid.add_empty_row() # same as None cell = grid.add_empty_row(0) # same as None cell = grid.add_empty_row(None) # explicitly empty cell = grid.add_empty_row(20) cell = grid.add_empty_row("expand")
set_work_up method for a list of displayed colors in work_up mode.| Parameters | height | None (default), int >= 0, or "expand" |
| Returns | _Cell object with _Gap object (type: object) | |
Add a _Cell object with a QLabel object at _WriteHead position into the grid
set_label_source method.cell = grid.add_label( name_id="foo", text="lorem ipsum", y_span=2, x_span=2, to_list="list1" ) cell = grid.add_label("foo", "lorem ipsum", y_span=2, x_span=2, to_list="list1") cell = grid.add_label("foo", "lorem ipsum", x_span="all") cell = grid.add_label("foo", "lorem ipsum")
There are predefined defaults:
cell = grid.add_label("default", "lorem ipsum") cell = grid.add_label("default-header", "Some Header")
get_label method._Cell object, since the added labelcell = grid.add_label("default", "lorem ipsum") label = cell.item
| Parameters | name_id | required string |
| text | required string | |
| y_span | int >= 1, default 1 | |
| x_span | int >= 1, or string "all", default 1 | |
| to_list | optional str name of an internal list | |
| Returns | _Cell object with QLabel object (type: object) | |
Delete all _Cell objects and corresponding items in QGridLayout recursively
grid.clear()
_WriteHead coordinates are reset.custom_lists and the private list _Spans._list are reset.| Parameters | _layout | None or QGridLayout object |
Always call this after you added all your cells
_Cell objects their holding QWidget objects to the resulting QGridLayout.Set label sources for "default" and "default-header"
After calling this method at init time the user can do :
grid.add_label("default", "my text") grid.add_label("default-header", "Some Header")
Get the number of remaining cells in row
_WriteHead is taken.| Parameters | from_x | None (default), or int >= 0 |
| Returns | int >= 0 (type: int) | |