1010from adafruit_bitmap_font import bitmap_font
1111
1212from adafruit_display_text import bitmap_label
13-
1413from adafruit_display_text import label
1514
1615# pylint: disable=no-member
1716
18- # Setup the SPI display
17+
1918##########
2019# Use this Boolean variables to select which font style to use
2120##########
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
2323# Set False to use a BDF loaded font, see "fontFiles" below
2424##########
2525
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+
2636# Set scaling factor for display text
2737my_scale = 1
2838
2939# Setup the SPI display
30-
3140if "DISPLAY" not in dir (board ):
3241 # Setup the LCD display with driver
3342 # You may need to change this to match the display driver for the chipset
8089print ("Display is started" )
8190
8291
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-
10792
10893preload_glyphs = (
10994 True # set this to True if you want to preload the font glyphs into memory
11095)
11196# preloading the glyphs will help speed up the rendering of text but will use more RAM
11297
113- if preload_glyphs :
98+ if preload_glyphs and not use_builtinfont :
11499
115100 # identify the glyphs to load into memory -> increases rendering speed
116101 glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:?! "
117102
118103 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 )
122105
123106 print ("Glyphs are loaded." )
124107
125-
126108print ("Fonts completed loading." )
127109
128110# create group
129111
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"
135114
136115#####
137116# Create the "bitmap_label.py" versions of the text labels.
140119bitmap_label_start = gc .mem_free ()
141120
142121bmap_label1 = bitmap_label .Label (
143- font = fontList [ 0 ] ,
144- text = my_string1 ,
122+ font = fontToUse ,
123+ text = short_string ,
145124 color = 0xFFFFFF ,
146- max_glyphs = len (my_string1 ),
125+ max_glyphs = len (short_string ),
147126 background_color = 0xFF0000 ,
148127 padding_bottom = 0 ,
149128 padding_left = 0 ,
150129 padding_right = 0 ,
151130 padding_top = 0 ,
152131 background_tight = True ,
153- x = 10 ,
154- y = 60 ,
155132 line_spacing = 1.25 ,
156133 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 ),
159136)
160137label2_padding = 10
161138bmap_label2 = bitmap_label .Label (
162- font = fontList [ 0 ] ,
163- text = my_string23 ,
139+ font = fontToUse ,
140+ text = long_string ,
164141 color = 0x000000 ,
165- max_glyphs = len (my_string23 ),
142+ max_glyphs = len (long_string ),
166143 background_color = 0xFFFF00 ,
167144 padding_bottom = label2_padding ,
168145 padding_left = 0 ,
169146 padding_right = 0 ,
170147 padding_top = label2_padding ,
171148 background_tight = False ,
172- x = 10 ,
173- y = 100 ,
174149 line_spacing = 1.25 ,
175150 scale = my_scale ,
176- anchor_point = (0 , 0 ),
177- anchored_position = (200 , 150 ),
151+ anchor_point = (0.0 , 0 ),
152+ anchored_position = (10 , 120 ),
178153)
179154
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-
235155gc .collect ()
236156bitmap_label_end = gc .mem_free ()
237157
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
239159bmap_group .append (bmap_label1 )
240160bmap_group .append (bmap_label2 )
241- bmap_group .append (bmap_label3 )
242- bmap_group .append (bmap_label4 )
243- bmap_group .append (bmap_label5 )
244161
245162
246163#####
250167label_start = gc .mem_free ()
251168
252169label1 = label .Label (
253- font = fontList [ 0 ] ,
254- text = my_string1 ,
170+ font = fontToUse ,
171+ text = short_string ,
255172 color = 0xFFFFFF ,
256- max_glyphs = len (my_string1 ),
173+ max_glyphs = len (short_string ),
257174 background_color = 0xFF0000 ,
258175 padding_bottom = 0 ,
259176 padding_left = 0 ,
260177 padding_right = 0 ,
261178 padding_top = 0 ,
262179 background_tight = True ,
263- x = 10 ,
264- y = 60 ,
265180 line_spacing = 1.25 ,
266181 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 ),
269184)
270185
271186label2 = label .Label (
272- font = fontList [ 0 ] ,
273- text = my_string23 ,
187+ font = fontToUse ,
188+ text = long_string ,
274189 color = 0x000000 ,
275- max_glyphs = len (my_string23 ),
190+ max_glyphs = len (long_string ),
276191 background_color = 0xFFFF00 ,
277192 padding_bottom = label2_padding ,
278193 padding_left = 0 ,
279194 padding_right = 0 ,
280195 padding_top = label2_padding ,
281196 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 ,
339197 line_spacing = 1.25 ,
340- anchor_point = (0 , 0.5 ),
341- anchored_position = (50 , 200 ),
342198 scale = my_scale ,
199+ anchor_point = (1.0 , 0 ),
200+ anchored_position = (display .width - 10 , 120 ),
343201)
344202
345203gc .collect ()
346204label_end = gc .mem_free ()
347205
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
349207label_group .append (label1 )
350208label_group .append (label2 )
351- label_group .append (label3 )
352- label_group .append (label4 )
353- label_group .append (label5 )
354209
355210
356211print ("***" )
357212
213+ main_group = displayio .Group ()
214+ main_group .append (label_group )
215+ main_group .append (bmap_group )
216+
358217display .auto_refresh = True
359218
219+ display .show (main_group )
360220while 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