-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathQDiveTimer.py
More file actions
97 lines (69 loc) · 1.98 KB
/
Copy pathQDiveTimer.py
File metadata and controls
97 lines (69 loc) · 1.98 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
from PyQt5.QtCore import QObject, QTime, QTimer
class QDiveTimer(QObject):
def __init__(self, parent=None) -> None:
QObject.__init__(self, parent)
self.__time = QTime(0, 0, 0)
self.__paused = False
self.__started = False
self.__timer = QTimer()
self.__timer.timeout.connect(self.__update)
def start(self) -> None:
"""Start the dive timer.
"""
if not self.__paused and self.__started:
return
self.__paused = False
self.__started = True
self.__timer.start(1000)
def pause(self) -> None:
"""Pause the dive timer.
"""
if self.__paused:
return
self.__paused = True
self.__timer.stop()
def stop(self) -> None:
"""Stop the dive timer.
"""
self.__timer.stop()
self.__paused = False
self.__started = False
self.__time = QTime(0, 0, 0)
@property
def elapsed(self) -> int:
"""Helper property.
Returns
-------
int
the time elapsed in seconds
"""
return self.__time.hour() * 3600 + self.__time.minute() * 60 + self.__time.second()
@property
def started(self) -> bool:
"""Check whether the dive timer has started or not.
Returns
-------
bool
True, if the timer has started, False otherwise
"""
return self.__started
@property
def paused(self) -> bool:
"""Check whether the dive timer has paused or not.
Returns
-------
bool
True, if the timer has paused, False otherwise
"""
return self.__paused
@property
def time(self) -> str:
"""Get the diving time.
Returns
-------
str
diving time in format hh:mm:ss
"""
return self.__time.toString('hh:mm:ss')
def __update(self):
self.__time = self.__time.addSecs(1)