-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
210 lines (182 loc) · 6.91 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
"""
JAKP
Hlavny file projektu,
menu, sluzi na spustanie modulov a submodulov
"""
import os
import pygame
import utils.create_user_files
from settings import *
from utils.load_assets import *
from utils.connectivity import internet as connection_check
from utils.user_settings_handling import return_user_settings
# Apps
from apps.settings_menu import settings_menu
from apps.meny import meny_app
from apps.stocks import stocks_app
from apps.kalkulacka_zivota import kalkulacka_zivota_app
from apps.kebab import kebab_app
from apps.vsemocna_kalkulacka import vsemocna_kalkulacka_app
from apps.case_inv import cases_app_inv
from apps.abeceda import abeceda_app
from apps.kalkulacka import kalkulacka_app
# Meny app importy
import http.client
import xml.etree.ElementTree as ET
# PyGame setup
pygame.init()
pygame.display.set_caption("JAKP")
pygame.display.set_icon(ICON)
os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide"
def return_conversion_list():
conn = http.client.HTTPSConnection("www.ecb.europa.eu")
conn.request("GET", "/stats/eurofxref/eurofxref-daily.xml")
res = conn.getresponse()
data = res.read()
root = ET.fromstring(data)
rates = {}
for i in root[2][0]:
entry = i.attrib
rates.update({entry["currency"]: float(entry["rate"])})
return rates
def main():
run = True
click = False
exit_cooldown = 0
no_internet_label_cooldown = 0
clock = pygame.time.Clock()
user_settings = return_user_settings()
if user_settings["theme"] == "light":
BG = BG_L
BG_LOADING = BG_LOADING_L
FONT_COLOR = FONT_COLOR_L
else:
BG = BG_D
BG_LOADING = BG_LOADING_D
FONT_COLOR = FONT_COLOR_D
WIN.blit(BG_LOADING, (0, 0))
pygame.display.update()
# Miesto pre robenie connections pre appky ktore to potrebuju
internet = connection_check()
if internet:
rates = return_conversion_list()
else:
B_RECONNECT = pygame.Rect(WIDTH_H - 80, 30, 160, 50)
label_no_internet = BIG_FONT.render("No internet connection", 1, (255, 0, 0))
label_reconnect = MAIN_FONT.render("Reconnect", 1, FONT_COLOR)
# BUTTONS
B_KEBAB = pygame.Rect(
(WIDTH_H - ICON_SIZE_H) // 2, HEIGHT_H // 3, ICON_SIZE, ICON_SIZE
)
B_A_SORT = pygame.Rect(
(WIDTH_H - ICON_SIZE_H) // 2 * 3, HEIGHT_H // 3, ICON_SIZE, ICON_SIZE
)
B_CASE = pygame.Rect(
(WIDTH_H - ICON_SIZE_H) // 2, HEIGHT_H - ICON_SIZE, ICON_SIZE, ICON_SIZE
)
B_LIFE = pygame.Rect(
(WIDTH_H - ICON_SIZE_H) // 2 * 3, HEIGHT_H - ICON_SIZE, ICON_SIZE, ICON_SIZE
)
B_MATHE = pygame.Rect(
(WIDTH_H - ICON_SIZE_H) // 2, HEIGHT_H + ICON_SIZE - 30, ICON_SIZE, ICON_SIZE
)
B_CALCUL = pygame.Rect(
(WIDTH_H - ICON_SIZE_H) // 2 * 3,
HEIGHT_H + ICON_SIZE - 30,
ICON_SIZE,
ICON_SIZE,
)
B_MENY = pygame.Rect(
(WIDTH_H - ICON_SIZE_H) // 2, HEIGHT_H * 3 // 2 + 40, ICON_SIZE, ICON_SIZE
)
B_STOCKS = pygame.Rect(
(WIDTH_H - ICON_SIZE_H) // 2 * 3, HEIGHT_H * 3 // 2 + 40, ICON_SIZE, ICON_SIZE
)
B_X = pygame.Rect(20, 20, 60, 60)
B_MENU = pygame.Rect(WIDTH - 60 - 20, 20, 60, 60)
# zaciatok main app loop
while run:
pos_x, pos_y = pygame.mouse.get_pos()
BG = BG_L if user_settings["theme"] == "light" else BG_D
WIN.blit(BG, (0, 0))
if not internet:
WIN.blit(BUTTON, (WIDTH_H - 80, 30))
WIN.blit(label_reconnect, (WIDTH_H - 60, 40))
# Blitovanie app icons
WIN.blit(KEBAB, ((WIDTH_H - ICON_SIZE_H) // 2, HEIGHT_H // 3))
WIN.blit(A_SORT, ((WIDTH_H - ICON_SIZE_H) // 2 * 3, HEIGHT_H // 3))
WIN.blit(CASE, ((WIDTH_H - ICON_SIZE_H) // 2, HEIGHT_H - ICON_SIZE))
WIN.blit(LIFE, ((WIDTH_H - ICON_SIZE_H) // 2 * 3, HEIGHT_H - ICON_SIZE))
WIN.blit(MATHE, ((WIDTH_H - ICON_SIZE_H) // 2, HEIGHT_H + ICON_SIZE - 30))
WIN.blit(CALCUL, ((WIDTH_H - ICON_SIZE_H) // 2 * 3, HEIGHT_H + ICON_SIZE - 30))
WIN.blit(X, (20, 20))
WIN.blit(MENU, (WIDTH - 65 - 20, 20))
if internet:
WIN.blit(MENY, ((WIDTH_H - ICON_SIZE_H) // 2, HEIGHT_H * 3 // 2 + 40))
WIN.blit(STOCKS, ((WIDTH_H - ICON_SIZE_H) // 2 * 3, HEIGHT_H * 3 // 2 + 40))
else:
WIN.blit(MENY_M, ((WIDTH_H - ICON_SIZE_H) // 2, HEIGHT_H * 3 // 2 + 40))
WIN.blit(
STOCKS_M, ((WIDTH_H - ICON_SIZE_H) // 2 * 3, HEIGHT_H * 3 // 2 + 40)
)
# Button Activations
if click:
if B_KEBAB.collidepoint(pos_x, pos_y):
kebab_app()
elif B_A_SORT.collidepoint(pos_x, pos_y):
abeceda_app()
elif B_CASE.collidepoint(pos_x, pos_y):
cases_app_inv()
elif B_LIFE.collidepoint(pos_x, pos_y):
kalkulacka_zivota_app()
elif B_MATHE.collidepoint(pos_x, pos_y):
vsemocna_kalkulacka_app()
elif B_CALCUL.collidepoint(pos_x, pos_y):
kalkulacka_app()
elif B_MENY.collidepoint(pos_x, pos_y):
if internet:
meny_app(rates)
else:
no_internet_label_cooldown = 180
elif B_STOCKS.collidepoint(pos_x, pos_y):
if internet:
stocks_app()
else:
no_internet_label_cooldown = 180
elif B_MENU.collidepoint(pos_x, pos_y):
settings_menu()
user_settings = return_user_settings()
elif B_X.collidepoint(pos_x, pos_y) and exit_cooldown == 0:
run = False
if not internet:
if B_RECONNECT.collidepoint(pos_x, pos_y):
label_reconnecting = BIG_FONT.render(
"Reconnecting...", 1, (0, 0, 255)
)
WIN.blit(label_reconnecting, (WIDTH_H - 120, 100))
pygame.display.update()
internet = connection_check()
if internet:
no_internet_label_cooldown = 0
rates = return_conversion_list()
exit_cooldown = FPS // 4
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
click = True
if event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
click = False
# exit_cooldown preventuje exit po clicknuti na back button z jednotlivych appiek
if exit_cooldown > 0:
exit_cooldown -= 1
if no_internet_label_cooldown > 0:
WIN.blit(label_no_internet, (WIDTH_H - 200, HEIGHT - 80))
no_internet_label_cooldown -= 1
clock.tick(FPS)
pygame.display.update()
pygame.quit()
if __name__ == "__main__":
main()