55
66
77class CountdownManager (object ):
8- def __init__ (self ):
8+ def __init__ (self , root_tk_app ):
99 self .minutes = 0
1010 self .seconds = 0
1111 self .time_change_callbacks = []
1212
13+ self .root_tk_app = root_tk_app
14+ self .refresh_timer ()
15+
1316 def set_countdown_duration (self , minutes , seconds ):
1417 self .minutes = minutes
1518 self .seconds = seconds
@@ -23,21 +26,25 @@ def fire_time_change_callbacks(self):
2326 if callback :
2427 callback (self .minutes , self .seconds )
2528
29+ def refresh_timer (self ):
30+ if self .root_tk_app :
31+ self .root_tk_app .after (1000 , self .refresh_timer )
32+
2633
2734class TestsCountdownManager (unittest .TestCase ):
2835 def test_set_countdown_timer (self ):
29- countdown_manager = CountdownManager ()
36+ countdown_manager = CountdownManager (None )
3037 countdown_manager .set_countdown_duration (5 , 14 )
3138 result = "{}:{}" .format (countdown_manager .minutes , countdown_manager .seconds )
3239 self .assertEqual ("5:14" , result )
3340
3441 def test_new_countdown_timer (self ):
35- countdown_manager = CountdownManager ()
42+ countdown_manager = CountdownManager (None )
3643 result = "{}:{}" .format (countdown_manager .minutes , countdown_manager .seconds )
3744 self .assertEqual ("0:0" , result )
3845
3946 def test_subscribe_to_time_changes (self ):
40- countdown_manager = CountdownManager ()
47+ countdown_manager = CountdownManager (None )
4148 result = {"result" : "Times changed to\n " , "increment" : 0 }
4249
4350 def time_change_callback (minutes , seconds ):
0 commit comments