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

player.py (1567B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\heronotification\player.py
      2 import uthread
      3 from stacklesslib.locks import NLCondition
      4 
      5 class HeroNotificationPlayer(object):
      6 
      7     class _State(object):
      8         INIT = 1
      9         PLAYING = 2
     10         DONE = 3
     11 
     12     def __init__(self, hero_notification, container, cancellation_token):
     13         self._hero_notification = hero_notification
     14         self._container = container
     15         self._state = self._State.INIT
     16         self._tasklet = None
     17         self._cancellation_token = cancellation_token
     18         self._done_condition = NLCondition()
     19 
     20     @property
     21     def done(self):
     22         return self._state == self._State.DONE
     23 
     24     def start(self):
     25         if self._state == self._State.INIT:
     26             if self._cancellation_token.cancelled:
     27                 self._to_done()
     28             else:
     29                 self._state = self._State.PLAYING
     30                 self._tasklet = uthread.new(self._play_hero_notification)
     31 
     32     def cancel(self):
     33         self._cancellation_token.cancel()
     34 
     35     def wait(self, timeout = None):
     36         if not self.done:
     37             self._done_condition.wait(timeout)
     38 
     39     def _play_hero_notification(self):
     40         try:
     41             self._hero_notification(self._container, self._cancellation_token)
     42         finally:
     43             self._to_done()
     44             self._tasklet = None
     45             self._container.Close()
     46             self._container = None
     47 
     48     def _to_done(self):
     49         self._state = self._State.DONE
     50         self._done_condition.notify_all()