From d2457e58111f7ca9f13695dbe5149499ebdee9c5 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Wed, 11 Jun 2025 11:55:00 +0200 Subject: [PATCH] imageview fullscreen works sortof --- .../assets/imageview.py | 44 ++++++++++++++++--- internal_filesystem/lib/mpos/ui/anim.py | 17 +++---- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/internal_filesystem/apps/com.micropythonos.imageview/assets/imageview.py b/internal_filesystem/apps/com.micropythonos.imageview/assets/imageview.py index f9d8c7e8..a47eb861 100644 --- a/internal_filesystem/apps/com.micropythonos.imageview/assets/imageview.py +++ b/internal_filesystem/apps/com.micropythonos.imageview/assets/imageview.py @@ -30,18 +30,24 @@ class ImageView(Activity): self.label.align(lv.ALIGN.TOP_MID,0,0) self.prev_button = lv.button(screen) self.prev_button.align(lv.ALIGN.BOTTOM_LEFT,0,0) + self.prev_button.add_event_cb(lambda e: self.show_prev_image_if_fullscreen(),lv.EVENT.FOCUSED,None) self.prev_button.add_event_cb(lambda e: self.show_prev_image(),lv.EVENT.CLICKED,None) prev_label = lv.label(self.prev_button) prev_label.set_text(lv.SYMBOL.LEFT) - #self.play_button = lv.button(screen) - #self.play_button.align(lv.ALIGN.BOTTOM_MID,0,0) + self.play_button = lv.button(screen) + self.play_button.align(lv.ALIGN.BOTTOM_MID,0,0) + self.play_button.add_flag(lv.obj.FLAG.HIDDEN) + self.play_button.set_style_opa(lv.OPA.TRANSP, 0) + #self.play_button.add_event_cb(lambda e: self.unfocus_if_not_fullscreen(),lv.EVENT.FOCUSED,None) + #self.play_button.set_style_shadow_opa(lv.OPA.TRANSP, 0) #self.play_button.add_event_cb(lambda e: self.play(),lv.EVENT.CLICKED,None) #play_label = lv.label(self.play_button) #play_label.set_text(lv.SYMBOL.PLAY) self.next_button = lv.button(screen) self.next_button.align(lv.ALIGN.BOTTOM_RIGHT,0,0) + #self.next_button.add_event_cb(self.print_events, lv.EVENT.ALL, None) + self.next_button.add_event_cb(lambda e: self.show_next_image_if_fullscreen(),lv.EVENT.FOCUSED,None) self.next_button.add_event_cb(lambda e: self.show_next_image(),lv.EVENT.CLICKED,None) - self.next_button.add_event_cb(self.print_events, lv.EVENT.ALL, None) next_label = lv.label(self.next_button) next_label.set_text(lv.SYMBOL.RIGHT) #screen.add_event_cb(self.print_events, lv.EVENT.ALL, None) @@ -109,16 +115,42 @@ class ImageView(Activity): mpos.ui.anim.smooth_show(self.label) mpos.ui.anim.smooth_show(self.prev_button) #mpos.ui.anim.smooth_show(self.play_button) + self.play_button.add_flag(lv.obj.FLAG.HIDDEN) mpos.ui.anim.smooth_show(self.next_button) else: print("starting fullscreen") self.fullscreen = True mpos.ui.anim.smooth_hide(self.label) - mpos.ui.anim.smooth_hide(self.prev_button) - #mpos.ui.anim.smooth_hide(self.play_button) - mpos.ui.anim.smooth_hide(self.next_button) + mpos.ui.anim.smooth_hide(self.prev_button, hide=False) + #mpos.ui.anim.smooth_hide(self.play_button, hide=False) + self.play_button.remove_flag(lv.obj.FLAG.HIDDEN) + mpos.ui.anim.smooth_hide(self.next_button, hide=False) self.scale_image() + def show_prev_image_if_fullscreen(self, event=None): + if self.fullscreen: + self.unfocus(True) + self.show_prev_image() + + def show_next_image_if_fullscreen(self, event=None): + if self.fullscreen: + self.unfocus(False) + self.show_next_image() + + def unfocus_if_not_fullscreen(self, event=None): + if not self.fullscreen: + self.unfocus(False) + + def unfocus(self, next): + group = lv.group_get_default() + # This doesn't work, and group.focus_obj() is missing, so need to do this hack: + #b = group.get_focused() + #b.remove_state(lv.STATE.FOCUSED) + if next: + group.focus_next() + else: + group.focus_prev() + def show_next_image(self, event=None): print("showing next image...") if len(self.images) < 1: diff --git a/internal_filesystem/lib/mpos/ui/anim.py b/internal_filesystem/lib/mpos/ui/anim.py index fb4800ca..704dba0b 100644 --- a/internal_filesystem/lib/mpos/ui/anim.py +++ b/internal_filesystem/lib/mpos/ui/anim.py @@ -67,7 +67,7 @@ class WidgetAnimator: anim.start() @staticmethod - def hide_widget(widget, anim_type="fade", duration=500, delay=0): + def hide_widget(widget, anim_type="fade", duration=500, delay=0, hide=True): """Hide a widget with an animation (fade or slide).""" if anim_type == "fade": # Create fade-out animation (opacity from 255 to 0) @@ -80,7 +80,7 @@ class WidgetAnimator: anim.set_custom_exec_cb(lambda anim, value: widget.set_style_opa(value, 0)) anim.set_path_cb(lv.anim_t.path_ease_in_out) # Set HIDDEN flag after animation - anim.set_completed_cb(lambda *args: WidgetAnimator.hide_complete_cb(widget)) + anim.set_completed_cb(lambda *args: WidgetAnimator.hide_complete_cb(widget, hide=hide)) elif anim_type == "slide_down": # Create slide-down animation (y from original y to +height) # Seems to cause scroll bars to be added somehow if done to a keyboard at the bottom of the screen... @@ -95,7 +95,7 @@ class WidgetAnimator: anim.set_custom_exec_cb(lambda anim, value: widget.set_y(value)) anim.set_path_cb(lv.anim_t.path_ease_in_out) # Set HIDDEN flag after animation - anim.set_completed_cb(lambda *args: WidgetAnimator.hide_complete_cb(widget, original_y)) + anim.set_completed_cb(lambda *args: WidgetAnimator.hide_complete_cb(widget, original_y, hide)) elif anim_type == "slide_up": print("hide with slide_up") # Create slide-up animation (y from original y to -height) @@ -110,16 +110,17 @@ class WidgetAnimator: anim.set_custom_exec_cb(lambda anim, value: widget.set_y(value)) anim.set_path_cb(lv.anim_t.path_ease_in_out) # Set HIDDEN flag after animation - anim.set_completed_cb(lambda *args: WidgetAnimator.hide_complete_cb(widget, original_y)) + anim.set_completed_cb(lambda *args: WidgetAnimator.hide_complete_cb(widget, original_y, hide)) # Store and start animation #self.animations[widget] = anim anim.start() @staticmethod - def hide_complete_cb(widget, original_y=None): + def hide_complete_cb(widget, original_y=None, hide=True): #print("hide_complete_cb") - widget.add_flag(lv.obj.FLAG.HIDDEN) + if hide: + widget.add_flag(lv.obj.FLAG.HIDDEN) if original_y: widget.set_y(original_y) # in case it shifted slightly due to rounding etc @@ -127,5 +128,5 @@ class WidgetAnimator: def smooth_show(widget): WidgetAnimator.show_widget(widget, anim_type="fade", duration=500, delay=0) -def smooth_hide(widget): - WidgetAnimator.hide_widget(widget, anim_type="fade", duration=500, delay=0) +def smooth_hide(widget, hide=True): + WidgetAnimator.hide_widget(widget, anim_type="fade", duration=500, delay=0, hide=hide)