GridSelector

class pygamelib.gfx.ui.GridSelector(choices: list = None, max_height: int = None, max_width: int = None, config: pygamelib.gfx.ui.UiConfig = None)

Bases: object

The GridSelector is a widget that present a list of elements as a grid to the user.

It also provides the API to draw and manage the cursor and to retrieve the selected element.

Warning

In the first version of that widget, only the characters that have a length of 1 are supported. This excludes some UTF8 characters and most of the emojis.

__init__(choices: list = None, max_height: int = None, max_width: int = None, config: pygamelib.gfx.ui.UiConfig = None) → None
Parameters:
  • choices (list) – A list of choices to present to the user. The elements of the list needs to be str or Sprixel.
  • max_height (int) – The maximum height of the grid selector.
  • max_width (int) – The maximum width of the grid selector.
  • config (UiConfig) – The configuration object.

Example:

choices = ["@","#","$","%","&","*","[","]"]
grid_selector = GridSelector(choices, 10, 30, conf)
screen.place(grid_selector, 10, 10)
screen.update()

Methods

__init__(choices, max_height, max_width, config)
param choices:A list of choices to present to the user. The elements of the
current_sprixel() Returns the currently selected sprixel.
cursor_down() Move the selection cursor one row down.
cursor_left() Move the selection cursor one column to the left.
cursor_right() Move the selection cursor one column to the right.
cursor_up() Move the selection cursor one row up.
items_per_page() Returns the number of items per page.
nb_pages() Returns the number of pages.
page_down() Change the current page to the one immediately down (current_page + 1).
page_up() Change the current page to the one immediately up (current_page - 1).
render_to_buffer(buffer, row, column, …) Render the object into a display buffer (not a screen buffer).

Attributes

choices Get and set the list of choices, it has to be a list of Sprixel or str.
current_choice Get and set the currently selected item’s index (the current choice), it needs to be an int.
current_page Get and set the current page of the grid selector, it needs to be an int.
max_height Get and set the maximum height of the grid selector, it needs to be an int.
max_width Get and set the maximum width of the grid selector, it needs to be an int.
choices

Get and set the list of choices, it has to be a list of Sprixel or str.

current_choice

Get and set the currently selected item’s index (the current choice), it needs to be an int. Use current_sprixel() to get the actual current item.

current_page

Get and set the current page of the grid selector, it needs to be an int.

current_sprixel() → pygamelib.gfx.core.Sprixel

Returns the currently selected sprixel.

cursor_down() → None

Move the selection cursor one row down.

cursor_left() → None

Move the selection cursor one column to the left.

cursor_right() → None

Move the selection cursor one column to the right.

cursor_up() → None

Move the selection cursor one row up.

items_per_page() → int

Returns the number of items per page.

max_height

Get and set the maximum height of the grid selector, it needs to be an int.

max_width

Get and set the maximum width of the grid selector, it needs to be an int.

nb_pages() → int

Returns the number of pages.

page_down() → None

Change the current page to the one immediately down (current_page + 1).

page_up() → None

Change the current page to the one immediately up (current_page - 1).

render_to_buffer(buffer, row: int, column: int, buffer_height: int, buffer_width: int) → None

Render the object into a display buffer (not a screen buffer).

This method is automatically called by pygamelib.engine.Screen.render().

Parameters:
  • buffer (numpy.array) – A screen buffer to render the item into.
  • row (int) – The row to render in.
  • column (int) – The column to render in.
  • height (int) – The total height of the display buffer.
  • width (int) – The total width of the display buffer.