search.py (5488B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\locations\search.py 2 import eveicon 3 import localization 4 import locks 5 import threadutils 6 from carbonui import uiconst 7 from carbonui.control.contextMenu.menuData import MenuData 8 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText 9 from carbonui.primitives.container import Container 10 from carbonui.primitives.containerAutoSize import ContainerAutoSize 11 from clientsettings.setting import CharSettingEnum 12 from eve.client.script.ui.control.eveScroll import Scroll 13 from carbonui.button.menu import MenuButtonIcon 14 from eve.client.script.ui.util import searchUtil 15 from eve.common.script.search.const import MatchBy, ResultType 16 17 class SearchType(object): 18 all = 0 19 station = 1 20 solar_system = 2 21 constellation = 3 22 region = 4 23 structure = 5 24 _RESULT_TYPE_BY_SEARCH_TYPE = {station: ResultType.station, 25 solar_system: ResultType.solar_system, 26 constellation: ResultType.constellation, 27 region: ResultType.region, 28 structure: ResultType.structure_with_inlined_data} 29 _DISPLAY_NAME_BY_SEARCH_TYPE = {all: localization.GetByLabel('UI/Common/Any'), 30 station: localization.GetByLabel('UI/Common/LocationTypes/Station'), 31 solar_system: localization.GetByLabel('UI/Common/LocationTypes/SolarSystem'), 32 constellation: localization.GetByLabel('UI/Common/LocationTypes/Constellation'), 33 region: localization.GetByLabel('UI/Common/LocationTypes/Region'), 34 structure: localization.GetByLabel('UI/Common/LocationTypes/Structures')} 35 36 @classmethod 37 def as_result_type_list(cls, search_type): 38 if search_type == cls.all: 39 return [ResultType.station, 40 ResultType.solar_system, 41 ResultType.constellation, 42 ResultType.region, 43 ResultType.structure_with_inlined_data] 44 else: 45 return [cls._RESULT_TYPE_BY_SEARCH_TYPE[search_type]] 46 47 @classmethod 48 def display_name(cls, search_type): 49 return cls._DISPLAY_NAME_BY_SEARCH_TYPE[search_type] 50 51 @classmethod 52 def iter(cls): 53 for name in dir(cls): 54 if name.startswith('_'): 55 continue 56 value = getattr(cls, name) 57 if isinstance(value, int): 58 yield value 59 60 61 SORT_KEY_BY_SEARCH_TYPE = {SearchType.all: 0, 62 SearchType.solar_system: 1, 63 SearchType.constellation: 2, 64 SearchType.region: 3, 65 SearchType.station: 4, 66 SearchType.structure: 5} 67 search_type_setting = CharSettingEnum(settings_key='locations_window_search_type', default_value=SearchType.all, options=frozenset(SearchType.iter())) 68 search_by_setting = CharSettingEnum(settings_key='locations_window_search_by', default_value=MatchBy.partial_terms, options=frozenset((value for _, value in searchUtil.SEARCHBY_OPTIONS))) 69 70 class LocationSearchPanel(Container): 71 72 def __init__(self, parent, align): 73 self._loaded = False 74 self._search_input = None 75 self._results_scroll = None 76 self._search_lock = locks.Lock() 77 super(LocationSearchPanel, self).__init__(parent=parent, align=align) 78 79 def load(self): 80 self._loaded = True 81 search_cont = Container(parent=self, align=uiconst.TOTOP, height=32, padBottom=16) 82 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')) 83 self._search_input = SingleLineEditText(parent=search_cont, align=uiconst.TOALL, hintText=localization.GetByLabel('UI/Common/Search'), OnReturn=self._search) 84 self._results_scroll = Scroll(parent=self, align=uiconst.TOALL, pushContent=True) 85 search_type_setting.on_change.connect(self._on_search_type_setting_changed) 86 search_by_setting.on_change.connect(self._on_search_by_setting_changed) 87 88 def _on_search_type_setting_changed(self, value): 89 self._search() 90 91 def _on_search_by_setting_changed(self, value): 92 self._search() 93 94 @threadutils.highlander_threaded 95 def _search(self): 96 with self._search_lock: 97 self._results_scroll.ShowLoading() 98 try: 99 search_string = self._search_input.GetValue().strip() 100 if not search_string: 101 return 102 scroll_entry_list = searchUtil.GetResultsScrollList(searchStr=search_string, groupIDList=SearchType.as_result_type_list(search_type_setting.get()), searchBy=search_by_setting.get()) 103 self._results_scroll.LoadContent(contentList=scroll_entry_list, noContentHint='No results') 104 finally: 105 self._results_scroll.HideLoading() 106 107 @staticmethod 108 def _get_search_settings_menu(): 109 menu = MenuData() 110 menu.AddCaption(localization.GetByLabel('UI/Common/SearchType')) 111 for search_type in sorted(SearchType.iter(), key=lambda x: SORT_KEY_BY_SEARCH_TYPE[x]): 112 menu.AddRadioButton(text=SearchType.display_name(search_type), value=search_type, setting=search_type_setting) 113 114 menu.AddCaption(localization.GetByLabel('UI/Common/SearchBy')) 115 for text, search_by in searchUtil.SEARCHBY_OPTIONS: 116 menu.AddRadioButton(text=text, value=search_by, setting=search_by_setting) 117 118 return menu 119 120 def OnTabSelect(self): 121 if not self._loaded: 122 self.load()