@@ -16,6 +16,7 @@ class ImageView(Activity):
1616image_nr = None
1717image_timer = None
1818fullscreen = False
19+ stopping = False
1920
2021# Widgets
2122image = None
@@ -62,6 +63,7 @@ def onCreate(self):
6263self .setContentView (screen )
6364
6465def onResume (self ,screen ):
66+ self .stopping = False
6567self .images .clear ()
6668for item in os .listdir (self .imagedir ):
6769print (item )
@@ -80,6 +82,8 @@ def onResume(self, screen):
8082#self.image_timer = lv.timer_create(self.show_next_image, 1000, None)
8183
8284def onStop (self ,screen ):
85+ print ("ImageView stopping" )
86+ self .stopping = True
8387if self .image_timer :
8488print ("ImageView: deleting image_timer" )
8589self .image_timer .delete ()
@@ -145,28 +149,34 @@ def start_fullscreen(self):
145149self .unfocus ()# focus on the invisible center button, not previous or next
146150
147151def show_prev_image_if_fullscreen (self ,event = None ):
152+ if self .stopping :# closing the window results in a focus shift, which can trigger the next action in fullscreen
153+ return
148154if self .fullscreen :
149155self .unfocus ()
150156self .show_prev_image ()
151157
152158def show_next_image_if_fullscreen (self ,event = None ):
159+ if self .stopping :# closing the window results in a focus shift, which can trigger the next action in fullscreen
160+ return
153161if self .fullscreen :
154162self .unfocus ()
155163self .show_next_image ()
156164
157165def unfocus (self ):
158166group = lv .group_get_default ()
167+ if not group :
168+ return
159169print ("got focus group" )
160170# group.focus_obj(self.play_button) would be better but appears missing?!
161- b = group .get_focused ()
171+ focused = group .get_focused ()
162172print ("got focus button" )
163- #b .remove_state(lv.STATE.FOCUSED) # this doesn't seem to work to remove focus
164- if b :
173+ #focused .remove_state(lv.STATE.FOCUSED) # this doesn't seem to work to remove focus
174+ if focused :
165175print ("checking which button is focused" )
166- if b == self .next_button :
176+ if focused == self .next_button :
167177print ("next is focused" )
168178group .focus_prev ()
169- elif b == self .prev_button :
179+ elif focused == self .prev_button :
170180print ("prev is focused" )
171181group .focus_next ()
172182else :
@@ -213,7 +223,11 @@ def show_image(self, name):
213223image_data = f .read ()
214224print (f"loaded{ len (image_data )} bytes from .raw file" )
215225f .close ()
216- width ,height ,color_format = self .extract_dimensions_and_format (name )
226+ try :
227+ width ,height ,color_format = self .extract_dimensions_and_format (name )
228+ except ValueError as e :
229+ print (f"Warning: could not extract dimensions and format from raw image:{ e } " )
230+ return
217231print (f"Raw image has width:{ width } , Height:{ height } , Color Format:{ color_format } " )
218232stride = width * 2
219233cf = lv .COLOR_FORMAT .RGB565