-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
48 lines (39 loc) · 1.27 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
from time import strftime
from kivy.app import App
from kivy.clock import Clock
from kivy.core.text import LabelBase
from kivy.core.window import Window
from kivy.utils import get_color_from_hex
class ClockApp(App):
sw_started = False
sw_seconds = 0
def update_time(self, nap):
if self.sw_started:
self.sw_seconds += nap
minutes, seconds = divmod(self.sw_seconds, 60)
self.root.ids.stopwatch.text = (
'%02d:%02d.[size=40]%02d[/size]' %
(int(minutes), int(seconds),
int(seconds * 100 % 100))
)
self.root.ids.time.text = strftime('[b]%H[/b]:%M:%S')
def on_start(self):
Clock.schedule_interval(self.update_time, 0)
def start_stop(self):
self.root.ids.start_stop.text = (
'Start' if self.sw_started else 'Stop'
)
self.sw_started = not self.sw_started
def reset(self):
if self.sw_started:
self.root.ids.start_stop.text = 'Start'
self.sw_started = False
self.sw_seconds = 0
if __name__ == '__main__':
Window.clearcolor = get_color_from_hex('#101216')
LabelBase.register(
name='Roboto',
fn_regular='Roboto-Thin.ttf',
fn_bold='Roboto-Medium.ttf'
)
ClockApp().run()