-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
124 lines (93 loc) · 2.66 KB
/
main.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""
Main module of Postrias.
"""
print("Start Postrias")
###############
### Imports ###
###############
### Python imports ###
import os
import platform
os_name = platform.system()
if os_name == "Windows":
os.environ['KIVY_TEXT'] = 'pil'
print("Python packages loaded")
### Kivy imports ###
# Disable back arrow
from kivy.config import Config
Config.set('kivy', 'exit_on_escape', '0')
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, NoTransition, Screen
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.clock import Clock
print("Kivy packages loaded")
### Module imports ###
from tools.path import (
PATH_IMAGES
)
from tools.constants import (
MOBILE_MODE,
FPS,
MSAA_LEVEL
)
import screens.opening
print("Local packages loaded")
###############
### General ###
###############
class WindowManager(ScreenManager):
"""
Screen manager, which allows the navigation between the different menus.
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.transition = NoTransition()
self.list_former_screens = []
current_screen = Screen(name="temp")
self.add_widget(current_screen)
self.current = "temp"
print("WindowManager initialised")
class MainApp(App, Widget):
"""
Main class of the application.
"""
def build_config(self, config):
"""
Build the config file for the application.
It sets the FPS number and the antialiasing level.
"""
config.setdefaults('graphics', {
'maxfps': str(FPS),
'multisamples': str(MSAA_LEVEL)
})
def build(self):
"""
Build the application.
Parameters
----------
None
Returns
-------
None
"""
Window.clearcolor = (0, 0, 0, 1)
self.icon = PATH_IMAGES + "logo.png"
def on_resume(self):
current_screen_name = self.root_window.children[0].current
self.root_window.children[0].get_screen(current_screen_name).refresh()
return super().on_resume()
def on_start(self):
if MOBILE_MODE:
Window.update_viewport()
# Open the opening screen
opening_screen = screens.opening.OpeningScreen(name="opening")
self.root_window.children[0].add_widget(opening_screen)
self.root_window.children[0].current = "opening"
Clock.schedule_once(
self.root_window.children[0].get_screen("opening").launch_thread)
print("Main app started")
return super().on_start()
# Run the application
if __name__ == "__main__":
MainApp().run()