Class Console
A class that represents the EV3 LCD console, which implements ANSI codes for cursor positioning, text color, and resetting the screen. Supports changing the console font using standard system fonts.
Declaration
class Console
source linkDocumentation
Methods
▶ def __init__(self, font="Lat15-TerminusBold24x12") Construct the Console instance, optionally with a font name specified.
▶ def clear_to_eol(self, column=None, row=None) Clear to the end of line from the ``column`` and ``row`` position on the EV3 LCD console. Default to current cursor position.
▷ def columns(self) @property Return (int) number of columns on the EV3 LCD console supported by the current font.
@property
def columns(self)
▷ def cursor(self) @property Return (bool) whether the console cursor is visible.
@property
def cursor(self)
▷ def cursor(self, value) @cursor.setter Enable/disable console cursor (to hide the cursor on the LCD). Set to True to show the cursor, or False to hide it.
@cursor.setter
def cursor(
self,
value,
)
▷ def echo(self) @property Return (bool) whether the console echo mode is enabled.
▷ def echo(self, value) @echo.setter Enable/disable console echo (so that EV3 button presses do not show the escape characters on the LCD console). Set to True to show the button codes, or False to hide them.
@echo.setter
def echo(
self,
value,
)
▷ def reset_console(self) Clear the EV3 LCD console using ANSI codes, and move the cursor to 1,1
▷ def rows(self) @property Return (int) number of rows on the EV3 LCD console supported by the current font.
▶ def set_font(self, font="Lat15-TerminusBold24x12", reset_console=True) Set the EV3 LCD console font and optionally reset the EV3 LCD console to clear it and turn off the cursor.
Parameters:
font (string): Font name, as found in /usr/share/consolefonts/
reset_console (bool): True to reset the EV3 LCD console after the font change; default is True
▶ def text_at(self, text, column=1, row=1, reset_console=False, inverse=False, alignment="L") Display ``text`` (string) at grid position (``column``, ``row``). Note that the grid locations are 1-based (not 0-based).
Depending on the font, the number of columns and rows supported by the EV3 LCD console can vary. Large fonts support as few as 11 columns and 4 rows, while small fonts support 44 columns and 21 rows. The default font for the Console() class results in a grid that is 14 columns and 5 rows.
Using the inverse=True parameter will display the text with more emphasis and contrast, as the background of the text will be black, and the foreground is white. Using inverse can help in certain situations, such as to indicate when a color sensor senses black, or the gyro sensor is pointing to zero.
Use the alignment parameter to enable the function to align the text differently to the column/row values passed-in. Use L for left-alignment (default), where the first character in the text will show at the column/row position. Use R for right-alignment, where the last character will show at the column/row position. Use C for center-alignment, where the text string will centered at the column/row position (as close as possible using integer division--odd-length text string will center better than even-length).
Parameters:
text (string): Text to display
column (int): LCD column position to start the text (1 = left column); text will wrap when it reaches the right edge
row (int): LCD row position to start the text (1 = top row)
reset_console (bool): True to reset the EV3 LCD console before showing the text; default is False
inverse (bool): True for white on black, otherwise black on white; default is False
alignment (string): Align the text horizontally. Use L for left-alignment (default), R for right-alignment, or C for center-alignment