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

focusUtil.py (1445B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\util\focusUtil.py
      2 import carbonui.const as uiconst
      3 import trinity
      4 import logging
      5 from eveexceptions.exceptionEater import ExceptionEater
      6 from carbonui.uicore import uicore
      7 logger = logging.getLogger(__name__)
      8 isFocused = False
      9 registeredToFocusEvent = False
     10 postponedFunctionCalls = []
     11 
     12 def RegisterToFocusEvent():
     13     global registeredToFocusEvent
     14     global isFocused
     15     if not registeredToFocusEvent:
     16         registeredToFocusEvent = True
     17         isFocused = trinity.app.IsActive()
     18         uicore.event.RegisterForTriuiEvents(uiconst.UI_ACTIVE, HandleAppFocus)
     19 
     20 
     21 def CallPostponedFunctions():
     22     global postponedFunctionCalls
     23     if len(postponedFunctionCalls) > 0:
     24         logger.debug('Running postponed functions')
     25         for function, args, kwargs in postponedFunctionCalls:
     26             with ExceptionEater('Failed to run a postponed function'):
     27                 function(*args, **kwargs)
     28 
     29         postponedFunctionCalls = []
     30 
     31 
     32 def HandleAppFocus(wnd, msgID, vkey):
     33     global isFocused
     34     isFocused = vkey[0]
     35     if isFocused:
     36         CallPostponedFunctions()
     37     return 1
     38 
     39 
     40 def postponeUntilFocus(func):
     41 
     42     def wrappedFunc(*args, **kwargs):
     43         RegisterToFocusEvent()
     44         if not isFocused:
     45             postponedFunctionCalls.append((func, args, kwargs))
     46         else:
     47             func(*args, **kwargs)
     48 
     49     return wrappedFunc