messageboxWithTimeout.py (2201B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\messageboxWithTimeout.py 2 import uthread 3 import blue 4 import log 5 from carbonui import uiconst 6 from eve.client.script.ui import eveColor 7 from eve.client.script.ui.control import eveLabel 8 from localization import GetByLabel 9 from eve.client.script.ui.control.eveLabel import Label 10 from eve.client.script.ui.shared.messagebox import MessageBox 11 from carbon.common.lib.const import SEC as SECONDS 12 from gametime import GetSimTime 13 DEFAULT_TIMEOUT = 20 14 MIN_TIMEOUT = 5 15 MAX_TIMEOUT = 60 16 17 class MessageBoxWithTimeout(MessageBox): 18 __guid__ = 'form.MessageBoxWithTimeout' 19 __nonpersistvars__ = ['suppress'] 20 21 def ApplyAttributes(self, attributes): 22 MessageBox.ApplyAttributes(self, attributes) 23 self.timeout = attributes.get('timeout', DEFAULT_TIMEOUT) 24 if not MIN_TIMEOUT <= self.timeout < MAX_TIMEOUT: 25 self.timeout = max(min(self.timeout, MAX_TIMEOUT), MIN_TIMEOUT) 26 log.LogWarn('MessageBoxWithTimeout: %s specifies an unreasonable timeout value of %d. Capping it to %d.' % (self.msgKey, attributes.get('timeout', DEFAULT_TIMEOUT), self.timeout)) 27 28 def _show_message(self, text, title, buttons, icon, suppText, default = None, modal = True, okLabel = None, cancelLabel = None, isClosable = True, is_suppressable = False): 29 super(MessageBoxWithTimeout, self)._show_message(text, title, buttons, icon, suppText, default, modal, okLabel, cancelLabel, isClosable, is_suppressable) 30 self.timeoutLabel = eveLabel.EveLabelMedium(parent=self.sr.main, idx=1, align=uiconst.TOBOTTOM, text='', color=eveColor.DANGER_RED, padding=8) 31 self.height += 20 32 33 def ShowModal(self): 34 uthread.new(self._TimeoutThread) 35 return MessageBox.ShowModal(self) 36 37 def _TimeoutThread(self): 38 now = GetSimTime() 39 timeoutAt = now + self.timeout * SECONDS 40 while now < timeoutAt: 41 self.timeoutLabel.SetText(GetByLabel('UI/Generic/OperationWillBeCanceledIn', time=timeoutAt - now)) 42 blue.pyos.synchro.SleepSim(450) 43 now = GetSimTime() 44 45 if self.IsOpen(): 46 self.CloseByUser()