pybot.minitel.forms
¶
A simple Minitel forms management toolkit.
-
class
pybot.minitel.forms.
Form
(mt)[source]¶ Bases:
object
Defines the forms in terms of layout and field connection with the application.
A form is made of static prompts and entry fields. The class handles its rendering and the management of user interactions when modifying its content.
The definition of the form can be provided by calls to
add_prompt()
andadd_field()
. This can also be done by loading the equivalent JSON data structure, usingload_definition()
.For convenience, the
dump_definition()
does the reverse operation, which allows producing the JSON data directly from the current definition of the form.Warning
The class is intended to be used in Videotex mode. Maybe it works fine in Teleinfo mode too, but it has not been tested. By the way, to ensure all goes well, the Minitel is switched in Videotex mode when rendering forms.
Parameters: mt ( Minitel
) – the Minitel instance-
add_field
(name, x, y, size, marker='.')[source]¶ Adds a field to the form, at a given position and with a given size.
Parameters:
-
dump_definition
()[source]¶ Returns the form current definition as a JSON formatted structure.
The returned structure is a dictionary, containing the two top-level entries
prompts
andfields
.The value of the
prompts
entry is a list of tuples, composed of :- the X position
- the Y position
- the prompt text
The value of the
fields
entry is a sub-dictionary, keyed by the field names, and which values are tuples, composed of :- the X position
- the Y position
- the size (in characters)
- the marker character (defaulted to
.
if not included)
Example:
{ "prompts": [ [0, 2, "First name"], [0, 4, "Last name"], [30, 23, "ENVOI"] ], "fields": { "lname": [15, 4, 20, "."], "fname": [15, 2, 20, "."] } }
Returns: JSON form definition Return type: str
-
input
(content=None, max_wait=None)[source]¶ Handles user interactions and return the fields content if the form is submitted.
The cursor is made visible on start, and hidden back when exiting.
Special keys are interpreted as follows :
ENVOI
(SEND)- submits the form, returning the fields content as a dictionary
SOMMAIRE
(CONTENT)- cancels and returns None
RETOUR
(BACK)- jumps to the previous field (or to the last one if current on the first one)
SUITE
(NEXT)- jumps to the next field (or to the first one if current on the last one)
CORRECTION
- backspaces one character in the field
ANNULATION
(CANCEL)- clears the field
Parameters: Returns: the fields content if the form has been submitted, None otherwise.
Return type:
-
load_definition
(data)[source]¶ Loads the form definition from the provided JSON structure.
Refer to
dump_definition()
documentation for the structure specifications.Parameters: data (str) – the form definition in JSON format Raises: ValueError
– if no data or invalid JSON data provided
-
prepare
()[source]¶ Prepares the form by sorting the prompts and fields according to their position.
Is automatically invoked by
render()
.
-