-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmy_timers.py
44 lines (32 loc) · 1.18 KB
/
my_timers.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
from abc import ABC, abstractmethod
from threading import Timer
from colors import ERROR_COLOR, SUCCESS_COLOR
from settings import ValidResponse
class MyTimerInterface(ABC):
"""Abstract class for custom timers."""
@abstractmethod
def timeout(self):
"""Performs user's commands when time has ended."""
pass
class MessageTimer(MyTimerInterface):
"""Class for changing an error message when time has ended."""
def __init__(self, delay, condition, label):
self.delay = Timer(delay, self.timeout)
self.condition = condition
self.label = label
self.delay.start()
def timeout(self):
self.condition.set('')
self.label.config(background=ERROR_COLOR)
class CommandTimer(MyTimerInterface):
"""Class for performing of command when time has ended."""
def __init__(self, delay, command, label, message):
self.delay = Timer(delay, self.timeout)
self.command = command
self.label = label
self.message = message
self.delay.start()
self.message.set(ValidResponse.SUCCESS)
self.label.config(background=SUCCESS_COLOR)
def timeout(self):
self.command()