Numeric input UI elements

from ui import IntegerAdjustInput
start_from = 0
number = IntegerAdjustInput(start_from, i, o).activate()
if number is None: #Input cancelled
    return
#process the number
class ui.number_input.IntegerAdjustInput(number, i, o, message='Pick a number:', interval=1, name='IntegerAdjustInput', mode='normal')[source]

Implements a simple number input dialog which allows you to increment/decrement a number using which can be used to navigate through your application, output a list of values or select actions to perform. Is one of the most used elements, used both in system core and in most of the applications.

Attributes:

  • number: The number being changed.
  • initial_number: The number sent to the constructor. Used by reset() method.
  • selected_number: A flag variable to be returned by activate().
  • 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.
__init__(number, i, o, message='Pick a number:', interval=1, name='IntegerAdjustInput', mode='normal')[source]

Initialises the IntegerAdjustInput object.

Args:

  • number: number to be operated on
  • i, o: input&output device objects

Kwargs:

  • message: Message to be shown on the first line of the screen when UI element is active.
  • interval: Value by which the number is incremented and decremented.
  • name: UI element name which can be used internally and for debugging.
  • mode: Number display mode, either “normal” (default) or “hex” (“float” will be supported eventually)
activate()[source]

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

deactivate()[source]

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

print_number()[source]

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

print_name()[source]

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

decrement(*args, **kwargs)[source]

Decrements the number by selected interval

increment(*args, **kwargs)[source]

Increments the number by selected interval

reset(*args, **kwargs)[source]

Resets the number, setting it to the number passed to the constructor.

select_number(*args, **kwargs)[source]

Selects the currently active number value, making activate() return it.