-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActions.py
More file actions
85 lines (78 loc) · 2.65 KB
/
Actions.py
File metadata and controls
85 lines (78 loc) · 2.65 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
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtGui import QFont, QIcon
from SqlFucntions import SqlFunctions
class Actions(SqlFunctions):
def __int__(self):
"""
Constructor
"""
SqlFunctions.__init__(self)
def show_records(self, obj):
"""
Show a Message Box with the best times
"""
font = QFont()
font.setPointSize(10)
messageBox = QMessageBox()
messageBox.setWindowTitle("Best Times")
messageBox.setWindowIcon(QIcon("images/bomb.jpg"))
messageBox.setFont(font)
times = self.get_times()
if times == []:
message = "You haven't records yet !"
else:
message = '\n'.join(f'{i+1} - {time}\t' for i, time in enumerate(times))
messageBox.setText(message)
obj.pause_timer()
messageBox.exec()
obj.resume_timer()
def erase_records(self, obj):
"""
Erase all the times from database
"""
font = QFont()
font.setPointSize(10)
messageBox = QMessageBox()
messageBox.setWindowTitle("Delete records")
messageBox.setText("Are you sure to delete the records ?")
messageBox.setWindowIcon(QIcon("images/bomb.jpg"))
messageBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
messageBox.setDefaultButton(QMessageBox.No)
messageBox.setFont(font)
obj.pause_timer()
if messageBox.exec_() == QMessageBox.Yes:
self.drop_table_best_times()
obj.resume_timer()
def save_time(self, time: str):
"""
Save player time
:param time: Player time
"""
self.insert_time(self.convert_time_to_seconds(time))
def get_times(self) -> list[str]:
"""
Get the five best times
:return: list of best times
"""
times = self.select_times()
return list(map(self.convert_secods_to_time, times))
@staticmethod
def convert_secods_to_time(seconds: int) -> str:
"""
Convert seconds to time
:param seconds: seconds in integer format
:return: Time string in hh:mm:ss format
"""
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds = (seconds % 3600) % 60
return "{:02d}:{:02d}:{:02d}".format(hours, minutes, seconds)
@staticmethod
def convert_time_to_seconds(time: str) -> int:
"""
Convert time to seconds
:param time: time string in hh:mm:ss format
:return: Seconds in integer format
"""
time = time.split(":")
return (int(time[0]) * 3600) + (int(time[1]) * 60) + int(time[2])