-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
90 lines (72 loc) · 2.84 KB
/
Copy pathapp.py
File metadata and controls
90 lines (72 loc) · 2.84 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
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import division
import sys
import pygame
import logging
# Suppress harmless missing hashlib warnings on the Miyoo Python 2.7 build
logging.getLogger().setLevel(logging.CRITICAL)
from config import settings as C
from core.state import global_state, AppScreen
from ui.fonts import UIFonts
from ui.input_map import TAB_PREV, TAB_NEXT, LEFT, RIGHT
from ui.screens.connection import ConnectionScreen
from ui.screens.dashboard import DashboardScreen
from ui.screens.logs import LogScreen
from ui.screens.settings import SettingsScreen
from ui.screens.loading import LoadingScreen
from ui.screens.errors import ErrorsScreen
# Tab order: 0=Dashboard, 1=Logs, 2=Errors, 3=Settings
TAB_SCREENS = [AppScreen.DASHBOARD, AppScreen.LOG, AppScreen.ERRORS, AppScreen.SETTINGS]
def _switch_tab(direction):
"""Rotate through tab screens by +1 or -1."""
cur = global_state.screen
if cur in TAB_SCREENS:
idx = TAB_SCREENS.index(cur)
global_state.screen = TAB_SCREENS[(idx + direction) % len(TAB_SCREENS)]
def main():
pygame.init()
pygame.display.set_caption(C.APP_NAME)
screen = pygame.display.set_mode(
(C.WIDTH, C.HEIGHT), pygame.HWSURFACE | pygame.DOUBLEBUF
)
clock = pygame.time.Clock()
fonts = UIFonts.create()
global_state.load()
screens = {
AppScreen.CONNECTION: ConnectionScreen(fonts),
AppScreen.LOADING: LoadingScreen(fonts),
AppScreen.DASHBOARD: DashboardScreen(fonts),
AppScreen.LOG: LogScreen(fonts),
AppScreen.ERRORS: ErrorsScreen(fonts),
AppScreen.SETTINGS: SettingsScreen(fonts),
}
running = True
while running:
dt = clock.tick(C.FPS) / 1000.0
fps = clock.get_fps() or float(C.FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
continue
# Let the active screen handle the event first.
# If it returns False (didn't consume), we handle global keys.
consumed = screens[global_state.screen].handle_event(event)
if not consumed and event.type == pygame.KEYDOWN:
key = event.key
# Miyoo L/R shoulder → always switch tabs
# Mac Left/Right arrow → switch tabs (only reached when screen
# returned False, meaning no editable widget consumed the key)
if key in TAB_PREV or key in LEFT:
_switch_tab(-1)
elif key in TAB_NEXT or key in RIGHT:
_switch_tab(+1)
# Update & draw active screen
active = screens[global_state.screen]
active.update(dt)
active.draw(screen, fps)
pygame.display.flip()
pygame.quit()
sys.exit(0)
if __name__ == "__main__":
main()