NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

countdownTimer.py (1340B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\script\util\countdownTimer.py
      2 from carbon.common.script.util.observerNotifier import ObserverNotifier
      3 from carbon.common.script.util.timerstuff import AutoTimer
      4 from gametime import GetWallclockTimeNow, MSEC, SEC
      5 from uthread2 import StartTasklet
      6 
      7 class CountdownTimer(ObserverNotifier):
      8 
      9     def __init__(self, expiration_date, seconds_between_updates = 1.0):
     10         self.milliseconds_between_updates = seconds_between_updates * SEC / MSEC
     11         self.expiration_date = expiration_date
     12         self.timer = None
     13         super(CountdownTimer, self).__init__()
     14 
     15     def get_value(self):
     16         return self.expiration_date - GetWallclockTimeNow()
     17 
     18     def set_expiration_date(self, expiration_date):
     19         self.expiration_date = expiration_date
     20 
     21     def start_updates(self):
     22         if not self.timer:
     23             self.timer = StartTasklet(self._do_timed_updates)
     24 
     25     def stop_updates(self):
     26         if self.timer:
     27             self.timer.KillTimer()
     28             self.timer = None
     29 
     30     def _do_timed_updates(self):
     31         self._notify_of_update()
     32         self.timer = AutoTimer(self.milliseconds_between_updates, self._notify_of_update)
     33 
     34     def _notify_of_update(self):
     35         update = self.get_value()
     36         self._notify_subscribers(update)