44
55class Activity :
66
7- throttle_async_call_counter = 0
8-
97 def __init__ (self ):
108 self .intent = None # Store the intent that launched this activity
119 self .result = None
@@ -19,7 +17,6 @@ def onStart(self, screen):
1917
2018 def onResume (self , screen ): # app goes to foreground
2119 self ._has_foreground = True
22- mpos .ui .task_handler .add_event_cb (self .task_handler_callback , 1 )
2320
2421 def onPause (self , screen ): # app goes to background
2522 self ._has_foreground = False
@@ -69,9 +66,6 @@ def finish(self):
6966 def has_foreground (self ):
7067 return self ._has_foreground
7168
72- def task_handler_callback (self , a , b ):
73- self .throttle_async_call_counter = 0
74-
7569 # Execute a function if the Activity is in the foreground
7670 def if_foreground (self , func , * args , event = None , ** kwargs ):
7771 if self ._has_foreground :
@@ -85,14 +79,10 @@ def if_foreground(self, func, *args, event=None, **kwargs):
8579 return None
8680
8781 # Update the UI in a threadsafe way if the Activity is in the foreground
88- # The call may get throttled, unless important=True is added to it.
8982 # The order of these update_ui calls are not guaranteed, so a UI update might be overwritten by an "earlier" update.
9083 # To avoid this, use lv.timer_create() with .set_repeat_count(1) as examplified in osupdate.py
84+ # Or avoid using threads altogether, by using TaskManager (asyncio).
9185 def update_ui_threadsafe_if_foreground (self , func , * args , important = False , event = None , ** kwargs ):
92- self .throttle_async_call_counter += 1
93- if not important and self .throttle_async_call_counter > 100 : # 250 seems to be okay, so 100 is on the safe side
94- print (f"update_ui_threadsafe_if_foreground called more than 100 times for one UI frame, which can overflow - throttling!" )
95- return None
9686 # lv.async_call() is needed to update the UI from another thread than the main one (as LVGL is not thread safe)
9787 result = lv .async_call (lambda _ : self .if_foreground (func , * args , event = event , ** kwargs ), None )
9888 return result
0 commit comments