@@ -79,12 +79,12 @@ def __init__(
79
79
):
80
80
81
81
self ._debug = debug
82
- self ._graphics = Graphics (
82
+ self .graphics = Graphics (
83
83
default_bg = default_bg , bit_depth = bit_depth , width = 64 , height = 32 , debug = debug
84
84
)
85
- self .display = self ._graphics .display
85
+ self .display = self .graphics .display
86
86
87
- self ._network = Network (
87
+ self .network = Network (
88
88
status_neopixel = status_neopixel ,
89
89
esp = esp ,
90
90
external_spi = external_spi ,
@@ -100,11 +100,11 @@ def __init__(
100
100
101
101
self ._regexp_path = regexp_path
102
102
103
- self .splash = self ._graphics .splash
103
+ self .splash = self .graphics .splash
104
104
105
105
# Add any JSON translators
106
106
if json_transform :
107
- self ._network . ad . json_transform (json_transform )
107
+ self .network . add_json_transform (json_transform )
108
108
109
109
self ._text = []
110
110
self ._text_color = []
@@ -166,15 +166,31 @@ def add_text(
166
166
if self ._debug :
167
167
print ("Init text area" )
168
168
self ._text .append (None )
169
- self ._text_color .append (text_color )
169
+ self ._text_color .append (self . html_color_convert ( text_color ) )
170
170
self ._text_position .append (text_position )
171
171
self ._text_wrap .append (text_wrap )
172
172
self ._text_maxlen .append (text_maxlen )
173
173
self ._text_transform .append (text_transform )
174
174
self ._text_scrolling .append (scrolling )
175
175
176
+ if scrolling and self ._scrolling_index is None : # Not initialized yet
177
+ self ._scrolling_index = self ._get_next_scrollable_text_index ()
178
+
176
179
# pylint: enable=too-many-arguments
177
180
181
+ @staticmethod
182
+ def html_color_convert (color ):
183
+ """Convert an HTML color code to an integer
184
+
185
+ :param color: The color value to be converted
186
+
187
+ """
188
+ if isinstance (color , str ):
189
+ if color [0 ] == "#" :
190
+ color = color .lstrip ("#" )
191
+ return int (color , 16 )
192
+ return color # Return unconverted
193
+
178
194
def set_headers (self , headers ):
179
195
"""Set the headers used by fetch().
180
196
@@ -189,7 +205,7 @@ def set_background(self, file_or_color, position=None):
189
205
:param file_or_color: The filename of the chosen background image, or a hex color.
190
206
191
207
"""
192
- self ._graphics .set_background (file_or_color , position )
208
+ self .graphics .set_background (file_or_color , position )
193
209
194
210
def preload_font (self , glyphs = None ):
195
211
# pylint: disable=line-too-long
@@ -205,6 +221,18 @@ def preload_font(self, glyphs=None):
205
221
if self ._text_font and self ._text_font is not terminalio .FONT :
206
222
self ._text_font .load_glyphs (glyphs )
207
223
224
+ def set_text_color (self , color , index = 0 ):
225
+ """Update the text color, with indexing into our list of text boxes.
226
+
227
+ :param int color: The color value to be used
228
+ :param index: Defaults to 0.
229
+
230
+ """
231
+ if self ._text [index ]:
232
+ color = self .html_color_convert (color )
233
+ self ._text_color [index ] = color
234
+ self ._text [index ].color = color
235
+
208
236
def set_text (self , val , index = 0 ):
209
237
"""Display text, with indexing into our list of text boxes.
210
238
@@ -248,7 +276,7 @@ def set_text(self, val, index=0):
248
276
249
277
def get_local_time (self , location = None ):
250
278
"""Accessor function for get_local_time()"""
251
- return self ._network .get_local_time (location = location )
279
+ return self .network .get_local_time (location = location )
252
280
253
281
def _get_next_scrollable_text_index (self ):
254
282
index = self ._scrolling_index
@@ -272,7 +300,7 @@ def push_to_io(self, feed_key, data):
272
300
273
301
"""
274
302
275
- self ._network .push_to_io (feed_key , data )
303
+ self .network .push_to_io (feed_key , data )
276
304
277
305
def get_io_data (self , feed_key ):
278
306
"""Return all values from the Adafruit IO Feed Data that matches the feed key
@@ -281,7 +309,7 @@ def get_io_data(self, feed_key):
281
309
282
310
"""
283
311
284
- return self ._network .get_io_data (feed_key )
312
+ return self .network .get_io_data (feed_key )
285
313
286
314
def get_io_feed (self , feed_key , detailed = False ):
287
315
"""Return the Adafruit IO Feed that matches the feed key
@@ -290,15 +318,15 @@ def get_io_feed(self, feed_key, detailed=False):
290
318
:param bool detailed: Whether to return additional detailed information
291
319
292
320
"""
293
- return self ._network .get_io_feed (feed_key , detailed )
321
+ return self .network .get_io_feed (feed_key , detailed )
294
322
295
323
def get_io_group (self , group_key ):
296
324
"""Return the Adafruit IO Group that matches the group key
297
325
298
326
:param str group_key: Name of group key to match.
299
327
300
328
"""
301
- return self ._network .get_io_group (group_key )
329
+ return self .network .get_io_group (group_key )
302
330
303
331
def scroll (self ):
304
332
"""Scroll any text that needs scrolling by a single frame. We also
@@ -307,32 +335,26 @@ def scroll(self):
307
335
"""
308
336
309
337
if self ._scrolling_index is None : # Not initialized yet
310
- next_index = self ._get_next_scrollable_text_index ()
311
- if next_index is None :
312
- return
313
- self ._scrolling_index = next_index
338
+ return
314
339
315
340
self ._text [self ._scrolling_index ].x = self ._text [self ._scrolling_index ].x - 1
316
341
line_width = self ._text [self ._scrolling_index ].bounding_box [2 ]
317
342
if self ._text [self ._scrolling_index ].x < - line_width :
318
343
# Find the next line
319
344
self ._scrolling_index = self ._get_next_scrollable_text_index ()
320
- self ._text [self ._scrolling_index ].x = self ._graphics .display .width
345
+ self ._text [self ._scrolling_index ].x = self .graphics .display .width
321
346
322
347
def scroll_text (self , frame_delay = 0.02 ):
323
348
"""Scroll the entire text all the way across. We also
324
349
we want to queue up multiple lines one after another. To get
325
350
simultaneous lines, we can simply use a line break.
326
351
"""
327
352
if self ._scrolling_index is None : # Not initialized yet
328
- next_index = self ._get_next_scrollable_text_index ()
329
- if next_index is None :
330
- return
331
- self ._scrolling_index = next_index
353
+ return
332
354
333
- self ._text [self ._scrolling_index ].x = self ._graphics .display .width
355
+ self ._text [self ._scrolling_index ].x = self .graphics .display .width
334
356
line_width = self ._text [self ._scrolling_index ].bounding_box [2 ]
335
- for _ in range (self ._graphics .display .width + line_width + 1 ):
357
+ for _ in range (self .graphics .display .width + line_width + 1 ):
336
358
self .scroll ()
337
359
sleep (frame_delay )
338
360
@@ -345,7 +367,7 @@ def fetch(self, refresh_url=None, timeout=10):
345
367
self ._url = refresh_url
346
368
values = []
347
369
348
- values = self ._network .fetch_data (
370
+ values = self .network .fetch_data (
349
371
self ._url ,
350
372
headers = self ._headers ,
351
373
json_path = self ._json_path ,
@@ -412,10 +434,10 @@ def url(self):
412
434
@url .setter
413
435
def url (self , value ):
414
436
self ._url = value
415
- if value and not self ._network .uselocal :
416
- self ._network .connect ()
437
+ if value and not self .network .uselocal :
438
+ self .network .connect ()
417
439
if self ._debug :
418
- print ("My IP address is" , self ._network .ip_address )
440
+ print ("My IP address is" , self .network .ip_address )
419
441
420
442
@property
421
443
def json_path (self ):
0 commit comments