@@ -122,6 +122,47 @@ def hide_widget(widget, anim_type="fade", duration=500, delay=0, hide=True):
122122 anim .start ()
123123 return anim
124124
125+ @staticmethod
126+ def change_widget (widget , anim_type = "interpolate" , duration = 5000 , delay = 0 , begin_value = 0 , end_value = 100 , display_change = None ):
127+ """
128+ Animate a widget's text by interpolating between begin_value and end_value.
129+
130+ Args:
131+ widget: The widget to animate (should have set_text method)
132+ anim_type: Type of animation (currently "interpolate" is supported)
133+ duration: Animation duration in milliseconds
134+ delay: Animation delay in milliseconds
135+ begin_value: Starting value for interpolation
136+ end_value: Ending value for interpolation
137+ display_change: callback to display the change in the UI
138+
139+ Returns:
140+ The animation object
141+ """
142+ lv .anim_delete (widget , None ) # stop all ongoing animations to prevent visual glitches
143+ anim = lv .anim_t ()
144+ anim .init ()
145+ anim .set_var (widget )
146+ anim .set_delay (delay )
147+ anim .set_duration (duration )
148+
149+ if anim_type == "interpolate" :
150+ print (f"Create interpolation animation (value from { begin_value } to { end_value } )" )
151+ anim .set_values (begin_value , end_value )
152+ if display_change is not None :
153+ anim .set_custom_exec_cb (lambda anim , value : safe_widget_access (lambda : display_change (value )))
154+ else :
155+ anim .set_custom_exec_cb (lambda anim , value : safe_widget_access (lambda : widget .set_text (str (value ))))
156+ anim .set_path_cb (lv .anim_t .path_ease_in_out )
157+ # Ensure final value is set after animation
158+ anim .set_completed_cb (lambda * args : safe_widget_access (lambda : widget .set_text (str (end_value ))))
159+ else :
160+ print (f"change_widget: unknown anim_type { anim_type } " )
161+ return
162+
163+ anim .start ()
164+ return anim
165+
125166 @staticmethod
126167 def hide_complete_cb (widget , original_y = None , hide = True ):
127168 #print("hide_complete_cb")
0 commit comments