2025-10-30 20:31:02 +01:00
|
|
|
import lvgl as lv
|
2026-01-09 17:59:00 +01:00
|
|
|
import sys
|
|
|
|
|
|
2025-10-30 20:31:02 +01:00
|
|
|
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]
|
2026-01-09 10:44:43 +01:00
|
|
|
try:
|
|
|
|
|
current_activity.onPause(current_screen)
|
|
|
|
|
except Exception as e:
|
2026-01-13 00:38:17 +01:00
|
|
|
print(f"onPause caught exception:")
|
2026-01-09 17:59:00 +01:00
|
|
|
sys.print_exception(e)
|
2026-01-09 10:44:43 +01:00
|
|
|
try:
|
|
|
|
|
current_activity.onStop(current_screen)
|
|
|
|
|
except Exception as e:
|
2026-01-13 00:38:17 +01:00
|
|
|
print(f"onStop caught exception:")
|
2026-01-09 17:59:00 +01:00
|
|
|
sys.print_exception(e)
|
2025-10-30 20:31:02 +01:00
|
|
|
|
|
|
|
|
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:
|
2026-01-09 10:44:43 +01:00
|
|
|
try:
|
|
|
|
|
new_activity.onStart(new_screen)
|
|
|
|
|
except Exception as e:
|
2026-01-13 00:38:17 +01:00
|
|
|
print(f"onStart caught exception:")
|
2026-01-09 17:59:00 +01:00
|
|
|
sys.print_exception(e)
|
2025-11-23 14:21:17 +01:00
|
|
|
lv.screen_load_anim(new_screen, lv.SCR_LOAD_ANIM.OVER_LEFT, 500, 0, False)
|
2025-10-30 20:31:02 +01:00
|
|
|
if new_activity:
|
2026-01-09 10:44:43 +01:00
|
|
|
try:
|
|
|
|
|
new_activity.onResume(new_screen)
|
|
|
|
|
except Exception as e:
|
2026-01-13 00:38:17 +01:00
|
|
|
print(f"onResume caught exception:")
|
2026-01-09 17:59:00 +01:00
|
|
|
sys.print_exception(e)
|
2025-10-30 20:31:02 +01:00
|
|
|
|
2025-11-08 07:08:17 +01:00
|
|
|
def remove_and_stop_all_activities():
|
|
|
|
|
global screen_stack
|
|
|
|
|
while len(screen_stack):
|
|
|
|
|
remove_and_stop_current_activity()
|
|
|
|
|
|
2025-10-30 21:22:37 +01:00
|
|
|
def remove_and_stop_current_activity():
|
|
|
|
|
current_activity, current_screen, current_focusgroup, _ = screen_stack.pop()
|
|
|
|
|
if current_activity:
|
2026-01-09 10:44:43 +01:00
|
|
|
try:
|
|
|
|
|
current_activity.onPause(current_screen)
|
|
|
|
|
except Exception as e:
|
2026-01-13 00:38:17 +01:00
|
|
|
print(f"onPause caught exception:")
|
2026-01-09 17:59:00 +01:00
|
|
|
sys.print_exception(e)
|
2026-01-09 10:44:43 +01:00
|
|
|
try:
|
|
|
|
|
current_activity.onStop(current_screen)
|
|
|
|
|
except Exception as e:
|
2026-01-13 00:38:17 +01:00
|
|
|
print(f"onStop caught exception:")
|
2026-01-09 17:59:00 +01:00
|
|
|
sys.print_exception(e)
|
2026-01-09 10:44:43 +01:00
|
|
|
try:
|
|
|
|
|
current_activity.onDestroy(current_screen)
|
|
|
|
|
except Exception as e:
|
2026-01-13 00:38:17 +01:00
|
|
|
print(f"onDestroy caught exception:")
|
2026-01-09 17:59:00 +01:00
|
|
|
sys.print_exception(e)
|
2025-10-30 21:22:37 +01:00
|
|
|
if current_screen:
|
|
|
|
|
current_screen.clean()
|
|
|
|
|
|
2025-10-30 20:31:02 +01:00
|
|
|
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()
|
|
|
|
|
|
2025-10-30 21:22:37 +01:00
|
|
|
remove_and_stop_current_activity()
|
2025-10-30 20:31:02 +01:00
|
|
|
|
|
|
|
|
# Load previous
|
|
|
|
|
prev_activity, prev_screen, prev_focusgroup, prev_focused = screen_stack[-1]
|
2026-01-09 19:45:25 +01:00
|
|
|
print(f"back_screen got {prev_activity}, {prev_screen}, {prev_focusgroup}, {prev_focused}")
|
2025-11-23 14:21:17 +01:00
|
|
|
lv.screen_load_anim(prev_screen, lv.SCR_LOAD_ANIM.OVER_RIGHT, 500, 0, True)
|
2025-10-30 20:31:02 +01:00
|
|
|
|
|
|
|
|
default_group = lv.group_get_default()
|
|
|
|
|
if default_group:
|
|
|
|
|
from .focus import move_focusgroup_objects
|
|
|
|
|
move_focusgroup_objects(prev_focusgroup, default_group)
|
2026-01-25 21:17:20 +01:00
|
|
|
from .input_manager import InputManager
|
|
|
|
|
InputManager.emulate_focus_obj(default_group, prev_focused)
|
2025-10-30 20:31:02 +01:00
|
|
|
|
|
|
|
|
if prev_activity:
|
|
|
|
|
prev_activity.onResume(prev_screen)
|
|
|
|
|
|
|
|
|
|
if len(screen_stack) == 1:
|
|
|
|
|
open_bar()
|
|
|
|
|
|
|
|
|
|
return True
|