55import board
66import displayio
77import terminalio
8- import adafruit_imageload
98from adafruit_display_shapes .rect import Rect
109from adafruit_display_text import label
1110from adafruit_pyportal import PyPortal
1716# Set the backlight brightness, 0.0 (off) to 1.0 (max brightness)
1817BACKLIGHT_BRIGHTNESS = 0.5
1918# Location text and images
20- LOCATION_IMAGES = { 'home' : 'images/home.bmp' , 'work' : 'images/office.bmp' , 'gym' : 'images/workout.bmp' , 'commute' : 'images/subway.bmp' }
19+ LOCATION_IMAGES = { 'home' : 'images/home.bmp' , 'work' : 'images/office.bmp' ,
20+ 'gym' : 'images/workout.bmp' , 'commute' : 'images/subway.bmp' }
2121
2222# Create the PyPortal object
2323pyportal = PyPortal (status_neopixel = board .NEOPIXEL )
@@ -72,16 +72,10 @@ def set_image(group, filename):
7272 if group :
7373 group .pop ()
7474
75- if not filename :
76- return # we're done, no icon desired
77- try :
78- if image_file :
79- image_file .close
80- except NameError :
81- pass
8275 image_file = open (filename , "rb" )
8376 image = displayio .OnDiskBitmap (image_file )
84- image_sprite = displayio .TileGrid (image , pixel_shader = getattr (image , 'pixel_shader' , displayio .ColorConverter ()))
77+ image_sprite = displayio .TileGrid (image ,
78+ pixel_shader = getattr (image , 'pixel_shader' , displayio .ColorConverter ()))
8579 image_sprite .x = IMAGE_SPRITE_X
8680 image_sprite .y = IMAGE_SPRITE_Y
8781 group .append (image_sprite )
@@ -114,9 +108,9 @@ def set_image(group, filename):
114108 text_area_location .text = f"Error: Unknown Value!"
115109 # Show the refreshed group
116110 display .root_group = group
117- except Exception as e :
118- print (f "Failed to fetch location data: { e } " )
111+ except RuntimeError as e :
112+ print ("Failed to fetch location data: " , e )
119113
120114 # Wait 5 minutes (300 seconds) before fetching the location feed again
121115 print ("Sleeping, fetching the location again in 5 minutes!" )
122- time .sleep (SLEEP_DELAY_SECONDS * 60 )
116+ time .sleep (SLEEP_DELAY_SECONDS * 60 )
0 commit comments