addressBookWindow.py (16454B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\addressBookWindow.py 2 import carbonui.const as uiconst 3 import eve.client.script.ui.util.searchUtil as searchUtil 4 import eveicon 5 import localization 6 import locks 7 import threadutils 8 import uthread 9 import utillib 10 from carbonui.control.button import Button 11 from carbonui import ButtonVariant 12 from carbonui.control.combo import Combo 13 from carbonui.control.contextMenu.menuData import MenuData 14 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText 15 from carbonui.control.window import Window 16 from carbonui.primitives.container import Container 17 from carbonui.primitives.containerAutoSize import ContainerAutoSize 18 from clientsettings.setting import CharSettingEnum 19 from carbonui.uicore import uicore 20 from carbonui.util.various_unsorted import SortListOfTuples 21 from eve.client.script.ui.control import eveScroll 22 from eve.client.script.ui.control.allUserEntries import AllUserEntries 23 from eve.client.script.ui.control.entries.util import GetFromClass 24 from eve.client.script.ui.control.eveScroll import Scroll 25 from eve.client.script.ui.control.listgroup import ListGroup 26 from carbonui.button.menu import MenuButtonIcon 27 from eve.client.script.ui.control.themeColored import SpriteThemeColored 28 from carbonui.window.header.tab_navigation import TabNavigationWindowHeader 29 from eve.client.script.ui.shared.neocom.addressBook.contactsConst import TAB_AGENTS, TAB_BOOKMARKS, TAB_CONTACTS, TAB_SEARCH 30 from eve.client.script.ui.shared.neocom.addressBook.contactsForm import ContactsForm 31 from eve.client.script.ui.shared.userentry import AgentEntry 32 from eve.common.script.search.const import ResultType, MatchBy 33 DEFAULT_SEARCH_STYLE = MatchBy.partial_terms 34 grplst = [[localization.GetByLabel('UI/Common/Any'), -1], 35 [localization.GetByLabel('UI/Agents/Agent'), ResultType.agent], 36 [localization.GetByLabel('UI/Common/Character'), ResultType.character], 37 [localization.GetByLabel('UI/Common/Corporation'), ResultType.corporation], 38 [localization.GetByLabel('UI/Common/Alliance'), ResultType.alliance], 39 [localization.GetByLabel('UI/Common/Faction'), ResultType.faction], 40 [localization.GetByLabel('UI/Common/LocationTypes/Station'), ResultType.station], 41 [localization.GetByLabel('UI/Common/LocationTypes/Structures'), ResultType.structure_with_inlined_data], 42 [localization.GetByLabel('UI/Common/LocationTypes/SolarSystem'), ResultType.solar_system], 43 [localization.GetByLabel('UI/Common/LocationTypes/Constellation'), ResultType.constellation], 44 [localization.GetByLabel('UI/Common/LocationTypes/Region'), ResultType.region]] 45 46 class AddressBookWindow(Window): 47 default_width = 600 48 default_height = 500 49 default_minSize = (320, 307) 50 default_windowID = 'addressbook' 51 default_captionLabelPath = 'UI/PeopleAndPlaces/WindowTitle' 52 default_descriptionLabelPath = 'Tooltips/Neocom/Contacts_description' 53 default_iconNum = 'res:/ui/Texture/WindowIcons/peopleandplaces.png' 54 55 def ApplyAttributes(self, attributes): 56 super(AddressBookWindow, self).ApplyAttributes(attributes) 57 self.inited = 0 58 self.tabGroup = self.header.tab_group 59 self.scroll = eveScroll.Scroll(parent=self.sr.main) 60 self.contactsPanel = ContactsForm(name='contactsform', parent=self.sr.main, contactType=TAB_CONTACTS) 61 self.searchPanel = SearchPanel(parent=self.content, align=uiconst.TOALL) 62 self.agentsBtnGroup = ContainerAutoSize(parent=self.content, align=uiconst.TOBOTTOM, idx=0, padTop=8) 63 Button(parent=self.agentsBtnGroup, align=uiconst.CENTERLEFT, label=localization.GetByLabel('UI/PeopleAndPlaces/CreateFolder'), texturePath=eveicon.add_folder, func=lambda : self.AddGroup('agentgroups'), args=(), variant=ButtonVariant.GHOST) 64 self.scroll.sr.content.OnDropData = self.OnDropData 65 idx = settings.user.tabgroups.Get('addressbookpanel', None) 66 if idx is None: 67 settings.user.tabgroups.Set('addressbookpanel', 4) 68 self.ConstructTabs() 69 self.inited = 1 70 71 def Prepare_Header_(self): 72 self.header = TabNavigationWindowHeader() 73 74 def ConstructTabs(self): 75 self.tabGroup.AddTab(localization.GetByLabel('UI/PeopleAndPlaces/Contacts'), self.contactsPanel, self, tabID=TAB_CONTACTS) 76 self.tabGroup.AddTab(localization.GetByLabel('UI/PeopleAndPlaces/Agents'), self.scroll, self, tabID=TAB_AGENTS) 77 self.tabGroup.AddTab(label=localization.GetByLabel('UI/Common/Search'), panel=self.searchPanel, code=self, tabID=TAB_SEARCH) 78 self.tabGroup.AutoSelect() 79 self.tabGroup.sr.Get('%s_tab' % localization.GetByLabel('UI/PeopleAndPlaces/Agents'), None).OnTabDropData = self.DropInAgents 80 self.tabGroup.sr.Get('%s_tab' % localization.GetByLabel('UI/PeopleAndPlaces/Contacts'), None).OnTabDropData = self.DropInPersonalContact 81 82 def ConstructSearchPanel(self): 83 searchPanel = Container(name='topParent', parent=self.sr.main, align=uiconst.TOTOP, clipChildren=True) 84 SpriteThemeColored(name='mainicon', parent=searchPanel, state=uiconst.UI_DISABLED, pos=(0, -3, 64, 64), texturePath=self.iconNum, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW) 85 searchTypeCombo = Combo(label=localization.GetByLabel('UI/Common/SearchType'), parent=searchPanel, options=grplst, name='addressBookComboSearchType', select=settings.user.ui.Get('ppSearchGroup', -1), width=86, left=74, top=20, callback=self.ChangeSearchGroup) 86 self.searchEdit = SingleLineEditText(name='search', parent=searchPanel, maxLength=100, left=searchTypeCombo.left + searchTypeCombo.width + 6, top=searchTypeCombo.top, width=86, label=localization.GetByLabel('UI/PeopleAndPlaces/SearchString')) 87 Button(parent=searchPanel, label=localization.GetByLabel('UI/Common/Buttons/Search'), pos=(self.searchEdit.left + self.searchEdit.width + 2, 88 self.searchEdit.top, 89 0, 90 0), func=self.Search, btn_default=1) 91 self.searchByCombo = Combo(label=localization.GetByLabel('UI/Common/SearchBy'), parent=searchPanel, options=searchUtil.GetSearchByChoices(), name='addressBookComboSearchBy', select=settings.user.ui.Get('ppSearchBy', DEFAULT_SEARCH_STYLE), width=233, left=75, top=self.searchEdit.top + self.searchEdit.height + 2, labelleft=searchTypeCombo.left + searchTypeCombo.width + 6 - 75, callback=self.ChangeSearchBy) 92 searchPanel.height = max(52, self.searchByCombo.top + self.searchByCombo.height) 93 94 def DropInAgents(self, *args): 95 sm.GetService('addressbook').DropInAgents(*args) 96 97 def DropInPersonalContact(self, *args): 98 sm.GetService('addressbook').DropInPersonalContact(*args) 99 100 def DropInBuddyGroup(self, *args): 101 sm.GetService('addressbook').DropInBuddyGroup(*args) 102 103 def OnDropData(self, dragObj, nodes): 104 self.ShowLoad() 105 try: 106 visibletab = self.tabGroup.GetSelectedTab() 107 if visibletab and hasattr(visibletab, 'OnTabDropData'): 108 visibletab.OnTabDropData(dragObj, nodes) 109 finally: 110 if self is not None and not self.destroyed and self.inited: 111 self.HideLoad() 112 113 def AddGroup(self, listID, *args): 114 uicore.registry.AddListGroup(listID) 115 self.RefreshWindow() 116 117 def RefreshWindow(self): 118 if not self.destroyed and self.inited: 119 self.tabGroup.ReloadVisible() 120 121 def ChangeSearchGroup(self, entry, header, value, *args): 122 settings.user.ui.Set('ppSearchGroup', value) 123 124 def ChangeSearchBy(self, entry, header, value, *args): 125 settings.user.ui.Set('ppSearchBy', value) 126 127 def Search(self, *args): 128 groupID = settings.user.ui.Get('ppSearchGroup', -1) 129 if groupID == -1: 130 groupIDList = [ResultType.agent, 131 ResultType.character, 132 ResultType.corporation, 133 ResultType.alliance, 134 ResultType.faction, 135 ResultType.station, 136 ResultType.solar_system, 137 ResultType.constellation, 138 ResultType.region, 139 ResultType.structure_with_inlined_data] 140 else: 141 groupIDList = [groupID] 142 exactSearch = settings.user.ui.Get('ppSearchBy', DEFAULT_SEARCH_STYLE) 143 searchUtil.GetResultsInNewWindow(self.searchEdit.GetValue().strip(), groupIDList, searchBy=exactSearch, searchWndName='addressBookSearch') 144 145 def Load(self, args): 146 uthread.Lock(self, 'load') 147 try: 148 self.agentsBtnGroup.state = uiconst.UI_HIDDEN 149 self.scroll.sr.iconMargin = 0 150 self.scroll.sr.id = '%sAddressBookScroll' % args 151 self.scroll.sr.ignoreTabTrimming = 1 152 if args == TAB_AGENTS: 153 self.ShowAgents() 154 elif args == TAB_BOOKMARKS: 155 self.ShowPlacesNew() 156 self.lastTab = args 157 finally: 158 uthread.UnLock(self, 'load') 159 160 def ShowAgents(self): 161 self.agentsBtnGroup.state = uiconst.UI_PICKCHILDREN 162 all_agents_group = uicore.registry.GetListGroup(('agentgroups', 'all')) 163 uicore.registry.GetLockedGroup(listID='agentgroups', listgroupName='all', label=localization.GetByLabel('UI/PeopleAndPlaces/AllAgents'), openState=all_agents_group.get('open', True)) 164 scrollData = self._GetAgentScrollData() 165 scrolllist = [] 166 for s in scrollData: 167 scrolllist.append((s.sortBy.lower(), GetFromClass(ListGroup, {'GetSubContent': self.GetAgentsSubContent, 168 'DropData': self.DropInBuddyGroup, 169 'RefreshScroll': self.RefreshWindow, 170 'label': s.label, 171 'id': s.id, 172 'groupItems': s.groupItems, 173 'headers': [localization.GetByLabel('UI/Common/Name')], 174 'iconMargin': 18, 175 'showlen': 1, 176 'state': s.state, 177 'npc': True, 178 'allowCopy': 1, 179 'showicon': s.logo, 180 'allowGuids': AllUserEntries()}))) 181 182 self.scroll.sr.iconMargin = 18 183 scrolllist = SortListOfTuples(scrolllist) 184 self.scroll.Load(contentList=scrolllist, fixedEntryHeight=None, headers=[localization.GetByLabel('UI/Common/Name')], scrolltotop=not getattr(self, 'personalshown', 0), noContentHint=localization.GetByLabel('UI/PeopleAndPlaces/NoAgents')) 185 setattr(self, 'personalshown', 1) 186 if not self.destroyed: 187 self.HideLoad() 188 189 def _GetAgentScrollData(self): 190 agents = sm.GetService('addressbook').GetAgents() 191 scrollData = [] 192 groups = uicore.registry.GetListGroups('agentgroups') 193 for g in groups.iteritems(): 194 key = g[0] 195 data = utillib.KeyVal(g[1]) 196 if key == 'all': 197 data.sortBy = [' 1', ' 2'][key == 'allcorps'] 198 data.groupItems = agents 199 else: 200 data.sortBy = data.label 201 data.state = None 202 data.groupItems = filter(lambda charID: charID in agents, data.groupItems) 203 data.logo = 'res:/UI/Texture/WindowIcons/agent.png' 204 scrollData.append(data) 205 206 return scrollData 207 208 def ShowPlacesNew(self): 209 self.bookmarksPanel.Setup() 210 211 def GetAgentsSubContent(self, nodedata, newitems = 0): 212 if not len(nodedata.groupItems): 213 return [] 214 charsToPrime = [] 215 for charID in nodedata.groupItems: 216 charsToPrime.append(charID) 217 218 cfg.eveowners.Prime(charsToPrime) 219 agents = sm.GetService('addressbook').GetAgents() 220 scrolllist = [] 221 for charID in nodedata.groupItems: 222 if charID in agents: 223 scrolllist.append(GetFromClass(AgentEntry, {'listGroupID': nodedata.id, 224 'charID': charID, 225 'info': cfg.eveowners.Get(charID)})) 226 227 scrolllist = localization.util.Sort(scrolllist, key=lambda x: x['info'].ownerName) 228 return scrolllist 229 230 231 class SearchType(object): 232 all = 0 233 character = 1 234 corporation = 2 235 alliance = 3 236 agent = 4 237 faction = 5 238 _RESULT_TYPE_BY_SEARCH_TYPE = {character: ResultType.character, 239 corporation: ResultType.corporation, 240 alliance: ResultType.alliance, 241 agent: ResultType.agent, 242 faction: ResultType.faction} 243 _DISPLAY_NAME_BY_SEARCH_TYPE = {all: localization.GetByLabel('UI/Common/Any'), 244 character: localization.GetByLabel('UI/Common/Character'), 245 corporation: localization.GetByLabel('UI/Common/Corporation'), 246 alliance: localization.GetByLabel('UI/Common/Alliance'), 247 agent: localization.GetByLabel('UI/Agents/Agent'), 248 faction: localization.GetByLabel('UI/Common/Faction')} 249 250 @classmethod 251 def as_result_type_list(cls, search_type): 252 if search_type == cls.all: 253 return [ResultType.character, 254 ResultType.corporation, 255 ResultType.alliance, 256 ResultType.agent, 257 ResultType.faction] 258 else: 259 return [cls._RESULT_TYPE_BY_SEARCH_TYPE[search_type]] 260 261 @classmethod 262 def display_name(cls, search_type): 263 return cls._DISPLAY_NAME_BY_SEARCH_TYPE[search_type] 264 265 @classmethod 266 def iter(cls): 267 for name in dir(cls): 268 if name.startswith('_'): 269 continue 270 value = getattr(cls, name) 271 if isinstance(value, int): 272 yield value 273 274 275 SORT_KEY_BY_SEARCH_TYPE = {SearchType.all: 0, 276 SearchType.character: 1, 277 SearchType.agent: 2, 278 SearchType.corporation: 3, 279 SearchType.alliance: 4, 280 SearchType.faction: 5} 281 search_type_setting = CharSettingEnum(settings_key='contacts_window_search_type', default_value=SearchType.all, options=frozenset(SearchType.iter())) 282 search_by_setting = CharSettingEnum(settings_key='contacts_window_search_by', default_value=MatchBy.partial_terms, options=frozenset((value for _, value in searchUtil.SEARCHBY_OPTIONS))) 283 284 class SearchPanel(Container): 285 286 def __init__(self, parent, align): 287 self._loaded = False 288 self._search_input = None 289 self._results_scroll = None 290 self._search_lock = locks.Lock() 291 super(SearchPanel, self).__init__(parent=parent, align=align) 292 293 def load(self): 294 self._loaded = True 295 search_cont = Container(parent=self, align=uiconst.TOTOP, height=32, padBottom=16) 296 MenuButtonIcon(parent=ContainerAutoSize(parent=search_cont, align=uiconst.TORIGHT, padLeft=8), align=uiconst.CENTER, get_menu_func=self._get_search_settings_menu, texturePath=eveicon.tune, hint=localization.GetByLabel('UI/Common/Settings')) 297 self._search_input = SingleLineEditText(parent=search_cont, align=uiconst.TOALL, hintText='Search', OnReturn=self._search) 298 self._results_scroll = Scroll(parent=self, align=uiconst.TOALL, pushContent=True) 299 search_type_setting.on_change.connect(self._on_search_type_setting_changed) 300 search_by_setting.on_change.connect(self._on_search_by_setting_changed) 301 302 def _on_search_type_setting_changed(self, value): 303 self._search() 304 305 def _on_search_by_setting_changed(self, value): 306 self._search() 307 308 @threadutils.highlander_threaded 309 def _search(self): 310 with self._search_lock: 311 self._results_scroll.ShowLoading() 312 try: 313 search_string = self._search_input.GetValue().strip() 314 if not search_string: 315 return 316 scroll_entry_list = searchUtil.GetResultsScrollList(searchStr=search_string, groupIDList=SearchType.as_result_type_list(search_type_setting.get()), searchBy=search_by_setting.get()) 317 self._results_scroll.LoadContent(contentList=scroll_entry_list, noContentHint='No results') 318 finally: 319 self._results_scroll.HideLoading() 320 321 @staticmethod 322 def _get_search_settings_menu(): 323 menu = MenuData() 324 menu.AddCaption(localization.GetByLabel('UI/Common/SearchType')) 325 for search_type in sorted(SearchType.iter(), key=lambda x: SORT_KEY_BY_SEARCH_TYPE[x]): 326 menu.AddRadioButton(text=SearchType.display_name(search_type), value=search_type, setting=search_type_setting) 327 328 menu.AddCaption(localization.GetByLabel('UI/Common/SearchBy')) 329 for text, search_by in searchUtil.SEARCHBY_OPTIONS: 330 menu.AddRadioButton(text=text, value=search_by, setting=search_by_setting) 331 332 return menu 333 334 def OnTabSelect(self): 335 if not self._loaded: 336 self.load()