MultiLineInputDialog

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

Bases: pygamelib.gfx.ui.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=[{'label': 'Input a value:', 'default': '', 'filter': 50000002}], 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 are coming from the constants module and can be either constants.INTEGER_FILTER or constants.PRINTABLE_FILTER.

Example:

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

Methods

__init__([fields, config])
param fields:A list of dictionnary that represent the fields to present to the
render_to_buffer(buffer, row, column, …) Render the object into a display buffer (not a screen 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.
user_input Facility to store and retrieve the user input.
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.

render_to_buffer(buffer, row, column, buffer_height, buffer_width) → 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.
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.PRINTABLE_FILTER,
    }
]

The returned value would be:

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

Example:

fields = multi_input.show()
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.