10
10
from adafruit_bitmap_font import bitmap_font
11
11
12
12
from adafruit_display_text import bitmap_label
13
-
14
13
from adafruit_display_text import label
15
14
16
15
# pylint: disable=no-member
17
16
18
- # Setup the SPI display
17
+
19
18
##########
20
19
# Use this Boolean variables to select which font style to use
21
20
##########
22
- use_builtinfont = True # Set True to use the terminalio.FONT BuiltinFont,
21
+ use_builtinfont = False # Set True to use the terminalio.FONT BuiltinFont,
22
+ fontToUse = terminalio .FONT
23
23
# Set False to use a BDF loaded font, see "fontFiles" below
24
24
##########
25
25
26
+ if not use_builtinfont :
27
+ # load the fonts
28
+ print ("loading font..." )
29
+
30
+ fontList = []
31
+
32
+ # Load some proportional fonts
33
+ fontFile = "fonts/Helvetica-Bold-16.bdf"
34
+ fontToUse = bitmap_font .load_font (fontFile )
35
+
26
36
# Set scaling factor for display text
27
37
my_scale = 1
28
38
29
39
# Setup the SPI display
30
-
31
40
if "DISPLAY" not in dir (board ):
32
41
# Setup the LCD display with driver
33
42
# You may need to change this to match the display driver for the chipset
80
89
print ("Display is started" )
81
90
82
91
83
- # load all the fonts
84
- print ("loading fonts..." )
85
-
86
- fontList = []
87
-
88
- # Load some proportional fonts
89
- fontFiles = [
90
- "fonts/Helvetica-Bold-16.bdf" ,
91
- # 'fonts/BitstreamVeraSans-Roman-24.bdf', # Header2
92
- # 'fonts/BitstreamVeraSans-Roman-16.bdf', # mainText
93
- ]
94
-
95
-
96
- for i , fontFile in enumerate (fontFiles ):
97
-
98
- if use_builtinfont :
99
- thisFont = (
100
- terminalio .FONT
101
- ) # comment this out to switch back to BDF loaded fonts
102
- else :
103
- thisFont = bitmap_font .load_font (fontFile )
104
-
105
- fontList .append (thisFont )
106
-
107
92
108
93
preload_glyphs = (
109
94
True # set this to True if you want to preload the font glyphs into memory
110
95
)
111
96
# preloading the glyphs will help speed up the rendering of text but will use more RAM
112
97
113
- if preload_glyphs :
98
+ if preload_glyphs and not use_builtinfont :
114
99
115
100
# identify the glyphs to load into memory -> increases rendering speed
116
101
glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:?! "
117
102
118
103
print ("loading glyphs..." )
119
- for font in fontList :
120
- if font is not terminalio .FONT :
121
- font .load_glyphs (glyphs )
104
+ fontToUse .load_glyphs (glyphs )
122
105
123
106
print ("Glyphs are loaded." )
124
107
125
-
126
108
print ("Fonts completed loading." )
127
109
128
110
# create group
129
111
130
- my_string1 = "This is a label.py and\n bitmap_label.py comparison."
131
- my_string23 = "none"
132
- my_string_bitmap_label = "bitmap_label"
133
- my_string_label = "label bitmap_label"
134
-
112
+ long_string = "The purple snake\n brings python fun\n to everyone."
113
+ short_string = "Hello World"
135
114
136
115
#####
137
116
# Create the "bitmap_label.py" versions of the text labels.
140
119
bitmap_label_start = gc .mem_free ()
141
120
142
121
bmap_label1 = bitmap_label .Label (
143
- font = fontList [ 0 ] ,
144
- text = my_string1 ,
122
+ font = fontToUse ,
123
+ text = short_string ,
145
124
color = 0xFFFFFF ,
146
- max_glyphs = len (my_string1 ),
125
+ max_glyphs = len (short_string ),
147
126
background_color = 0xFF0000 ,
148
127
padding_bottom = 0 ,
149
128
padding_left = 0 ,
150
129
padding_right = 0 ,
151
130
padding_top = 0 ,
152
131
background_tight = True ,
153
- x = 10 ,
154
- y = 60 ,
155
132
line_spacing = 1.25 ,
156
133
scale = my_scale ,
157
- anchor_point = (0.5 , 0 ),
158
- anchored_position = (160 , 50 ),
134
+ anchor_point = (0.0 , 0 ),
135
+ anchored_position = (10 , 60 ),
159
136
)
160
137
label2_padding = 10
161
138
bmap_label2 = bitmap_label .Label (
162
- font = fontList [ 0 ] ,
163
- text = my_string23 ,
139
+ font = fontToUse ,
140
+ text = long_string ,
164
141
color = 0x000000 ,
165
- max_glyphs = len (my_string23 ),
142
+ max_glyphs = len (long_string ),
166
143
background_color = 0xFFFF00 ,
167
144
padding_bottom = label2_padding ,
168
145
padding_left = 0 ,
169
146
padding_right = 0 ,
170
147
padding_top = label2_padding ,
171
148
background_tight = False ,
172
- x = 10 ,
173
- y = 100 ,
174
149
line_spacing = 1.25 ,
175
150
scale = my_scale ,
176
- anchor_point = (0 , 0 ),
177
- anchored_position = (200 , 150 ),
151
+ anchor_point = (0.0 , 0 ),
152
+ anchored_position = (10 , 120 ),
178
153
)
179
154
180
- bmap_label3 = bitmap_label .Label (
181
- font = fontList [0 ],
182
- text = my_string23 ,
183
- color = 0x000000 ,
184
- max_glyphs = len (my_string23 ),
185
- background_color = 0xFFFF00 ,
186
- padding_bottom = 0 ,
187
- padding_left = 0 ,
188
- padding_right = 0 ,
189
- padding_top = 0 ,
190
- background_tight = True ,
191
- x = 10 ,
192
- y = 150 ,
193
- line_spacing = 1.25 ,
194
- scale = my_scale ,
195
- )
196
-
197
- bmap_label4 = bitmap_label .Label (
198
- font = fontList [0 ],
199
- text = my_string_label ,
200
- color = 0x000000 ,
201
- max_glyphs = len (my_string_label ),
202
- background_color = 0xFFFF00 ,
203
- padding_bottom = 0 ,
204
- padding_left = 0 ,
205
- padding_right = 0 ,
206
- padding_top = 0 ,
207
- background_tight = False ,
208
- x = 10 ,
209
- y = 200 ,
210
- line_spacing = 1.25 ,
211
- scale = my_scale ,
212
- )
213
-
214
- my_string5 = "bitmap_label -->"
215
- bmap_label5 = bitmap_label .Label (
216
- font = fontList [0 ],
217
- text = my_string5 ,
218
- color = 0xFFFFFF ,
219
- max_glyphs = len (my_string5 ),
220
- background_color = 0x000000 ,
221
- padding_bottom = 0 ,
222
- padding_left = 0 ,
223
- padding_right = 0 ,
224
- padding_top = 0 ,
225
- background_tight = True ,
226
- x = 10 ,
227
- y = 200 ,
228
- line_spacing = 1.25 ,
229
- anchor_point = (1 , 0.5 ),
230
- anchored_position = (200 , 200 ),
231
- scale = my_scale ,
232
- )
233
-
234
-
235
155
gc .collect ()
236
156
bitmap_label_end = gc .mem_free ()
237
157
238
- bmap_group = displayio .Group (max_size = 5 ) # Create a group for displaying
158
+ bmap_group = displayio .Group (max_size = 4 ) # Create a group for displaying
239
159
bmap_group .append (bmap_label1 )
240
160
bmap_group .append (bmap_label2 )
241
- bmap_group .append (bmap_label3 )
242
- bmap_group .append (bmap_label4 )
243
- bmap_group .append (bmap_label5 )
244
161
245
162
246
163
#####
250
167
label_start = gc .mem_free ()
251
168
252
169
label1 = label .Label (
253
- font = fontList [ 0 ] ,
254
- text = my_string1 ,
170
+ font = fontToUse ,
171
+ text = short_string ,
255
172
color = 0xFFFFFF ,
256
- max_glyphs = len (my_string1 ),
173
+ max_glyphs = len (short_string ),
257
174
background_color = 0xFF0000 ,
258
175
padding_bottom = 0 ,
259
176
padding_left = 0 ,
260
177
padding_right = 0 ,
261
178
padding_top = 0 ,
262
179
background_tight = True ,
263
- x = 10 ,
264
- y = 60 ,
265
180
line_spacing = 1.25 ,
266
181
scale = my_scale ,
267
- anchor_point = (0.5 , 0 ),
268
- anchored_position = (160 , 50 ),
182
+ anchor_point = (1.0 , 0 ),
183
+ anchored_position = (display . width - 10 , 60 ),
269
184
)
270
185
271
186
label2 = label .Label (
272
- font = fontList [ 0 ] ,
273
- text = my_string23 ,
187
+ font = fontToUse ,
188
+ text = long_string ,
274
189
color = 0x000000 ,
275
- max_glyphs = len (my_string23 ),
190
+ max_glyphs = len (long_string ),
276
191
background_color = 0xFFFF00 ,
277
192
padding_bottom = label2_padding ,
278
193
padding_left = 0 ,
279
194
padding_right = 0 ,
280
195
padding_top = label2_padding ,
281
196
background_tight = False ,
282
- x = 10 ,
283
- y = 100 ,
284
- line_spacing = 1.25 ,
285
- scale = my_scale ,
286
- anchor_point = (0 , 0 ),
287
- anchored_position = (200 , 150 ),
288
- )
289
-
290
- label3 = label .Label (
291
- font = fontList [0 ],
292
- text = my_string23 ,
293
- color = 0x000000 ,
294
- max_glyphs = len (my_string23 ),
295
- background_color = 0xFFFF00 ,
296
- padding_bottom = 0 ,
297
- padding_left = 0 ,
298
- padding_right = 0 ,
299
- padding_top = 0 ,
300
- background_tight = True ,
301
- x = 10 ,
302
- y = 150 ,
303
- line_spacing = 1.25 ,
304
- scale = my_scale ,
305
- )
306
-
307
- label4 = label .Label (
308
- font = fontList [0 ],
309
- text = my_string_label ,
310
- color = 0x000000 ,
311
- max_glyphs = len (my_string_label ),
312
- background_color = 0xFFFF00 ,
313
- padding_bottom = 0 ,
314
- padding_left = 0 ,
315
- padding_right = 0 ,
316
- padding_top = 0 ,
317
- background_tight = True ,
318
- x = 10 ,
319
- y = 200 ,
320
- line_spacing = 1.25 ,
321
- scale = my_scale ,
322
- )
323
-
324
-
325
- my_string5 = "<-- label"
326
- label5 = label .Label (
327
- font = fontList [0 ],
328
- text = my_string5 ,
329
- color = 0xFFFFFF ,
330
- max_glyphs = len (my_string5 ),
331
- background_color = 0x000000 ,
332
- padding_bottom = 0 ,
333
- padding_left = 0 ,
334
- padding_right = 0 ,
335
- padding_top = 0 ,
336
- background_tight = False ,
337
- x = 10 ,
338
- y = 200 ,
339
197
line_spacing = 1.25 ,
340
- anchor_point = (0 , 0.5 ),
341
- anchored_position = (50 , 200 ),
342
198
scale = my_scale ,
199
+ anchor_point = (1.0 , 0 ),
200
+ anchored_position = (display .width - 10 , 120 ),
343
201
)
344
202
345
203
gc .collect ()
346
204
label_end = gc .mem_free ()
347
205
348
- label_group = displayio .Group (max_size = 5 ) # Create a group for displaying
206
+ label_group = displayio .Group (max_size = 4 ) # Create a group for displaying
349
207
label_group .append (label1 )
350
208
label_group .append (label2 )
351
- label_group .append (label3 )
352
- label_group .append (label4 )
353
- label_group .append (label5 )
354
209
355
210
356
211
print ("***" )
357
212
213
+ main_group = displayio .Group ()
214
+ main_group .append (label_group )
215
+ main_group .append (bmap_group )
216
+
358
217
display .auto_refresh = True
359
218
219
+ display .show (main_group )
360
220
while True :
361
- print ("bitmap_label" )
362
- time .sleep (0.1 )
363
- display .show (bmap_group )
364
-
365
- time .sleep (2 )
366
-
367
- print ("label" )
368
- time .sleep (0.1 )
369
- display .show (label_group )
370
- time .sleep (2 )
221
+ pass
0 commit comments