@@ -16,6 +16,7 @@ class ImageView(Activity):
1616 image_nr = None
1717 image_timer = None
1818 fullscreen = False
19+ stopping = False
1920
2021 # Widgets
2122 image = None
@@ -62,6 +63,7 @@ def onCreate(self):
6263 self .setContentView (screen )
6364
6465 def onResume (self , screen ):
66+ self .stopping = False
6567 self .images .clear ()
6668 for item in os .listdir (self .imagedir ):
6769 print (item )
@@ -80,6 +82,8 @@ def onResume(self, screen):
8082 #self.image_timer = lv.timer_create(self.show_next_image, 1000, None)
8183
8284 def onStop (self , screen ):
85+ print ("ImageView stopping" )
86+ self .stopping = True
8387 if self .image_timer :
8488 print ("ImageView: deleting image_timer" )
8589 self .image_timer .delete ()
@@ -145,28 +149,34 @@ def start_fullscreen(self):
145149 self .unfocus () # focus on the invisible center button, not previous or next
146150
147151 def 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
148154 if self .fullscreen :
149155 self .unfocus ()
150156 self .show_prev_image ()
151157
152158 def 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
153161 if self .fullscreen :
154162 self .unfocus ()
155163 self .show_next_image ()
156164
157165 def unfocus (self ):
158166 group = lv .group_get_default ()
167+ if not group :
168+ return
159169 print ("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 ()
162172 print ("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 :
165175 print ("checking which button is focused" )
166- if b == self .next_button :
176+ if focused == self .next_button :
167177 print ("next is focused" )
168178 group .focus_prev ()
169- elif b == self .prev_button :
179+ elif focused == self .prev_button :
170180 print ("prev is focused" )
171181 group .focus_next ()
172182 else :
@@ -213,7 +223,11 @@ def show_image(self, name):
213223 image_data = f .read ()
214224 print (f"loaded { len (image_data )} bytes from .raw file" )
215225 f .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
217231 print (f"Raw image has width: { width } , Height: { height } , Color Format: { color_format } " )
218232 stride = width * 2
219233 cf = lv .COLOR_FORMAT .RGB565
0 commit comments