NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

attributeSelectionPanel.py (7245B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\comparison\attributeSelectionPanel.py
      2 import telemetry
      3 from carbonui import const as uiconst
      4 from carbonui.button.group import ButtonGroup, ButtonSizeMode
      5 from carbonui.control.checkbox import Checkbox
      6 from carbonui.control.dragResizeCont import DragResizeCont
      7 from carbonui.control.scroll import Scroll
      8 from dogma.attributes import uiAttributeGroups
      9 from dogma.attributes.format import FormatUnit
     10 from eve.client.script.ui.comparison.comparisonSettings import only_show_diffrentiators_setting
     11 from eve.client.script.ui.control.entries.header import Header
     12 from eve.client.script.ui.control.entries.label_text import LabelTextTop
     13 from eve.client.script.ui.control.entries.util import GetFromClass
     14 from eve.client.script.ui.shared.info.infoUtil import GetAttributeTooltipTitleAndDescription
     15 from localization import GetByLabel
     16 from signals import Signal
     17 
     18 class AttributeSelectionPanel(DragResizeCont):
     19     default_id = 'typecompare_attributescroll'
     20 
     21     def __init__(self, type_comparer, **kw):
     22         super(AttributeSelectionPanel, self).__init__(**kw)
     23         self.hiliteSorted = 0
     24         self.type_comparer = type_comparer
     25         self.attribute_ids_currently_checked = set()
     26         self.is_all_selected = True
     27         self.on_selection_changed = Signal('on_selection_changed')
     28         self.construct_right_button_group()
     29         self.scroll = Scroll(name='attributescroll', parent=self)
     30         self.connect_signals()
     31 
     32     def connect_signals(self):
     33         only_show_diffrentiators_setting.on_change.connect(self.on_only_show_diffrentiators_setting)
     34 
     35     def Close(self):
     36         super(AttributeSelectionPanel, self).Close()
     37         self.disconnect_signals()
     38 
     39     def disconnect_signals(self):
     40         only_show_diffrentiators_setting.on_change.disconnect(self.on_only_show_diffrentiators_setting)
     41 
     42     def construct_right_button_group(self):
     43         btnGroup = ButtonGroup(parent=self, padTop=8, button_size_mode=ButtonSizeMode.DYNAMIC)
     44         btnGroup.AddButton(GetByLabel('UI/Common/SelectAll'), self.select_all_attributes)
     45         btnGroup.AddButton(GetByLabel('UI/Common/DeselectAll'), self.deselect_all_attributes)
     46 
     47     def on_types_changed(self):
     48         self._check_modify_attribute_selection()
     49         self.populate_scroll()
     50 
     51     def _check_modify_attribute_selection(self):
     52         selectable_attribute_ids = self.get_selectable_attribute_ids()
     53         self.attribute_ids_currently_checked.intersection_update(selectable_attribute_ids)
     54         if not self.attribute_ids_currently_checked or self.is_all_selected:
     55             self.attribute_ids_currently_checked.update(selectable_attribute_ids)
     56         self._update_is_all_selected()
     57 
     58     def populate_scroll(self):
     59         scroll_entries = self._get_attribute_scroll_list()
     60         self.scroll.Load(contentList=scroll_entries, noContentHint=GetByLabel('UI/Compare/NothingToCompare'))
     61 
     62     def _update_is_all_selected(self):
     63         self.is_all_selected = self.attribute_ids_currently_checked == self.get_selectable_attribute_ids()
     64 
     65     def get_attribute_ids_selected(self):
     66         return self.attribute_ids_currently_checked
     67 
     68     def _get_attribute_scroll_list(self):
     69         scroll_list = []
     70         attribute_ids_by_group_name = self.type_comparer.get_common_attribute_ids_by_groupname(self.get_selectable_attribute_ids())
     71         for group_id, attribute_ids in attribute_ids_by_group_name.items():
     72             scroll_list.append(GetFromClass(Header, {'label': GetByLabel(uiAttributeGroups.name_by_group_id[group_id])}))
     73             for attribute_id in attribute_ids:
     74                 attribute = self.type_comparer.get_common_attribute(attribute_id)
     75                 scroll_list.append(self.GetAttributeScrollEntry(attribute))
     76 
     77         return scroll_list
     78 
     79     def get_selectable_attribute_ids(self):
     80         if not only_show_diffrentiators_setting.is_enabled() or len(self.type_comparer.get_comparable_types()) <= 1:
     81             attributes_by_id = self.type_comparer.get_common_attributes_by_id()
     82         else:
     83             attributes_by_id = self.type_comparer.get_common_attribute_that_diffrentiate_by_id()
     84         return set(attributes_by_id.keys())
     85 
     86     def GetAttributeScrollEntry(self, attribute):
     87         return GetFromClass(AttributeCheckbox, {'line': 1,
     88          'info': attribute,
     89          'label': attribute.name,
     90          'iconID': attribute.texture_path,
     91          'item': attribute,
     92          'text': FormatUnit(getattr(attribute, 'unitID', None)) or ' ',
     93          'hint': attribute.name,
     94          'checked': attribute.attribute_id in self.attribute_ids_currently_checked,
     95          'cfgname': attribute.attribute_id,
     96          'OnChange': self.OnAttributeCheckbox})
     97 
     98     def _SetAttributeChecked(self, attributeID, is_checked):
     99         if is_checked:
    100             self.attribute_ids_currently_checked.add(attributeID)
    101         elif attributeID in self.attribute_ids_currently_checked:
    102             self.attribute_ids_currently_checked.remove(attributeID)
    103         self._update_is_all_selected()
    104         self.on_selection_changed()
    105 
    106     def OnAttributeCheckbox(self, checkbox, *args):
    107         attributeID = checkbox.GetSettingsKey()
    108         is_checked = checkbox.GetValue()
    109         self._SetAttributeChecked(attributeID, is_checked)
    110 
    111     def on_only_show_diffrentiators_setting(self, value):
    112         self.on_types_changed()
    113         self.on_selection_changed()
    114 
    115     def select_all_attributes(self, *args):
    116         self.attribute_ids_currently_checked.update(self.get_selectable_attribute_ids())
    117         self.populate_scroll()
    118         self.on_selection_changed()
    119 
    120     def deselect_all_attributes(self, *args):
    121         self.attribute_ids_currently_checked.clear()
    122         self.populate_scroll()
    123         self.on_selection_changed()
    124 
    125 
    126 class AttributeCheckbox(LabelTextTop):
    127     __guid__ = 'listentry.AttributeCheckbox'
    128 
    129     def Startup(self, *args):
    130         LabelTextTop.Startup(self, args)
    131         self.sr.checkbox = Checkbox(parent=self, align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, callback=self.CheckBoxChange, pos=(4, 4, 0, 0))
    132 
    133     def Load(self, args):
    134         LabelTextTop.Load(self, args)
    135         data = self.sr.node
    136         self.sr.checkbox.SetChecked(data.checked, 0)
    137         self.sr.checkbox.SetSettingsKey(data.cfgname)
    138         self.sr.icon.left = 20
    139         if self.sr.icon.display:
    140             self.sr.label.left = self.sr.icon.left + self.sr.icon.width + 2
    141             self.sr.text.left = self.sr.icon.left + self.sr.icon.width + 2
    142         else:
    143             self.sr.label.left = 24
    144             self.sr.text.left = 24
    145 
    146     def CheckBoxChange(self, *args):
    147         self.sr.node.checked = self.sr.checkbox.checked
    148         self.sr.node.OnChange(*args)
    149 
    150     def OnClick(self, *args):
    151         self.sr.checkbox.OnClick(*args)
    152 
    153     def LoadTooltipPanel(self, tooltipPanel, *args):
    154         tooltipTitleText, tooltipDescriptionText = GetAttributeTooltipTitleAndDescription(self.sr.node.item.attribute_id)
    155         if tooltipTitleText:
    156             tooltipPanel.LoadStandardSpacing()
    157             tooltipPanel.columns = 1
    158             tooltipPanel.AddMediumHeader(text=tooltipTitleText)
    159             tooltipPanel.AddLabelMedium(text=tooltipDescriptionText, wrapWidth=240)