-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainSC.py
More file actions
153 lines (127 loc) · 5.01 KB
/
MainSC.py
File metadata and controls
153 lines (127 loc) · 5.01 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
'''
This is the entry point to the SmartClock interface.
It initializes the window and manages the screens.
It also updates the main modules, like the Leap Motion module, and distributes the data to the screens.
Interface developped by Julien REBOUL, Priscille Valla and Pierre LACLAU.
'''
import pygame
from InputManager import InputManager
from HomeScreen import *
from StartScreen import *
from NewsScreen import *
from Screen import *
from TestScreen import *
from WeatherScreen import *
from AutomationScreen import *
from TimeScreen import *
from CalendarScreen import *
from LockScreen import *
'''
Initialisations principales : demarrage de pygame et du chrono qui limite le systeme a 30 FPS.
'''
pygame.init()
clock = pygame.time.Clock()
'''
Initialisation de la fenetre : definit la resolution, mode plein ecran, et titre du logiciel.
'''
WindowRes = (800, 480)
gameDisplay = pygame.display.set_mode(WindowRes)#, pygame.FULLSCREEN)
pygame.display.set_caption('HomeCenter')
'''
....
Initialisation de l'ecouteur d'entrees : prepare la classe a capturer les entrees utilisateur
(clavier, souris, leap motion, evenements pygame)
'''
Input = InputManager(use_leapmotion = False, mouse_visible = True)
home_icon = pygame.image.load("Images/home.png")
'''
Creation de deux slots qui contiendront les ecrans a afficher.
Initialisation du premier ecran (StartScreen) et d'un ecran vide (Screen) pour l'instant.
'''
global currentScreen
LockScreen = SleepManager(WindowRes)
currentScreen = StartScreen(WindowRes) # ECRAN DE DEMARRAGE ICI
fadingScreen = Screen(WindowRes)
chrono = AnimationManager() #DEBUG FPS
gameRunning = True
while gameRunning:
chrono.Update()
'''
Handles pygame events such as quitting events.
'''
Input.Update(pygame.event.get())
if "QUIT" in Input.events:
gameRunning = False
if "HOME" in Input.events:
currentScreen = HomeScreen(WindowRes)
'''
Update des ecrans actifs (currentScreen pour l'ecran actif et fadingScreen pour l'eventuel ecran qui est en
train de faire sa transition sortante).
'''
LockScreen.Update(Input.events)
currentScreen.Update(Input.events)
fadingScreen.Update(Input.events)
'''
ScreenManager : Gere la creation, destruction et organisation des ecrans, et les prepare pour la Render Zone.
'''
status = currentScreen.ScreenStatus
if "FADING_OUT" in status :
fadingScreen = currentScreen
currentScreen = Screen(WindowRes)
status = fadingScreen.ScreenStatus
if status is not "RUNNING":
if "GOTO" in status:
if "GOTO_HOMESCREEN" in status:
currentScreen = HomeScreen(WindowRes, str(fadingScreen))
if "GOTO_STARTSCREEN" in status:
currentScreen = StartScreen(WindowRes)
if "GOTO_NEWSSCREEN" in status:
currentScreen = NewsScreen(WindowRes)
if "GOTO_TIMESCREEN" in status:
currentScreen = TimeScreen(WindowRes)
if "GOTO_CALENDARSCREEN" in status:
currentScreen = CalendarScreen(WindowRes)
if "GOTO_WEATHERSCREEN" in status:
currentScreen = WeatherScreen(WindowRes)
if "GOTO_AUTOMATIONSCREEN" in status:
currentScreen = AutomationScreen(WindowRes)
if "DEAD" in fadingScreen.ScreenStatus:
print "killing " + str(fadingScreen)
fadingScreen.Quit()
fadingScreen = Screen(WindowRes)
else:
fadingScreen.ScreenStatus = "FADING_OUT"
if "DEAD" in fadingScreen.ScreenStatus:
print "killing " + str(fadingScreen)
fadingScreen.Quit()
fadingScreen = Screen(WindowRes)
'''
Render Zone : dessine tous les ecrans actifs.
'''
gameDisplay.fill((0, 0, 0))
if "FADING_OUT" in fadingScreen.ScreenStatus:
fadingScreen.Draw(gameDisplay)
currentScreen.Draw(gameDisplay)
LockScreen.Draw(gameDisplay)
if str(currentScreen) is not "HOMESCREEN":
if str(currentScreen) is not "NEWSSCREEN": # petite exception pour NewsScreen
gameDisplay.blit(home_icon, (0, 0))
for event in Input.events:
if Helpers.is_in_rect(pygame.mouse.get_pos(), [0, 0, 30, 30]):
currentScreen = HomeScreen(WindowRes)
Input.EndUpdate()
'''
Envoie les dessins a pygame qui les affiche.
Limite le systeme a 30 FPS pour economiser les ressources de l'ordinateur.
'''
pygame.display.update()
clock.tick(30)
#print "FPS : " + str(1/ chrono.delta_elapsed_time()) #DEBUG FPS
'''
Sortie du systeme : desinitialise pygame, les ecrans actifs et l'ecouteur d'entrees avant de quitter totalement.
'''
pygame.quit()
Input.quit()
currentScreen.Quit()
fadingScreen.Quit()
quit()