@@ -185,15 +185,12 @@ def reset(self, **kwargs):
185
185
186
186
Args:
187
187
----
188
- **kwargs: Not used in this method. Only exists since this method is
189
- often registered as an event handler which may contain
190
- additional keyword arguments.
188
+ **kwargs: Optional kwargs that may affect the evaluation of the
189
+ timer value placeholder template.
191
190
"""
192
- del kwargs
193
-
194
191
self .debug_log ("Resetting timer. New value: %s" , self .start_value )
195
192
196
- self .jump (self .start_value )
193
+ self .jump (self .start_value , ** kwargs )
197
194
198
195
def start (self , ** kwargs ):
199
196
"""Start this timer based on the starting value that's already been configured.
@@ -246,12 +243,10 @@ def restart(self, **kwargs):
246
243
247
244
Args:
248
245
----
249
- **kwargs: Not used in this method. Only exists since this method is
250
- often registered as an event handler which may contain
251
- additional keyword arguments.
246
+ **kwargs: Optional kwargs that may affect the evaluation of the
247
+ timer value placeholder template.
252
248
"""
253
- del kwargs
254
- self .reset ()
249
+ self .reset (** kwargs )
255
250
# If the timer is not running, start it
256
251
if not self .running :
257
252
self .start ()
@@ -300,16 +295,13 @@ def pause(self, timer_value=0, **kwargs):
300
295
timer_value: How many seconds you want to pause the timer for. Note
301
296
that this pause time is real-world seconds and does not take
302
297
into consideration this timer's tick interval.
303
- **kwargs: Not used in this method. Only exists since this method is
304
- often registered as an event handler which may contain
305
- additional keyword arguments.
298
+ **kwargs: Optional kwargs that may affect the evaluation of the
299
+ timer value placeholder template.
306
300
"""
307
- del kwargs
308
-
309
301
if not timer_value :
310
302
pause_ms = 0 # make sure it's not None, etc.
311
303
else :
312
- pause_ms = self ._get_timer_value (timer_value ) * 1000 # delays happen in ms
304
+ pause_ms = self ._get_timer_value (timer_value , in_ms = True , ** kwargs ) # delays happen in ms
313
305
314
306
self .info_log ("Pausing Timer for %s ms" , pause_ms )
315
307
@@ -417,13 +409,10 @@ def add(self, timer_value, **kwargs):
417
409
----
418
410
timer_value: The number of ticks you want to add to this timer's
419
411
current value.
420
- kwargs: Not used in this method. Only exists since this method is
421
- often registered as an event handler which may contain
422
- additional keyword arguments.
412
+ **kwargs: Optional kwargs that may affect the evaluation of the
413
+ timer value placeholder template.
423
414
"""
424
- del kwargs
425
-
426
- timer_value = self ._get_timer_value (timer_value )
415
+ timer_value = self ._get_timer_value (timer_value , ** kwargs )
427
416
ticks_added = timer_value
428
417
429
418
new_value = self .ticks + ticks_added
@@ -457,13 +446,10 @@ def subtract(self, timer_value, **kwargs):
457
446
----
458
447
timer_value: The number of ticks you want to subtract from this
459
448
timer's current value.
460
- **kwargs: Not used in this method. Only exists since this method is
461
- often registered as an event handler which may contain
462
- additional keyword arguments.
449
+ **kwargs: Optional kwargs that may affect the evaluation of the
450
+ timer value placeholder template.
463
451
"""
464
- del kwargs
465
-
466
- ticks_subtracted = self ._get_timer_value (timer_value )
452
+ ticks_subtracted = self ._get_timer_value (timer_value , ** kwargs )
467
453
468
454
self .ticks -= ticks_subtracted
469
455
@@ -526,10 +512,19 @@ def _remove_system_timer(self):
526
512
self .timer = None
527
513
528
514
@staticmethod
529
- def _get_timer_value (timer_value ):
515
+ def _get_timer_value (timer_value , in_ms = False , ** kwargs ):
516
+ """Return an int value for the number of ticks on the timer."""
517
+ if hasattr (timer_value , "evaluate" ):
518
+ # Convert to int for ticks; config_spec must be float for change_tick_interval
519
+ return int (timer_value .evaluate (kwargs ) * (1000 if in_ms else 1 ))
520
+ return timer_value
521
+
522
+ @staticmethod
523
+ def _get_timer_tick_secs (timer_value , ** kwargs ):
524
+ """Return a float value for the number of seconds between each tick."""
530
525
if hasattr (timer_value , "evaluate" ):
531
526
# Convert to int for ticks; config_spec must be float for change_tick_interval
532
- return int ( timer_value .evaluate ([]) )
527
+ return timer_value .evaluate (kwargs )
533
528
return timer_value
534
529
535
530
def change_tick_interval (self , change = 0.0 , ** kwargs ):
@@ -541,14 +536,10 @@ def change_tick_interval(self, change=0.0, **kwargs):
541
536
tick rate. Note this value is multiplied by the current tick
542
537
interval: >1 will increase the tick interval (slow the timer) and
543
538
<1 will decrease the tick interval (accelerate the timer).
544
- To set an absolute value, use the set_tick_interval() method.
545
- **kwargs: Not used in this method. Only exists since this method is
546
- often registered as an event handler which may contain
547
- additional keyword arguments.
539
+ **kwargs: Optional kwargs that may affect the evaluation of the
540
+ timer value placeholder template.
548
541
"""
549
- del kwargs
550
-
551
- self .tick_secs *= change .evaluate ([])
542
+ self .tick_secs *= change .evaluate (kwargs )
552
543
self ._create_system_timer ()
553
544
554
545
def set_tick_interval (self , timer_value , ** kwargs ):
@@ -561,11 +552,10 @@ def set_tick_interval(self, timer_value, **kwargs):
561
552
----
562
553
timer_value: The new number of seconds between each tick of this
563
554
timer. This value should always be positive.
564
- **kwargs: Not used in this method. Only exists since this method is
565
- often registered as an event handler which may contain
566
- additional keyword arguments.
555
+ **kwargs: Optional kwargs that may affect the evaluation of the
556
+ timer value placeholder template.
567
557
"""
568
- self .tick_secs = abs (self ._get_timer_value (timer_value . evaluate ( kwargs ) ))
558
+ self .tick_secs = abs (self ._get_timer_tick_secs (timer_value , ** kwargs ))
569
559
self ._create_system_timer ()
570
560
571
561
def jump (self , timer_value , ** kwargs ):
@@ -577,13 +567,10 @@ def jump(self, timer_value, **kwargs):
577
567
Args:
578
568
----
579
569
timer_value: Integer of the current value you want this timer to be.
580
- **kwargs: Not used in this method. Only exists since this method is
581
- often registered as an event handler which may contain
582
- additional keyword arguments.
570
+ **kwargs: Optional kwargs that may affect the evaluation of the
571
+ timer value placeholder template.
583
572
"""
584
- del kwargs
585
-
586
- self .ticks = self ._get_timer_value (timer_value )
573
+ self .ticks = self ._get_timer_value (timer_value , ** kwargs )
587
574
588
575
if self .max_value and self .ticks > self .max_value :
589
576
self .ticks = self .max_value
0 commit comments