MultiLineInputDialog

class pygamelib.gfx.ui.MultiLineInputDialog(fields=[{'default': '', 'filter': InputValidator.PRINTABLE_FILTER, 'label': 'Input a value:'}], title: str = None, config=None)

Bases: Dialog

The MultiLineInputDialog behave essentially like the LineInputDialog but is more configurable to allow the user to enter and edit a multiple lines of text.

Each field of this dialog can be individually configured to accept either anything printable or only digits.

The show() method returns the user input.

Key mapping:

  • ESC: set the user input to “” and exit from the show() method.

  • ENTER: Exit from the show() method. Returns the user input.

  • BACKSPACE / DELETE: delete a character (both keys have the same result).

  • TAB: cycle through the fields.

  • All other keys input characters in the input field.

In all cases, when the dialog is closed, the user input is returned.

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

__init__(fields=[{'default': '', 'filter': InputValidator.PRINTABLE_FILTER, 'label': 'Input a value:'}], title: str = None, config=None) None
Parameters:
  • fields (list) – A list of dictionnary that represent the fields to present to the user. Please see bellow for a description of the dictionnary.

  • title (str) – The short title of the dialog. Only used when the dialog is not borderless.

  • config (UiConfig) – The configuration object.

The fields needs to be a list that contains dictionaries. Each of the dictionaries needs to contain 3 fields:

  • “label”: A one line instruction displayed over the field. This is a string.

  • “default”: A string that is going to pre-fill the input field.

  • “filter”: A filter to configure the acceptable inputs.

The filters needs to be a InputValidator.

Example:

fields = [
    {
        "label": "Enter the height of the new sprite:",
        "default": "",
        "filter": constants.InputValidator.INTEGER_FILTER,
    },
    {
        "label": "Enter the width of the new sprite:",
        "default": "",
        "filter": constants.InputValidator.INTEGER_FILTER,
    },
    {
        "label": "Enter the name of the new sprite:",
        "default": f"Sprite {len(sprite_list)}",
        "filter": constants.InputValidator.PRINTABLE_FILTER,
    },
]
multi_input = MultiLineInput(fields, conf)
screen.place(multi_input, 10, 10)
completed_fields = multi_input.show()

Methods

__init__([fields, title, config])

param fields:

A list of dictionnary that represent the fields to present to 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).

fields

Get and set the fields of the dialog, see the constructor for the format or this list.

title

Get and set the title of the dialog, it has to be a str.

user_input

Facility to store and retrieve the user input.

property config

Get and set the config object (UiConfig).

property fields

Get and set the fields of the dialog, see the constructor for the format or this list.

render_to_buffer(buffer, row, column, buffer_height, buffer_width) 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 a list of dictionaries with the content of each fields. The list of dictionaries is the same than the fields constructor parameter but each key has an additional ‘user_input’ field that contains the user input.

If the fields parameter was:

[
    {
        "label": "Input a value:",
        "default": "",
        "filter": constants.InputValidator.PRINTABLE_FILTER,
    }
]

The returned value would be:

[
    {
        "label": "Input a value:",
        "default": "",
        "filter": constants.InputValidator.PRINTABLE_FILTER,
        "user_input": "some input",
    }
]

Example:

fields = multi_input.show()
property title: str

Get and set the title of the dialog, it has to be a str.

property user_input

Facility to store and retrieve the user input.