ImageView app: improve error handling

This commit is contained in:
Thomas Farstrike
2025-11-21 18:45:10 +01:00
parent 9abada9d75
commit 9f98c48bd1
2 changed files with 17 additions and 12 deletions
@@ -3,10 +3,10 @@
"publisher": "MicroPythonOS",
"short_description": "Image Viewer",
"long_description": "Opens and shows images on the display.",
"icon_url": "https://apps.micropythonos.com/apps/com.micropythonos.imageview/icons/com.micropythonos.imageview_0.0.3_64x64.png",
"download_url": "https://apps.micropythonos.com/apps/com.micropythonos.imageview/mpks/com.micropythonos.imageview_0.0.3.mpk",
"icon_url": "https://apps.micropythonos.com/apps/com.micropythonos.imageview/icons/com.micropythonos.imageview_0.0.4_64x64.png",
"download_url": "https://apps.micropythonos.com/apps/com.micropythonos.imageview/mpks/com.micropythonos.imageview_0.0.4.mpk",
"fullname": "com.micropythonos.imageview",
"version": "0.0.3",
"version": "0.0.4",
"category": "graphics",
"activities": [
{
@@ -61,10 +61,12 @@ class ImageView(Activity):
def onResume(self, screen):
self.stopping = False
self.images.clear()
for item in os.listdir(self.imagedir):
print(item)
lowercase = item.lower()
if lowercase.endswith(".jpg") or lowercase.endswith(".jpeg") or lowercase.endswith(".png") or lowercase.endswith(".raw") or lowercase.endswith(".gif"):
try:
for item in os.listdir(self.imagedir):
print(item)
lowercase = item.lower()
if not (lowercase.endswith(".jpg") or lowercase.endswith(".jpeg") or lowercase.endswith(".png") or lowercase.endswith(".raw") or lowercase.endswith(".gif")):
continue
fullname = f"{self.imagedir}/{item}"
size = os.stat(fullname)[6]
print(f"size: {size}")
@@ -72,11 +74,14 @@ class ImageView(Activity):
print(f"Skipping file of size {size}")
continue
self.images.append(fullname)
self.images.sort()
# Begin with one image:
self.show_next_image()
self.stop_fullscreen()
#self.image_timer = lv.timer_create(self.show_next_image, 1000, None)
self.images.sort()
# Begin with one image:
self.show_next_image()
self.stop_fullscreen()
#self.image_timer = lv.timer_create(self.show_next_image, 1000, None)
except Exception as e:
print(f"ImageView encountered exception for {self.imagedir}: {e}")
def onStop(self, screen):
print("ImageView stopping")