Character input UI elements

from ui import CharArrowKeysInput
password = CharArrowKeysInput(i, o, message="Password:", name="My password dialog").activate()
if password is None: #UI element exited
    return False #Cancelling
#processing the input you received...
class ui.char_input.CharArrowKeysInput(i, o, initial_value='', message='Value:', allowed_chars=['][S', '][c', '][C', '][s', '][n'], name='CharArrowKeysInput')[source]

Implements a character input dialog which allows to input a character string using arrow keys to scroll through characters


  • value: A list of characters of the currently displayed value
  • position: Position of the currently edited character.
  • cancel_flag: A flag that is set when editing is cancelled.
  • in_foreground: A flag which indicates if UI element is currently displayed. If it’s not active, inhibits any of element’s actions which can interfere with other UI element being displayed.
  • charmap: Internal string that contains all of the possible character values
  • char_indices: A list containing char’s index in charmap for every char in value list
  • first_displayed_char: An integer pointer to the first character currently displayed (for the occasions where part of value is off-screen)
  • last_displayed_char: An integer pointer to the last character currently displayed
__init__(i, o, initial_value='', message='Value:', allowed_chars=['][S', '][c', '][C', '][s', '][n'], name='CharArrowKeysInput')[source]

Initialises the CharArrowKeysInput object.


  • i, o: input&output device objects


  • initial_value: Value to be edited. If not set, will start with an empty string.
  • allowed_chars: Characters to be used during input. Is a list of strings designating ranges which can be the following: * ‘][c’ for lowercase ASCII characters * ‘][C’ for uppercase ASCII characters * ‘][s’ for special characters from those supported by HD44780 character maps * ‘][S’ for space * ‘][n’ for numbers * ‘][h’ for hexadecimal characters (0-F) If a string does not designate a range of characters, it’ll be added to character map as-is.
  • message: Message to be shown in the first row of the display
  • name: UI element name which can be used internally and for debugging.

A method which is called when input element needs to start operating. Is blocking, sets up input&output devices, renders the element and waits until self.in_background is False, while menu callbacks are executed from the input device thread. This method returns the selected value if KEY_ENTER was pressed, thus accepting the selection. This method returns None when the UI element was exited by KEY_LEFT and thus the value was not accepted.


Deactivates the UI element, exiting it and thus making activate() return.


A debug method. Useful for hooking up to an input event so that you can see which UI element is currently processing input events.


A debug method. Useful for hooking up to an input event so that you can see current value.