namedPopup.py (4926B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\util\namedPopup.py 2 import localization 3 import carbonui.const as uiconst 4 from carbonui.control.singlelineedits.singleLineEditPassword import SingleLineEditPassword 5 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText 6 from carbonui.primitives.containerAutoSize import ContainerAutoSize 7 from carbonui.uicore import uicore 8 from carbonui.primitives.container import Container 9 from eve.client.script.ui.control import eveLabel 10 from carbonui.button.group import ButtonGroup 11 from carbonui.control.window import Window 12 from carbonui.control.singlelineedits.prefixed import PrefixedSingleLineEdit 13 from eve.common.lib import appConst as const 14 from player_messaging.client.ui_message import prompt_player_fsd_dialog 15 16 class NamePopupWnd(Window): 17 __guid__ = 'form.NamePopupWnd' 18 default_width = 360 19 default_height = 160 20 default_minSize = (default_width, default_height) 21 default_windowID = 'setNewName' 22 default_maxLength = None 23 default_body = None 24 25 def ApplyAttributes(self, attributes): 26 self._mainCont = None 27 Window.ApplyAttributes(self, attributes) 28 caption = attributes.get('caption', None) 29 if caption is None: 30 caption = localization.GetByLabel('UI/Common/Name/TypeInName') 31 self.SetCaption(caption) 32 self.MakeUnResizeable() 33 self.label = attributes.get('label', None) 34 if self.label is None: 35 self.label = localization.GetByLabel('UI/Common/Name/TypeInName') 36 self.body = attributes.get('body', self.default_body) 37 self.setvalue = attributes.get('setvalue', '') 38 self.maxLength = attributes.get('maxLength', self.default_maxLength) 39 self.passwordChar = attributes.get('passwordChar', None) 40 self.prefix = attributes.get('prefix', None) 41 self.funcValidator = attributes.get('validator', None) or self.CheckName 42 self.ConstructLayout() 43 44 def ConstructLayout(self): 45 self.AddMainContainer() 46 self.AddBody(parent=self._mainCont) 47 self.AddLabel() 48 self.AddLineEdit(parent=self._mainCont, padding=0) 49 self.AddExtra(parent=self._mainCont) 50 self.AddButtons() 51 uicore.registry.SetFocus(self.newName) 52 53 def AddMainContainerOld(self): 54 return Container(parent=self.sr.main, align=uiconst.TOALL, pos=(const.defaultPadding, 55 16, 56 const.defaultPadding, 57 const.defaultPadding)) 58 59 def AddMainContainer(self): 60 self._mainCont = ContainerAutoSize(parent=self.GetMainArea(), align=uiconst.TOTOP, callback=self._OnContentSizeChanged) 61 62 def AddBody(self, parent): 63 if not self.body: 64 return 65 leftPad, _, rightPad, _ = self.content_padding 66 eveLabel.EveLabelMedium(parent=ContainerAutoSize(parent=parent, align=uiconst.TOTOP, padTop=8, padBottom=16), align=uiconst.TOPLEFT, text=self.body, width=self.width - leftPad - rightPad) 67 68 def AddLabel(self): 69 eveLabel.EveLabelMedium(parent=ContainerAutoSize(parent=self._mainCont, align=uiconst.TOTOP, padBottom=8), align=uiconst.TOPLEFT, text=self.label) 70 71 def AddLineEdit(self, parent, padding): 72 if self.prefix: 73 editClass = PrefixedSingleLineEdit 74 elif self.passwordChar: 75 editClass = SingleLineEditPassword 76 else: 77 editClass = SingleLineEditText 78 self.newName = editClass(name='namePopup', parent=parent, align=uiconst.TOTOP, setvalue=self.setvalue, maxLength=self.maxLength, passwordCharacter=self.passwordChar, autoselect=True, prefix=self.prefix, OnReturn=self.Confirm, padding=padding, showLetterCounter=bool(self.maxLength)) 79 80 def AddExtra(self, parent): 81 pass 82 83 def AddButtons(self): 84 buttons = ButtonGroup(parent=ContainerAutoSize(parent=self._mainCont, align=uiconst.TOTOP, padTop=8), align=uiconst.CENTER) 85 buttons.AddButton(label=localization.GetByLabel('UI/Common/Buttons/OK'), func=self.Confirm) 86 buttons.AddButton(label=localization.GetByLabel('UI/Common/Buttons/Cancel'), func=self.Cancel) 87 88 def _OnContentSizeChanged(self): 89 _, self.height = self.GetWindowSizeForContentSize(height=self._mainCont.height) 90 91 def CheckName(self, name, *args): 92 name = self.newName.GetValue() 93 if not len(name) or len(name) and len(name.strip()) < 1: 94 return localization.GetByLabel('UI/Common/PleaseTypeSomething') 95 96 def Confirm(self, *args): 97 if not hasattr(self, 'newName'): 98 return 99 newName = self.newName.GetValue() 100 error = self.funcValidator(newName) 101 if error: 102 prompt_player_fsd_dialog('CustomInfo', {'info': error}) 103 else: 104 self.result = newName 105 self.SetModalResult(1) 106 107 def Cancel(self, *args): 108 self.result = None 109 self.SetModalResult(0)