forked from MicroPythonOS/MicroPythonOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.py
More file actions
98 lines (82 loc) · 3.08 KB
/
view.py
File metadata and controls
98 lines (82 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import lvgl as lv
import sys
from .focus import save_and_clear_current_focusgroup
from .topmenu import open_bar
screen_stack = []
def setContentView(new_activity, new_screen):
global screen_stack
if screen_stack:
current_activity, current_screen, current_focusgroup, _ = screen_stack[-1]
try:
current_activity.onPause(current_screen)
except Exception as e:
print(f"onPause caught exception:")
sys.print_exception(e)
try:
current_activity.onStop(current_screen)
except Exception as e:
print(f"onStop caught exception:")
sys.print_exception(e)
from .util import close_top_layer_msgboxes
close_top_layer_msgboxes()
screen_stack.append((new_activity, new_screen, lv.group_create(), None))
if new_activity:
try:
new_activity.onStart(new_screen)
except Exception as e:
print(f"onStart caught exception:")
sys.print_exception(e)
lv.screen_load_anim(new_screen, lv.SCR_LOAD_ANIM.OVER_LEFT, 500, 0, False)
if new_activity:
try:
new_activity.onResume(new_screen)
except Exception as e:
print(f"onResume caught exception:")
sys.print_exception(e)
def remove_and_stop_all_activities():
global screen_stack
while len(screen_stack):
remove_and_stop_current_activity()
def remove_and_stop_current_activity():
current_activity, current_screen, current_focusgroup, _ = screen_stack.pop()
if current_activity:
try:
current_activity.onPause(current_screen)
except Exception as e:
print(f"onPause caught exception:")
sys.print_exception(e)
try:
current_activity.onStop(current_screen)
except Exception as e:
print(f"onStop caught exception:")
sys.print_exception(e)
try:
current_activity.onDestroy(current_screen)
except Exception as e:
print(f"onDestroy caught exception:")
sys.print_exception(e)
if current_screen:
current_screen.clean()
def back_screen():
global screen_stack
if len(screen_stack) <= 1:
print("Warning: can't go back — stack empty")
return False
from .util import close_top_layer_msgboxes
close_top_layer_msgboxes()
remove_and_stop_current_activity()
# Load previous
prev_activity, prev_screen, prev_focusgroup, prev_focused = screen_stack[-1]
print(f"back_screen got {prev_activity}, {prev_screen}, {prev_focusgroup}, {prev_focused}")
lv.screen_load_anim(prev_screen, lv.SCR_LOAD_ANIM.OVER_RIGHT, 500, 0, True)
default_group = lv.group_get_default()
if default_group:
from .focus import move_focusgroup_objects
move_focusgroup_objects(prev_focusgroup, default_group)
from .input_manager import InputManager
InputManager.emulate_focus_obj(default_group, prev_focused)
if prev_activity:
prev_activity.onResume(prev_screen)
if len(screen_stack) == 1:
open_bar()
return True