pybot.minitel.core

Core classes for communicating with a Minitel.

class pybot.minitel.core.Minitel(port=None, baud=4800, debug=False)[source]

Bases: object

Represents a Minitel beast.

Warning

tested only with a Philips Minitel 2

The serial port to be used can be either a string such as /dev/ttyUSB0 or an instance of serial.Serial. In this case, the port is automatically opened if not yet done.

Warning

When providing a port instance, beware to have it initialized with even parity and 7 data bytes.

Parameters:
  • port (str or serial.Serial) – serial port identification or serial port instance
  • baud (int) – baud rate (default: 4800)
  • debug (bool) – if True, communications are traced
Raises:
  • ValueError – if port is not specified.
  • TypeError – if the port type is not one of the expected ones
activate_echo(activate=True)[source]

Activates or deactivates the local echo :param activate: True for local echo activation, False otherwise

char_size_sequence(width=1, height=1)[source]

Returns the sequence for changing the size (width and height) of the characters in Videotex mode.

Parameters:
  • width (int) – character width (1 or 2)
  • height (int) – character height (1 or 2)
Returns:

the sequence

Return type:

str

Raises:

ValueError – if invalid width or height

clear_all()[source]

Clears the whole screen, including the status line.

clear_line(part=2)[source]

Clears (a part of) the current line.

Parameters:part (int) – which part should be cleared (among :py:class:Part pre-defined constants)
Raises:ValueError – if part code is invalid
clear_screen(part=2)[source]

Clears (a part of) the screen.

Parameters:part (int) – which part should be cleared (among PART_xxx constants)
Raises:ValueError – if part code is invalid
clear_status()[source]

Clears the status line

close()[source]

Closes the communication.

Should be invoked only when the instance is no more needed.

cursor_home()[source]

Moves the cursor to the top-left corner of the screen.

display_status(text, x=0)[source]

Displays a text in the status line.

Parameters:
  • text (str) – the text to display
  • x (int) – the horizontal position in [0, 39] (default: 0)
Raises:

ValueError – if horizontal position is invalid

display_text(text, x=0, y=0, clear_eol=False, clear_bol=False, charset=0, char_width=1, char_height=1)[source]

Displays a text at a given position of the screen, with various options.

The clear_xxx options provide convenient way to clear parts of the target line while displaying the text.

The charset to be used can be customised. Same for the character size.

Parameters:
  • text (str) – the text to be displayed
  • x (int) – horizontal position
  • y (int) – vertical position
  • clear_eol (bool) – if True the target line is cleared after the end of the displayed text
  • clear_bol (bool) – if True the target line is cleared before the start end of the displayed text
  • charset (int) – the charset to be used
  • width (int) – character width (1 or 2)
  • height (int) – character height (1 or 2)
display_text_center(text, y=0, charset=0, char_width=1, char_height=1, pad_char=' ')[source]

Convenience method for displaying a centered text on a given line.

Parameters:pad_char (str) – the string padding char. Default: ‘ ‘

See display_text() for the documentation of the other parameters

flush()[source]

Flushes the serial link (output direction).

get_cursor_position()[source]

Returns the current cursor position.

Returns:X, Y coordinates as a tuple
Return type:tuple
get_functional_status()[source]

Returns the current settings of the modules.

Returns:caps lock state, roll mode, screen width
Return type:tuple
get_screen_width()[source]

Returns the width of the screen (in characters), depending on the current mode.

Returns:the width (40 or 80)
Return type:int
get_speeds()[source]

Returns the current teleinfo communication speed settings.

Teleinfo link speeds are symmetrical, so both values should be the same.

Returns:send/received baudrates
Return type:tuple
goto_xy(x, y)[source]

Moves the cursor to the given 0 based coordinates.

Parameters:
  • x (int) – X (col) position
  • y (int) – Y (line) position
Raises:

ValueError – if coordinates are outside valid ranges

in_videotex_mode()[source]

Tells if we are presently in Videotex mode.

Tries to probe the device. If it is not in Videotex, the Protocol module is not here, and we will get no reply.

Returns:True if in Videotex mode, False otherwise
Return type:bool
input(max_length=40, prompt=None, input_start_xy=None, marker=' ', max_wait=None)[source]

Get a user input from the Minitel.

Handles common editing actions, such as backspace and clear input.

Warning

The serial link is flushed before waiting for the input.

