Skip to content

Commit 3655a53

Browse files
Make animations simpler
1 parent ba0b2bd commit 3655a53

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

  • internal_filesystem

internal_filesystem/builtin/apps/com.micropythonos.wifi/assets/wifi.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import _thread
66

77
from mpos.apps import Activity, Intent
8-
import mpos.ui.anim
9-
import mpos.ui
8+
109
import mpos.config
10+
import mpos.ui.anim
1111

1212
have_network = True
1313
try:
@@ -220,8 +220,6 @@ class PasswordPage(Activity):
220220
connect_button=None
221221
cancel_button=None
222222

223-
animator = mpos.ui.anim.WidgetAnimator()
224-
225223
def onCreate(self):
226224
self.selected_ssid = self.getIntent().extras.get("selected_ssid")
227225
print("PasswordPage: Creating new password page")
@@ -269,7 +267,7 @@ def onCreate(self):
269267

270268
def hide_keyboard(self):
271269
print("keyboard_cb: READY or CANCEL or RETURN clicked, hiding keyboard")
272-
self.animator.hide_widget(self.keyboard, anim_type="fade", duration=500, delay=0)
270+
mpos.ui.anim.smooth_hide(self.keyboard)
273271
print("keyboard_cb: Showing Connect and Cancel buttons")
274272
self.connect_button.remove_flag(lv.obj.FLAG.HIDDEN)
275273
self.cancel_button.remove_flag(lv.obj.FLAG.HIDDEN)
@@ -296,7 +294,7 @@ def password_ta_cb(self, event):
296294
self.connect_button.add_flag(lv.obj.FLAG.HIDDEN)
297295
self.cancel_button.add_flag(lv.obj.FLAG.HIDDEN)
298296
print("password_ta_cb: Showing keyboard")
299-
self.animator.show_widget(self.keyboard, anim_type="fade", duration=500, delay=0) # slide_up causes it to be placed way too low...
297+
mpos.ui.anim.smooth_show(self.keyboard)
300298

301299

302300
def connect_cb(self, event):

internal_filesystem/lib/mpos/ui/anim.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import lvgl as lv
22

33
class WidgetAnimator:
4-
def __init__(self):
5-
self.animations = {} # Store animations for each widget
64

7-
# show_widget and hide_widget could have a (lambda) callback that sets the final state (eg: drawer_open) at the end
5+
# def __init__(self):
6+
# self.animations = {} # Store animations for each widget
7+
8+
# def stop_animation(self, widget):
9+
# """Stop any running animation for the widget."""
10+
# if widget in self.animations:
11+
# self.animations[widget].delete()
12+
# del self.animations[widget]
13+
814

9-
def show_widget(self, widget, anim_type="fade", duration=500, delay=0):
15+
# show_widget and hide_widget could have a (lambda) callback that sets the final state (eg: drawer_open) at the end
16+
@staticmethod
17+
def show_widget(widget, anim_type="fade", duration=500, delay=0):
1018
"""Show a widget with an animation (fade or slide)."""
1119
# Clear HIDDEN flag to make widget visible for animation
1220
widget.remove_flag(lv.obj.FLAG.HIDDEN)
@@ -55,10 +63,11 @@ def show_widget(self, widget, anim_type="fade", duration=500, delay=0):
5563
anim.set_completed_cb(lambda *args: widget.set_y(original_y))
5664

5765
# Store and start animation
58-
self.animations[widget] = anim
66+
#self.animations[widget] = anim
5967
anim.start()
6068

61-
def hide_widget(self, widget, anim_type="fade", duration=500, delay=0):
69+
@staticmethod
70+
def hide_widget(widget, anim_type="fade", duration=500, delay=0):
6271
"""Hide a widget with an animation (fade or slide)."""
6372
if anim_type == "fade":
6473
# Create fade-out animation (opacity from 255 to 0)
@@ -71,7 +80,7 @@ def hide_widget(self, widget, anim_type="fade", duration=500, delay=0):
7180
anim.set_custom_exec_cb(lambda anim, value: widget.set_style_opa(value, 0))
7281
anim.set_path_cb(lv.anim_t.path_ease_in_out)
7382
# Set HIDDEN flag after animation
74-
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget))
83+
anim.set_completed_cb(lambda *args: WidgetAnimator.hide_complete_cb(widget))
7584
elif anim_type == "slide_down":
7685
# Create slide-down animation (y from original y to +height)
7786
# Seems to cause scroll bars to be added somehow if done to a keyboard at the bottom of the screen...
@@ -86,7 +95,7 @@ def hide_widget(self, widget, anim_type="fade", duration=500, delay=0):
8695
anim.set_custom_exec_cb(lambda anim, value: widget.set_y(value))
8796
anim.set_path_cb(lv.anim_t.path_ease_in_out)
8897
# Set HIDDEN flag after animation
89-
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget))
98+
anim.set_completed_cb(lambda *args: WidgetAnimator.hide_complete_cb(widget))
9099
elif anim_type == "slide_up":
91100
print("hide with slide_up")
92101
# Create slide-up animation (y from original y to -height)
@@ -101,21 +110,22 @@ def hide_widget(self, widget, anim_type="fade", duration=500, delay=0):
101110
anim.set_custom_exec_cb(lambda anim, value: widget.set_y(value))
102111
anim.set_path_cb(lv.anim_t.path_ease_in_out)
103112
# Set HIDDEN flag after animation
104-
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget))
113+
anim.set_completed_cb(lambda *args: WidgetAnimator.hide_complete_cb(widget))
105114

106115
# Store and start animation
107-
self.animations[widget] = anim
116+
#self.animations[widget] = anim
108117
anim.start()
109118

110-
def hide_complete_cb(self, widget):
119+
@staticmethod
120+
def hide_complete_cb(widget):
111121
#print("hide_complete_cb")
112122
widget.add_flag(lv.obj.FLAG.HIDDEN)
113123
#if original_y:
114124
# widget.set_y(original_y) # in case it shifted slightly due to rounding etc
115125

116126

117-
def stop_animation(self, widget):
118-
"""Stop any running animation for the widget."""
119-
if widget in self.animations:
120-
self.animations[widget].delete()
121-
del self.animations[widget]
127+
def smooth_show(widget):
128+
WidgetAnimator.show_widget(widget, anim_type="fade", duration=500, delay=0)
129+
130+
def smooth_hide(widget):
131+
WidgetAnimator.hide_widget(widget, anim_type="fade", duration=500, delay=0)

0 commit comments

Comments
 (0)