bookmarkLocationWindow.py (12337B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\bookmarks\bookmarkLocationWindow.py 2 from collections import defaultdict 3 import eveicon 4 import localization 5 from carbonui import uiconst 6 from carbonui.control.combo import Combo 7 from carbonui.uicore import uicore 8 from eve.client.script.ui import eveColor 9 from eve.common.lib.appConst import MAX_BOOKMARK_NAME_LENGTH, MAX_BOOKMARK_DESCRIPTION_LENGTH 10 from carbon.common.script.util.format import FmtDate 11 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText 12 from carbonui.primitives.container import Container 13 from carbonui.primitives.containerAutoSize import ContainerAutoSize 14 from carbonui.primitives.sprite import Sprite 15 from carbonui.util.sortUtil import SortListOfTuples 16 from carbonui.button.group import ButtonGroup 17 from carbonui.control.checkbox import Checkbox 18 from carbonui.control.radioButton import RadioButton 19 from eve.client.script.ui.control.eveEditPlainText import EditPlainText 20 from eve.client.script.ui.control.eveLabel import EveLabelMedium 21 from carbonui.control.window import Window 22 from eve.client.script.ui.control.infoIcon import MoreInfoIcon 23 from eve.common.script.mgt.bookmarkConst import BOOKMARK_EXPIRY_NONE, BOOKMARK_EXPIRY_4HOURS, BOOKMARK_EXPIRY_2DAYS, BOOKMARK_EXPIRY_24HOURS 24 from eveexceptions import UserError 25 from inventorycommon.const import ownerSystem 26 from localization import GetByLabel 27 from player_messaging.client.ui_message import prompt_player_fsd_dialog 28 BOOKMARK_EXPIRY_STRINGS = {BOOKMARK_EXPIRY_NONE: 'UI/AclBookmarks/ExpireNever', 29 BOOKMARK_EXPIRY_4HOURS: 'UI/AclBookmarks/ExpireIn4Hours', 30 BOOKMARK_EXPIRY_2DAYS: 'UI/AclBookmarks/ExpireIn2Days', 31 BOOKMARK_EXPIRY_24HOURS: 'UI/AclBookmarks/ExpireIn24Hours'} 32 ROW_PADDING = (2, 2, 2, 2) 33 34 class BookmarkLocationWindow(Window): 35 __guid__ = 'form.BookmarkLocationWindow' 36 __notifyevents__ = ['OnRefreshBookmarks'] 37 default_windowID = 'bookmarkLocationWindow' 38 default_width = 340 39 default_height = 340 40 default_minSize = (default_width, default_height) 41 42 def ApplyAttributes(self, attributes): 43 Window.ApplyAttributes(self, attributes) 44 self.locationID = attributes.get('locationID') 45 locationName = attributes.get('locationName') 46 note = attributes.get('note', '') 47 self.typeID = attributes.get('typeID') 48 self.scannerInfo = attributes.get('scannerInfo') 49 self.parentID = attributes.get('parentID') 50 self.bookmark = attributes.get('bookmark') 51 self.expireIn = None 52 self.expiryCancel = 0 53 self.folderSelection = None 54 if self.bookmark is None: 55 self.caption = GetByLabel('UI/PeopleAndPlaces/NewBookmark') 56 else: 57 self.caption = GetByLabel('UI/PeopleAndPlaces/EditLocation') 58 mainCont = Container(name='mainCont', parent=self.sr.main, align=uiconst.TOALL) 59 labelContainer = ContainerAutoSize(name='labelContainer', parent=mainCont, align=uiconst.TOTOP, alignMode=uiconst.TOTOP) 60 EveLabelMedium(text=GetByLabel('UI/PeopleAndPlaces/Label'), parent=labelContainer, align=uiconst.CENTERLEFT, width=60) 61 self.labelEdit = SingleLineEditText(name='labelEdit', setvalue=locationName, parent=labelContainer, align=uiconst.TOTOP, padLeft=60, autoselect=True, maxLength=MAX_BOOKMARK_NAME_LENGTH, OnReturn=self.Confirm) 62 uicore.registry.SetFocus(self.labelEdit) 63 self.forcedFolderID = None 64 if self.bookmark is None: 65 self.folderSelection = settings.char.ui.Get('bookmarkFolderAndSubfolder', (None, None)) 66 else: 67 self.folderSelection = (self.bookmark.folderID, self.bookmark.subfolderID) 68 self.forcedFolderID = self.bookmark.folderID 69 self._AddExpiryContainer(mainCont) 70 folderContainer = ContainerAutoSize(name='folderContainer', parent=mainCont, align=uiconst.TOBOTTOM, alignMode=uiconst.TOTOP, top=8) 71 EveLabelMedium(parent=Container(parent=folderContainer, align=uiconst.TOLEFT, width=60), align=uiconst.CENTERLEFT, text=GetByLabel('UI/PeopleAndPlaces/Folder')) 72 folders = attributes.get('folders') 73 subfolders = attributes.get('subfolders') 74 options, personalFolderFound = self.GetFolderAndSubfolderOptions(folders, subfolders) 75 self.noPersonalFolderWarningIcon = ContainerAutoSize(name='warningIcon', parent=folderContainer, align=uiconst.TOLEFT, padding=(0, 0, 4, 0)) 76 Sprite(parent=self.noPersonalFolderWarningIcon, align=uiconst.CENTER, state=uiconst.UI_NORMAL, width=16, height=16, texturePath='res:/UI/Texture/classes/agency/iconExclamation.png', color=eveColor.WARNING_ORANGE, hint=GetByLabel('UI/AclBookmarks/NoPersonalFolderAvailable')) 77 if personalFolderFound: 78 self.noPersonalFolderWarningIcon.display = False 79 else: 80 self.noPersonalFolderWarningIcon.display = True 81 self.folderCombo = Combo(name='folderCombo', parent=folderContainer, align=uiconst.TOTOP, select=self.folderSelection, options=options, callback=self.OnFolderChange) 82 descriptionContainer = Container(name='descriptionContainer', parent=mainCont, align=uiconst.TOALL, top=8, padding=(0, 0, 0, 8)) 83 EveLabelMedium(text=GetByLabel('UI/PeopleAndPlaces/Notes'), parent=descriptionContainer, align=uiconst.TOLEFT, width=60) 84 self.notesEdit = EditPlainText(name='notesEdit', parent=descriptionContainer, align=uiconst.TOALL, setvalue=note, maxLength=MAX_BOOKMARK_DESCRIPTION_LENGTH, countWithTags=True) 85 buttonGroup = ButtonGroup(name='buttonGroup', parent=self.sr.main, idx=0) 86 submitButton = buttonGroup.AddButton(label=GetByLabel('UI/Common/Submit'), func=self.Confirm) 87 buttonGroup.AddButton(label=GetByLabel('UI/Common/Cancel'), func=self.Cancel) 88 submitButton.OnSetFocus() 89 90 def _AddExpiryContainer(self, parent): 91 if self.bookmark is None: 92 self.expiryContainer = ContainerAutoSize(name='expiryContainer', parent=parent, align=uiconst.TOBOTTOM, alignMode=uiconst.TOTOP, top=8) 93 self._LoadExpiryOptions() 94 else: 95 expiryContainer = ContainerAutoSize(name='expiryContainer', parent=parent, align=uiconst.TOBOTTOM, alignMode=uiconst.TOTOP, top=8) 96 EveLabelMedium(parent=expiryContainer, align=uiconst.TOLEFT, width=60, text=GetByLabel('UI/AclBookmarks/AutoExpire')) 97 if self.bookmark.expiry: 98 label = FmtDate(self.bookmark.expiry, 'ls') 99 else: 100 label = GetByLabel(BOOKMARK_EXPIRY_STRINGS[BOOKMARK_EXPIRY_NONE]) 101 EveLabelMedium(text=label, parent=expiryContainer, align=uiconst.TOTOP) 102 if self.bookmark.expiry: 103 self.expiryResetCheckBox = Checkbox(parent=expiryContainer, align=uiconst.TOTOP, text=GetByLabel('UI/AclBookmarks/CancelAutomatedExpiry'), settingsKey='isPersonal', checked=False, callback=self.OnExpiryCancelCheckBoxChange) 104 105 def _LoadExpiryOptions(self): 106 self.expiryContainer.Flush() 107 folderID, subfolderID = self.folderSelection 108 self.expireIn = settings.char.ui.Get('bookmarkExpiryByFolder_%s_%s' % (folderID, subfolderID), 0) 109 EveLabelMedium(text=GetByLabel('UI/AclBookmarks/AutoExpire'), parent=self.expiryContainer, align=uiconst.TOLEFT, width=60) 110 infoContainer = Container(name='infoContainer', parent=self.expiryContainer, align=uiconst.TORIGHT, width=24) 111 MoreInfoIcon(parent=infoContainer, hint=GetByLabel('UI/AclBookmarks/ExpiryOptionsHelpText'), align=uiconst.CENTER) 112 for expiryConst in (BOOKMARK_EXPIRY_NONE, 113 BOOKMARK_EXPIRY_2DAYS, 114 BOOKMARK_EXPIRY_24HOURS, 115 BOOKMARK_EXPIRY_4HOURS): 116 RadioButton(parent=self.expiryContainer, align=uiconst.TOTOP, text=GetByLabel(BOOKMARK_EXPIRY_STRINGS[expiryConst]), groupname='expirySelection', settingsKey='isPersonal', checked=self.expireIn == expiryConst, retval=expiryConst, callback=self.OnExpiryCheckBoxChange) 117 118 def GetFolderAndSubfolderOptions(self, folders, subfolders): 119 optionsTemp = [] 120 options = [] 121 personalFolderFound = False 122 for folder in folders: 123 if folder.isPersonal: 124 personalFolderFound = True 125 activeStr = GetByLabel('UI/AclBookmarks/Active') if folder.isActive else GetByLabel('UI/AclBookmarks/NotActive') 126 label = folder.folderName + ' (' + activeStr + ')' 127 sortKey = (-folder.isPersonal, -folder.isActive, label.lower()) 128 data = (label, folder) 129 optionsTemp.append((sortKey, data)) 130 131 optionsTemp = SortListOfTuples(optionsTemp) 132 subFoldersByParentFolderID = defaultdict(list) 133 for subfolder in subfolders: 134 subFoldersByParentFolderID[subfolder.folderID].append(subfolder) 135 136 for label, folder in optionsTemp: 137 currentFolderID = folder.folderID 138 isPersonal = folder.isPersonal 139 returnValue = (currentFolderID, None) 140 if isPersonal: 141 texturePath = eveicon.folder 142 hint = GetByLabel('UI/AclBookmarks/PersonalFolderType') 143 else: 144 texturePath = eveicon.shared_folder 145 hint = GetByLabel('UI/AclBookmarks/SharedFolderType') 146 options.append((label, 147 returnValue, 148 hint, 149 texturePath)) 150 sub = subFoldersByParentFolderID[currentFolderID] 151 subfolderOptions = [] 152 for eachSubFolder in sub: 153 if eachSubFolder.creatorID == ownerSystem: 154 continue 155 x = (eachSubFolder.subfolderName, 156 (eachSubFolder.folderID, eachSubFolder.subfolderID), 157 hint, 158 texturePath, 159 1) 160 subfolderOptions.append(x) 161 162 subfolderOptions = localization.util.Sort(subfolderOptions, key=lambda x: x[0].lower()) 163 options.extend(subfolderOptions) 164 165 return (options, personalFolderFound) 166 167 def OnRefreshBookmarks(self): 168 folders, subfolders = sm.GetService('bookmarkSvc').GetFilteredFoldersAndSubfolders(self.forcedFolderID) 169 options, personalFolderFound = self.GetFolderAndSubfolderOptions(folders, subfolders) 170 if options: 171 self.folderCombo.entries = options 172 if personalFolderFound: 173 self.noPersonalFolderWarningIcon.display = False 174 else: 175 self.noPersonalFolderWarningIcon.display = True 176 else: 177 prompt_player_fsd_dialog('CustomNotify', {'notify': GetByLabel('UI/AclBookmarks/NoValidFolder')}) 178 self.Close() 179 180 def OnFolderChange(self, combo, text, value): 181 self.folderSelection = value 182 if self.bookmark is None: 183 self._LoadExpiryOptions() 184 185 def OnExpiryCheckBoxChange(self, checkbox): 186 self.expireIn = checkbox.GetReturnValue() 187 188 def OnExpiryCancelCheckBoxChange(self, checkbox): 189 self.expiryCancel = checkbox.checked 190 191 def Confirm(self, *args): 192 label = self.labelEdit.GetValue() 193 if label.strip() == '': 194 raise UserError('CustomInfo', {'info': GetByLabel('UI/Map/MapPallet/msgPleaseTypeSomething')}) 195 label = label.replace('\t', ' ') 196 note = self.notesEdit.GetValue() 197 self._ConfirmAclBookmark(label, note) 198 self.Close() 199 200 def _ConfirmAclBookmark(self, label, note): 201 folderID, subfolderID = self.folderCombo.GetValue() 202 if self.bookmark is None: 203 if self.scannerInfo is not None: 204 sm.GetService('bookmarkSvc').ACLBookmarkScanResult(self.locationID, label, note, self.scannerInfo.id, folderID, self.expireIn, subfolderID=subfolderID) 205 else: 206 sm.GetService('bookmarkSvc').ACLBookmarkLocation(self.locationID, folderID, label, note, self.typeID, self.expireIn, subfolderID=subfolderID) 207 settings.char.ui.Set('bookmarkExpiryByFolder_%s_%s' % (folderID, subfolderID), self.expireIn) 208 else: 209 sm.GetService('bookmarkSvc').UpdateACLBookmark(self.bookmark.bookmarkID, self.bookmark.folderID, label, note, subfolderID, folderID, self.expiryCancel) 210 settings.char.ui.Set('bookmarkFolderAndSubfolder', (folderID, subfolderID)) 211 212 def Cancel(self, *args): 213 self.Close()