|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 3 | +# of this software and associated documentation files (the "Software"), to deal |
| 4 | +# in the Software without restriction, including without limitation the rights |
| 5 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 6 | +# copies of the Software, and to permit persons to whom the Software is |
| 7 | +# furnished to do so, subject to the following conditions: |
| 8 | +# |
| 9 | +# The above copyright notice and this permission notice shall be included in |
| 10 | +# all copies or substantial portions of the Software. |
| 11 | +# |
| 12 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 18 | +# THE SOFTWARE. |
| 19 | +# ----------------------------------------------------------------------------- |
| 20 | + |
| 21 | + |
| 22 | +class Console(): |
| 23 | + """ |
| 24 | + A class that represents the EV3 LCD console, which implements ANSI codes |
| 25 | + for cursor positioning, text color, and resetting the screen. Supports changing |
| 26 | + the console font using standard system fonts. |
| 27 | + """ |
| 28 | + |
| 29 | + |
| 30 | + def __init__(self, font="Lat15-TerminusBold24x12"): |
| 31 | + """ |
| 32 | + Construct the Console instance, optionally with a font name specified. |
| 33 | +
|
| 34 | + Parameter: |
| 35 | +
|
| 36 | + - `font` (string): Font name, as found in `/usr/share/consolefonts/` |
| 37 | +
|
| 38 | + """ |
| 39 | + self._font = None |
| 40 | + self._columns = 0 |
| 41 | + self._rows = 0 |
| 42 | + self._echo = False |
| 43 | + self._cursor = False |
| 44 | + self.set_font(font, reset_console=False) # don't reset the screen during construction |
| 45 | + self.cursor = False |
| 46 | + self.echo = False |
| 47 | + |
| 48 | + |
| 49 | + @property |
| 50 | + def columns(self): |
| 51 | + """ |
| 52 | + Return (int) number of columns on the EV3 LCD console supported by the current font. |
| 53 | + """ |
| 54 | + |
| 55 | + pass |
| 56 | + |
| 57 | + |
| 58 | + @property |
| 59 | + def rows(self): |
| 60 | + """ |
| 61 | + Return (int) number of rows on the EV3 LCD console supported by the current font. |
| 62 | + """ |
| 63 | + |
| 64 | + pass |
| 65 | + |
| 66 | + |
| 67 | + @property |
| 68 | + def echo(self): |
| 69 | + """ |
| 70 | + Return (bool) whether the console echo mode is enabled. |
| 71 | + """ |
| 72 | + |
| 73 | + pass |
| 74 | + |
| 75 | + |
| 76 | + @echo.setter |
| 77 | + def echo(self, value): |
| 78 | + """ |
| 79 | + Enable/disable console echo (so that EV3 button presses do not show the escape characters on |
| 80 | + the LCD console). Set to True to show the button codes, or False to hide them. |
| 81 | + """ |
| 82 | + |
| 83 | + pass |
| 84 | + |
| 85 | + |
| 86 | + @property |
| 87 | + def cursor(self): |
| 88 | + """ |
| 89 | + Return (bool) whether the console cursor is visible. |
| 90 | + """ |
| 91 | + |
| 92 | + pass |
| 93 | + |
| 94 | + |
| 95 | + @cursor.setter |
| 96 | + def cursor(self, value): |
| 97 | + """ |
| 98 | + Enable/disable console cursor (to hide the cursor on the LCD). |
| 99 | + Set to True to show the cursor, or False to hide it. |
| 100 | + """ |
| 101 | + |
| 102 | + pass |
| 103 | + |
| 104 | + |
| 105 | + def text_at(self, text, column=1, row=1, reset_console=False, inverse=False, alignment="L"): |
| 106 | + """ |
| 107 | + Display `text` (string) at grid position (`column`, `row`). |
| 108 | + Note that the grid locations are 1-based (not 0-based). |
| 109 | +
|
| 110 | + Depending on the font, the number of columns and rows supported by the EV3 LCD console |
| 111 | + can vary. Large fonts support as few as 11 columns and 4 rows, while small fonts support |
| 112 | + 44 columns and 21 rows. The default font for the Console() class results in a grid that |
| 113 | + is 14 columns and 5 rows. |
| 114 | +
|
| 115 | + Using the `inverse=True` parameter will display the `text` with more emphasis and contrast, |
| 116 | + as the background of the text will be black, and the foreground is white. Using inverse |
| 117 | + can help in certain situations, such as to indicate when a color sensor senses |
| 118 | + black, or the gyro sensor is pointing to zero. |
| 119 | +
|
| 120 | + Use the `alignment` parameter to enable the function to align the `text` differently to the |
| 121 | + column/row values passed-in. Use `L` for left-alignment (default), where the first character |
| 122 | + in the `text` will show at the column/row position. Use `R` for right-alignment, where the |
| 123 | + last character will show at the column/row position. Use `C` for center-alignment, where the |
| 124 | + text string will centered at the column/row position (as close as possible using integer |
| 125 | + division--odd-length text string will center better than even-length). |
| 126 | +
|
| 127 | + Parameters: |
| 128 | +
|
| 129 | + - `text` (string): Text to display |
| 130 | + - `column` (int): LCD column position to start the text (1 = left column); |
| 131 | + text will wrap when it reaches the right edge |
| 132 | + - `row` (int): LCD row position to start the text (1 = top row) |
| 133 | + - `reset_console` (bool): ``True`` to reset the EV3 LCD console before showing |
| 134 | + the text; default is ``False`` |
| 135 | + - `inverse` (bool): ``True`` for white on black, otherwise black on white; |
| 136 | + default is ``False`` |
| 137 | + - `alignment` (string): Align the `text` horizontally. Use `L` for left-alignment (default), |
| 138 | + `R` for right-alignment, or `C` for center-alignment |
| 139 | +
|
| 140 | + """ |
| 141 | + |
| 142 | + pass |
| 143 | + |
| 144 | + |
| 145 | + def set_font(self, font="Lat15-TerminusBold24x12", reset_console=True): |
| 146 | + """ |
| 147 | + Set the EV3 LCD console font and optionally reset the EV3 LCD console |
| 148 | + to clear it and turn off the cursor. |
| 149 | +
|
| 150 | + Parameters: |
| 151 | +
|
| 152 | + - `font` (string): Font name, as found in `/usr/share/consolefonts/` |
| 153 | + - `reset_console` (bool): ``True`` to reset the EV3 LCD console |
| 154 | + after the font change; default is ``True`` |
| 155 | +
|
| 156 | + """ |
| 157 | + |
| 158 | + pass |
| 159 | + |
| 160 | + |
| 161 | + def clear_to_eol(self, column=None, row=None): |
| 162 | + """ |
| 163 | + Clear to the end of line from the `column` and `row` position |
| 164 | + on the EV3 LCD console. Default to current cursor position. |
| 165 | +
|
| 166 | + Parameters: |
| 167 | +
|
| 168 | + - `column` (int): LCD column position to move to before clearing |
| 169 | + - `row` (int): LCD row position to move to before clearing |
| 170 | +
|
| 171 | + """ |
| 172 | + |
| 173 | + pass |
| 174 | + |
| 175 | + |
| 176 | + def reset_console(self): |
| 177 | + """ |
| 178 | + Clear the EV3 LCD console using ANSI codes, and move the cursor to 1,1 |
| 179 | + """ |
| 180 | + |
| 181 | + pass |
0 commit comments