GridSelectorDialog

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

Bases: Dialog

The GridSelectorDialog is an easy wrapper around the GridSelector object. It offers a simple interface for the programmer to present a GridSelector to the user and retrieve its selection.

The show() method returns the path selected by the user.

Key mapping:

  • ESC: set the selected item to an empty Sprixel and exit from the show() method.

  • ENTER: Exit from the show() method. Returns the currently selected sprixel.

  • UP / DOWN / LEFT / RIGHT: Navigate between the files.

  • PAGE_UP / PAGE_DOWN: Go to previous / next page if there’s any.

In all cases, when the dialog is closed, a Sprixel is returned.

Like all dialogs, it is automatically destroyed on exit of the show() method. It is also deleted from the screen buffer.

__init__(choices: list = None, max_height: int = None, max_width: int = None, title: str = None, config: 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_dialog = GridSelector(choices, 10, 30, conf)
screen.place(grid_dialog, 10, 10)
grid_dialog.show()

Methods

__init__([choices, max_height, max_width, ...])

param choices:

A list of choices to present to the user. The elements of the

render_to_buffer(buffer, row, column, ...)

Render the object from the display buffer to the frame buffer.

show()

Show the dialog and execute the event loop.

Attributes

config

Get and set the config object (UiConfig).

grid_selector

Get / set the GridSelector object, it has to be a GridSelector object.

title

Get / set the title of the dialog, it needs to be a str.

user_input

Facility to store and retrieve the user input.

property config

Get and set the config object (UiConfig).

property grid_selector

Get / set the GridSelector object, it has to be a GridSelector object.

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

Render the object from the display buffer to the frame 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.

show()

Show the dialog and execute the event loop. Until this method returns, all keyboards event are processed by the local event loop. This is also true if called from the main event loop.

This event loop returns the selected item as a Sprixel or None if the user pressed the ESC key.

Returns:

The selected item.

Return type:

Sprixel

Example:

item = grid_dialog.show()
property title

Get / set the title of the dialog, it needs to be a str.

property user_input

Facility to store and retrieve the user input.