Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitce57c1e

Browse files
Activity.py: limit async_call()s
1 parente4d1b5a commitce57c1e

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

‎internal_filesystem/lib/mpos/app/activity.py‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
importlvglaslv
22
importmpos.ui
3+
importtime
34

45
classActivity:
56

@@ -15,6 +16,8 @@ def onStart(self, screen):
1516
pass
1617
defonResume(self,screen):# app gets foreground
1718
self._has_foreground=True
19+
mpos.ui.th.add_event_cb(self.thc,2)
20+
1821
defonPause(self,screen):# app goes to background
1922
self._has_foreground=False
2023
defonStop(self,screen):
@@ -62,15 +65,27 @@ def finish(self):
6265
defhas_foreground(self):
6366
returnself._has_foreground
6467

68+
defthc(self,a,b):
69+
#print("thc called")
70+
self.counter=0
71+
6572
# Execute a function if the Activity is in the foreground
6673
defif_foreground(self,func,*args,**kwargs):
6774
ifself._has_foreground:
68-
returnfunc(*args,**kwargs)
75+
print(f"executing{func} with args{args} and kwargs{kwargs}")
76+
result=func(*args,**kwargs)
77+
returnresult
6978
else:
70-
print(f"[if_foreground] Skipped{func} because _has_foreground=False")
79+
#print(f"[if_foreground] Skipped {func} because _has_foreground=False")
7180
returnNone
7281

82+
counter=0
7383
# Update the UI in a threadsafe way if the Activity is in the foreground
74-
defupdate_ui_threadsafe_if_foreground(self,func,*args,**kwargs):
84+
defupdate_ui_threadsafe_if_foreground(self,func,*args,important=False,**kwargs):
85+
self.counter+=1
86+
ifnotimportantandself.counter>250:
87+
#print(f"skipping because self.counter is {self.counter} and not important")
88+
return
7589
# lv.async_call() is needed to update the UI from another thread than the main one (as LVGL is not thread safe)
76-
lv.async_call(lambda_:self.if_foreground(func,*args,**kwargs),None)
90+
result=lv.async_call(lambda_:self.if_foreground(func,*args,**kwargs),None)
91+
returnresult

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp