|
1 | 1 | #!/usr/bin/env micropython |
2 | 2 | from time import sleep |
3 | | -from sys import stderr, stdin |
| 3 | +from sys import stderr |
4 | 4 | from os import listdir |
5 | 5 | from ev3dev2.console import Console |
6 | 6 |
|
7 | 7 | """ |
8 | | -Used to iterate over the system console fonts (in /usr/share/consolefonts) and calculate the max row/col |
9 | | -position by moving the cursor to 50, 50 and asking the LCD for the actual cursor position |
10 | | -where it ends up (the EV3 LCD console driver prevents the cursor from positioning off-screen). |
| 8 | +Used to iterate over the system console fonts (in /usr/share/consolefonts) and show the max row/col. |
11 | 9 |
|
12 | | -The font specification consists of three parameters - codeset, font face and font size. The codeset specifies |
| 10 | +Font names consist of three parameters - codeset, font face and font size. The codeset specifies |
13 | 11 | what characters will be supported by the font. The font face determines the general look of the font. Each |
14 | 12 | font face is available in certain possible sizes. |
15 | 13 |
|
|
18 | 16 | """ |
19 | 17 |
|
20 | 18 |
|
21 | | -def calc_fonts(): |
| 19 | +def show_fonts(): |
22 | 20 | """ |
23 | | - Iterate through all the Latin "1 & 5" fonts, and use ANSI escape sequences to see how many rows/columns |
24 | | - the EV3 LCD console can accommodate for each font |
| 21 | + Iterate through all the Latin "1 & 5" fonts, and see how many rows/columns |
| 22 | + the EV3 LCD console can accommodate for each font. |
| 23 | + Note: `Terminus` fonts are "thinner"; `TerminusBold` and `VGA` offer more contrast on the LCD console |
| 24 | + and are thus more readable; the `TomThumb` font is waaaaay too small to read! |
25 | 25 | """ |
26 | 26 | console = Console() |
27 | | - |
28 | 27 | files = [f for f in listdir("/usr/share/consolefonts/") if f.startswith("Lat15") and f.endswith(".psf.gz")] |
29 | 28 | files.sort() |
| 29 | + fonts = [] |
30 | 30 | for font in files: |
31 | 31 | console.set_font(font, True) |
32 | | - |
33 | | - # position cursor at 50, 50, and ask the console to report its actual cursor position |
34 | | - console.text_at("\x1b[6n", 50, 50, False) |
35 | 32 | console.text_at(font, 1, 1, False, True) |
36 | 33 | console.clear_to_eol() |
| 34 | + console.text_at("{}, {}".format(console.columns, console.rows), |
| 35 | + column=2, row=4, reset_console=False, inverse=False) |
| 36 | + print("{}, {}, \"{}\"".format(console.columns, console.rows, font), file=stderr) |
| 37 | + fonts.append((console.columns, console.rows, font)) |
37 | 38 |
|
38 | | - # now, read the console response of the actual cursor position, in the form of esc[rr;ccR |
39 | | - # requires pressing the center button on the EV3 for each read |
40 | | - dims = '' |
41 | | - while True: |
42 | | - ch = stdin.read(1) |
43 | | - if ch == '\x1b' or ch == '[' or ch == '\r' or ch == '\n': |
44 | | - continue |
45 | | - if ch == 'R': |
46 | | - break |
47 | | - dims += str(ch) |
48 | | - (rows, cols) = dims.split(";") |
49 | | - print("({}, {}, \"{}\"),".format(rows, cols, font), file=stderr) |
50 | | - sleep(.5) |
51 | | - |
52 | | - |
53 | | -def show_fonts(): |
54 | | - """ |
55 | | - Iterate over the known Latin "1 & 5" fonts and display each on the EV3 LCD console. |
56 | | - Note: `Terminus` fonts are "thinner"; `TerminusBold` and `VGA` offer more contrast on the LCD console |
57 | | - and are thus more readable; the `TomThumb` font is waaaaay too small to read! |
58 | | - """ |
59 | | - # Create a list of tuples with calulated rows, columns, font filename |
60 | | - fonts = [ |
61 | | - (4, 11, "Lat15-Terminus32x16.psf.gz"), |
62 | | - (4, 11, "Lat15-TerminusBold32x16.psf.gz"), |
63 | | - (4, 11, "Lat15-VGA28x16.psf.gz"), |
64 | | - (4, 11, "Lat15-VGA32x16.psf.gz"), |
65 | | - (4, 12, "Lat15-Terminus28x14.psf.gz"), |
66 | | - (4, 12, "Lat15-TerminusBold28x14.psf.gz"), |
67 | | - (5, 14, "Lat15-Terminus24x12.psf.gz"), |
68 | | - (5, 14, "Lat15-TerminusBold24x12.psf.gz"), |
69 | | - (5, 16, "Lat15-Terminus22x11.psf.gz"), |
70 | | - (5, 16, "Lat15-TerminusBold22x11.psf.gz"), |
71 | | - (6, 17, "Lat15-Terminus20x10.psf.gz"), |
72 | | - (6, 17, "Lat15-TerminusBold20x10.psf.gz"), |
73 | | - (7, 22, "Lat15-Fixed18.psf.gz"), |
74 | | - (8, 22, "Lat15-Fixed15.psf.gz"), |
75 | | - (8, 22, "Lat15-Fixed16.psf.gz"), |
76 | | - (8, 22, "Lat15-Terminus16.psf.gz"), |
77 | | - (8, 22, "Lat15-TerminusBold16.psf.gz"), |
78 | | - (8, 22, "Lat15-TerminusBoldVGA16.psf.gz"), |
79 | | - (8, 22, "Lat15-VGA16.psf.gz"), |
80 | | - (9, 22, "Lat15-Fixed13.psf.gz"), |
81 | | - (9, 22, "Lat15-Fixed14.psf.gz"), |
82 | | - (9, 22, "Lat15-Terminus14.psf.gz"), |
83 | | - (9, 22, "Lat15-TerminusBold14.psf.gz"), |
84 | | - (9, 22, "Lat15-TerminusBoldVGA14.psf.gz"), |
85 | | - (9, 22, "Lat15-VGA14.psf.gz"), |
86 | | - (10, 29, "Lat15-Terminus12x6.psf.gz"), |
87 | | - (16, 22, "Lat15-VGA8.psf.gz"), |
88 | | - (21, 44, "Lat15-TomThumb4x6.psf.gz") |
89 | | - ] |
| 39 | + fonts.sort(key=lambda f: (f[0], f[1], f[2])) |
90 | 40 |
|
91 | 41 | # Paint the screen full of numbers that represent the column number, reversing the even rows |
92 | | - console = Console() |
93 | | - for rows, cols, font in fonts: |
94 | | - print(rows, cols, font, file=stderr) |
| 42 | + for cols, rows, font in fonts: |
| 43 | + print(cols, rows, font, file=stderr) |
95 | 44 | console.set_font(font, True) |
96 | 45 | for row in range(1, rows+1): |
97 | 46 | for col in range(1, cols+1): |
98 | 47 | console.text_at("{}".format(col % 10), col, row, False, (row % 2 == 0)) |
99 | 48 | console.text_at(font.split(".")[0], 1, 1, False, True) |
100 | 49 | console.clear_to_eol() |
101 | | - sleep(.5) |
102 | | - |
103 | | - |
104 | | -# Uncomment the calc_fonts() call to iterate through each system font |
105 | | -# and use ANSI codes to find the max row/column the screen will accommodate for |
106 | | -# each font. Remember to press the center EV3 button for each font. |
107 | | -# Also, you may want to adjust the `startswith` filter to show other codesets. |
108 | | -# calc_fonts() |
109 | | - |
110 | 50 |
|
111 | | -# show the fonts |
| 51 | +# Show the fonts; you may want to adjust the `startswith` filter to show other codesets. |
112 | 52 | show_fonts() |
113 | 53 |
|
114 | 54 | sleep(5) |
0 commit comments