forked from Marken-Foo/tsumemi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.py
56 lines (44 loc) · 1.26 KB
/
event.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
from abc import ABC, abstractmethod
class Event:
def __init__(self):
pass
class ProbDirEvent(Event):
def __init__(self, prob_list):
self.prob_list = prob_list
class ProbStatusEvent(Event):
def __init__(self, prob_idx, status):
self.idx = prob_idx
self.status = status
class ProbTimeEvent(Event):
def __init__(self, prob_idx, time):
self.idx = prob_idx
self.time = time
class TimerStartEvent(Event):
pass
class TimerStopEvent(Event):
pass
class TimerSplitEvent(Event):
def __init__(self, lap_time):
self.time = lap_time
class IObserver(ABC):
@abstractmethod
def on_notify(event):
event_type = type(event)
if event_type in self.NOTIFY_ACTIONS:
self.NOTIFY_ACTIONS[event_type](event)
return
class Emitter():
def add_observer(self, observer):
self.observers.append(observer)
return
def remove_observer(self, observer):
try:
self.observers.remove(observer)
except ValueError:
# observer does not exist in list; log
pass
return
def _notify_observers(self, event):
for observer in self.observers:
observer.on_notify(event)
return