Parameters:
  • max_length (int) – maximum length of entered text
  • prompt (tuple) – optional prompt to display, as a (text, width, x, y) tuple
  • input_start_xy (tuple) – x, y coordinates for input area start. If None, use the current position
  • max_wait (int) – maximum wait time in seconds for user to complete the input (if None, waits indefinitely)
Returns:

the entered value and the key used to terminate the entry

Return type:

tuple

is_w80()[source]

Tells if the screen is currently in 80 chars width.

Returns:is large screen currently active
Return type:bool
newline()[source]

Sends a newline/carriage return combo.

probe()[source]

Reads the content of the identification ROM and returns it in a decoded form.

Returns:class:DeviceSpecs: the decoded identification ROM
Return type::py
receive(count=1)[source]

Receives a given count of bytes from the Minitel.

Does not wait for data, but returns whats is currently available.

Parameters:count (int) – the expected count of bytes (default: 1)
Returns:the received bytes
Return type:str
request(command, reply_size)[source]

Sends a request and returns its reply.

Warning

The serial input link is flushed before issuing the request to be sure that the returned value will not contain data remaining from previous communications. This means that such data will be lost.

Parameters:
  • command (str) – the command to be sent
  • reply_size (int) – the size of the expected reply
Returns:

the reply

Return type:

str

reset()[source]

Guess what...

rlinput(max_length=40, marker=' ', start_pos=None, initial_value=None, max_wait=None)[source]

User input with basic Gnu’s readline features

Parameters:
  • max_length (int) – max length of the input
  • marker (str) – the char to be used as the input area filler
  • start_pos (tuple) – input area start position (default: current one)
  • initial_value (str) – the value of the input on entry
  • max_wait (int) – maximum wait time in seconds for user to complete the input (if None, waits indefinitely)
Returns:

the entered value and the key used to terminate the entry. If the time limit has been reached, the first item will be the characters entered so far and the second one will be None

Return type:

tuple

send(data)[source]

Sends data to the Minitel.

Parameters:data (str) – the data to be sent
set_char_size(width=1, height=1)[source]

Defines the size (width and height) of the characters in Videotex mode.

Parameters:
  • width (int) – character width (1 or 2)
  • height (int) – character height (1 or 2)
Raises:

ValueError – if not in Videotex mode or in invalid width or height

set_charset(num=0)[source]

Activates the charset (i.e. Gn) to be used for subsequent text display.

Parameters:num (int) – the charset num (in range [0, 2])
Raises:ValueError – if passed number is out of range
set_colors(fg=None, bg=None)[source]

Sets the color of subsequently displayed text.

The color is translated to a gray level on a monochrome Minitel.

Parameters:
  • fg (int) – foreground color (if None, don’t change it)
  • bg (int) – background color (if None, don’t change it)
Raises:

ValueError if color is out of range

set_mode(mode, force=False)[source]

Sets the Minitel mode.

Parameters:
  • mode (int) – the operating mode, selected among VIDEOTEX, MIXED and TELEINFO
  • force (bool) – if True, the command is issued whatever is the current mode
Raises:

ValueError – if a wrong mode is passed

set_speed(speed)[source]

Sets the communication link communication speed.

Send and receive speeds are set to the same value, since the teleinfo link is symmetrical.

The provided value is automatically interpreted as a speed code or a baudrate if it is a valid value for both cases. See LinkSpeed for details.

Parameters:speed (int) – baudrate or speed code
Raises:ValueError – if an invalid speed is provided
set_text_normal()[source]

Reverts to normal text.

set_text_style(blink=None, inverse=None, underscore=None, bright=None)[source]

Sets the attributes for subsequently displayed text.

show_cursor(on=True)[source]

Sets the visibility of the cursor.

Ignored if not in Videotex mode.

Parameters:on (bool) – True for showing the caret, False to hide it
videotex_graphic_mode(activate=True, force=False)[source]

Switches Videotex mode between graphics and text

Parameters:
  • activate (bool) – True (default) to activate graphics mode
  • force (bool) – True to ignore current mode and send the appropriate sequence anyway
wait_for_key(key_set=('\x13A', ), max_wait=None)[source]

Waits for the user to type any key in the provided set.

Parameters:
  • key_set (iterable) – the list of the codes of the accepted keys
  • max_wait (int) – maximum wait time in seconds (if None, waits indefinitely)
Returns:

the hit key, or None if nothing accepted has been typed in the given delay

Return type:

char

class pybot.minitel.core.Part[source]

Bases: object

A screen or line part.