Skip to content

Commit 2f67da0

Browse files
committed
Timer cycle working. Can be used as a mob timer now.
1 parent 342ab6e commit 2f67da0

11 files changed

+47
-24
lines changed

Infrastructure/CountdownManager.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import datetime
2+
import time
3+
4+
5+
class CountdownManager(object):
6+
def __init__(self, root_tk_app):
7+
self.start_time = time.time()
8+
self.minutes = 0
9+
self.seconds = 0
10+
self.time_change_callbacks = []
11+
self.count_down_total = datetime.timedelta(minutes=0, seconds=0)
12+
13+
self.root_tk_app = root_tk_app
14+
self.refresh_timer()
15+
16+
def set_countdown_duration(self, minutes, seconds):
17+
self.minutes = minutes
18+
self.seconds = seconds
19+
self.count_down_total = datetime.timedelta(minutes=minutes, seconds=seconds)
20+
self.fire_time_change_callbacks()
21+
22+
def subscribe_to_time_changes(self, time_change_callback):
23+
self.time_change_callbacks.append(time_change_callback)
24+
25+
def fire_time_change_callbacks(self):
26+
end_time = time.time()
27+
up_time = end_time - self.start_time
28+
remaining_time = self.count_down_total - datetime.timedelta(seconds=(int(up_time)))
29+
for callback in self.time_change_callbacks:
30+
if callback:
31+
callback((remaining_time.seconds // 60) % 60, self.seconds)
32+
33+
def refresh_timer(self):
34+
if self.root_tk_app:
35+
self.fire_time_change_callbacks()
36+
self.root_tk_app.after(1000, self.refresh_timer)

tests/Infrastrcture/CountdownManager/TestsCountdownManager.py renamed to tests/Infrastructure/CountdownManager/TestsCountdownManager.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
1+
import datetime
2+
import time
13
import unittest
24

35
from approvaltests import Approvals
46
from approvaltests.TextDiffReporter import TextDiffReporter
57

8+
from Infrastructure.CountdownManager.TestsCountdownManager import CountdownManager
69

7-
class CountdownManager(object):
8-
def __init__(self, root_tk_app):
9-
self.minutes = 0
10-
self.seconds = 0
11-
self.time_change_callbacks = []
1210

13-
self.root_tk_app = root_tk_app
14-
self.refresh_timer()
15-
16-
def set_countdown_duration(self, minutes, seconds):
17-
self.minutes = minutes
18-
self.seconds = seconds
19-
self.fire_time_change_callbacks()
20-
21-
def subscribe_to_time_changes(self, time_change_callback):
22-
self.time_change_callbacks.append(time_change_callback)
23-
24-
def fire_time_change_callbacks(self):
25-
for callback in self.time_change_callbacks:
26-
if callback:
27-
callback(self.minutes, self.seconds)
11+
class TestsCountdownManager(unittest.TestCase):
12+
def test_time(self):
13+
start_time = time.time()
14+
time.sleep(2)
15+
end_time = time.time()
2816

29-
def refresh_timer(self):
30-
if self.root_tk_app:
31-
self.root_tk_app.after(1000, self.refresh_timer)
17+
uptime = end_time - start_time
3218

19+
self.assertEqual(datetime.timedelta(seconds=int(uptime)).__str__(), (
20+
datetime.timedelta(seconds=15, minutes=1) - datetime.timedelta(seconds=(int(uptime)))).__str__())
3321

34-
class TestsCountdownManager(unittest.TestCase):
3522
def test_set_countdown_timer(self):
3623
countdown_manager = CountdownManager(None)
3724
countdown_manager.set_countdown_duration(5, 14)
File renamed without changes.

tests/Infrastrcture/CountdownManager/tests.Infrastrcture.CountdownManager.TestsCountdownManager.test_subscribe_to_time_changes.approved.txt renamed to tests/Infrastructure/CountdownManager/tests.Infrastructure.CountdownManager.TestsCountdownManager.test_subscribe_to_time_changes.approved.txt

File renamed without changes.

tests/Infrastrcture/MobberManager/TestsMobberManager.py renamed to tests/Infrastructure/MobberManager/TestsMobberManager.py

File renamed without changes.
File renamed without changes.

tests/Infrastrcture/MobberManager/tests.Infrastrcture.MobberManager.TestsMobberManager.test_subscribe_to_mobber_list_changes.approved.txt renamed to tests/Infrastructure/MobberManager/tests.Infrastructure.MobberManager.TestsMobberManager.test_subscribe_to_mobber_list_changes.approved.txt

File renamed without changes.

tests/Infrastrcture/TimeOptionsManager/TestsTimeOptionsManager.py renamed to tests/Infrastructure/TimeOptionsManager/TestsTimeOptionsManager.py

File renamed without changes.
File renamed without changes.

tests/Infrastrcture/TimeOptionsManager/tests.Infrastrcture.TimeOptionsManager.TestsTimeOptionsManager.test_subscribe_to_time_changes_complex.approved.txt renamed to tests/Infrastructure/TimeOptionsManager/tests.Infrastructure.TimeOptionsManager.TestsTimeOptionsManager.test_subscribe_to_time_changes_complex.approved.txt

File renamed without changes.

0 commit comments

Comments
 (0)