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

scrollColumnHeader.py (10139B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\scrollColumnHeader.py
      2 import eveicon
      3 from carbon.client.script.environment.AudioUtil import PlaySound
      4 from carbonui import Axis, uiconst
      5 from carbonui.control.scroll_const import SortDirection
      6 from carbonui.decorative.resize_handle import ResizeHandle
      7 from carbonui.primitives.container import Container
      8 from carbonui.primitives.sprite import Sprite
      9 from carbonui.text.color import TextColor
     10 from carbonui.uianimations import animations
     11 from carbonui.uicore import uicore
     12 from eve.client.script.ui.control.eveLabel import EveLabelSmall
     13 from eve.client.script.ui.control.pointerPanel import GetPanelInterestFromObject
     14 
     15 class ColumnHeader(Container):
     16     DIRECTION_INDICATOR_ICON_SIZE = 16
     17     SCALE_HANDLE_SIZE = 8
     18     _text_clipper = None
     19 
     20     def __init__(self, column_id = None, text = None, direction = SortDirection.ASCENDING, on_click = None, on_double_click = None, scalable = False, on_scale_start = None, on_scale_move = None, on_scale_end = None, get_menu = None, selected = False, tab_margin = 0, header_hint = None, **kwargs):
     21         self.id = column_id
     22         self._direction = direction
     23         self._direction_indicator = None
     24         self._get_menu = get_menu
     25         self._hovered = False
     26         self._label = None
     27         self._on_click = on_click
     28         self._on_double_click = on_double_click
     29         self._scalable = scalable
     30         self._scaler = None
     31         self._selected = selected
     32         self._tab_margin = tab_margin
     33         self._text = text
     34         self._header_hint = header_hint
     35         super(ColumnHeader, self).__init__(**kwargs)
     36         self._prepare_label()
     37         self._prepare_direction_indicator()
     38         if self._scalable:
     39             self._prepare_scaler(on_scale_start, on_scale_move, on_scale_end)
     40 
     41     @property
     42     def direction(self):
     43         return self._direction
     44 
     45     @direction.setter
     46     def direction(self, value):
     47         if value != self._direction:
     48             self._direction = value
     49             self._update()
     50 
     51     @property
     52     def on_scale_start(self):
     53         if self._scaler is not None:
     54             return self._scaler.on_scale_start
     55 
     56     @on_scale_start.setter
     57     def on_scale_start(self, value):
     58         if self._scaler is not None:
     59             self._scaler.on_scale_start = value
     60 
     61     @property
     62     def on_scale_move(self):
     63         if self._scaler is not None:
     64             return self._scaler.on_scale_move
     65 
     66     @on_scale_move.setter
     67     def on_scale_move(self, value):
     68         if self._scaler is not None:
     69             self._scaler.on_scale_move = value
     70 
     71     @property
     72     def on_scale_end(self):
     73         if self._scaler is not None:
     74             return self._scaler.on_scale_end
     75 
     76     @on_scale_end.setter
     77     def on_scale_end(self, value):
     78         if self._scaler is not None:
     79             self._scaler.on_scale_end = value
     80 
     81     def show_resizer_hint(self):
     82         if self._scaler:
     83             self._scaler.handle_ghost_visible = True
     84 
     85     def hide_resizer_hint(self):
     86         if self._scaler:
     87             self._scaler.handle_ghost_visible = False
     88 
     89     def _prepare_divider(self):
     90         pass
     91 
     92     def _prepare_label(self):
     93         self._text_clipper = Container(name='text_clipper', parent=self, align=uiconst.TOALL, padding=self._get_text_clipper_padding(), state=uiconst.UI_PICKCHILDREN, clipChildren=True)
     94         self._label = EveLabelSmall(parent=self._text_clipper, align=uiconst.CENTERLEFT, text=self._text, state=uiconst.UI_DISABLED, color=self._get_label_color(), autoFadeSides=8)
     95 
     96     def _get_text_clipper_padding(self):
     97         if self._selected:
     98             pad_right = 0
     99         else:
    100             pad_right = int(round(self.SCALE_HANDLE_SIZE / 2.0))
    101         return (self._tab_margin,
    102          0,
    103          pad_right,
    104          0)
    105 
    106     def _update_text_clipper_padding(self):
    107         self._text_clipper.padding = self._get_text_clipper_padding()
    108 
    109     def _get_label_color(self):
    110         if self._hovered:
    111             return TextColor.HIGHLIGHT
    112         else:
    113             return TextColor.SECONDARY
    114 
    115     def _prepare_direction_indicator(self):
    116         self._direction_indicator_cont = Container(name='direction_indicator', parent=self, align=uiconst.TORIGHT, left=max(0, self._tab_margin - 4), width=self.DIRECTION_INDICATOR_ICON_SIZE, idx=0)
    117         self._direction_indicator = Sprite(parent=self._direction_indicator_cont, align=uiconst.CENTER, width=self.DIRECTION_INDICATOR_ICON_SIZE, height=self.DIRECTION_INDICATOR_ICON_SIZE, state=uiconst.UI_DISABLED, texturePath=self._get_direction_indicator_icon(), color=self._get_direction_indicator_color())
    118         self._direction_indicator_cont.display = self._selected
    119 
    120     def _get_direction_indicator_icon(self):
    121         if self._direction == SortDirection.ASCENDING:
    122             return eveicon.caret_up
    123         if self._direction == SortDirection.DESCENDING:
    124             return eveicon.caret_down
    125         raise ValueError('Unknown sort direction')
    126 
    127     def _get_direction_indicator_color(self):
    128         if self._hovered:
    129             return TextColor.HIGHLIGHT
    130         elif self._selected:
    131             return TextColor.NORMAL
    132         else:
    133             return TextColor.SECONDARY
    134 
    135     def _prepare_scaler(self, on_scale_start, on_scale_move, on_scale_end):
    136         self._scaler = ScaleHandle(parent=self, align=uiconst.TORIGHT_NOPUSH, width=self.SCALE_HANDLE_SIZE, on_scale_start=on_scale_start, on_scale_move=on_scale_move, on_scale_end=on_scale_end, on_double_click=self._on_double_click, hint_delegate=self, idx=0)
    137 
    138     def _update(self):
    139         if self._direction_indicator is not None:
    140             self._direction_indicator_cont.display = self._selected
    141             self._direction_indicator.texturePath = self._get_direction_indicator_icon()
    142             self._direction_indicator.color = self._get_direction_indicator_color()
    143         if self._label is not None:
    144             animations.SpColorMorphTo(self._label, endColor=self._get_label_color(), duration=0.3)
    145 
    146     def select(self, direction = None):
    147         self._selected = True
    148         if direction is not None:
    149             self._direction = direction
    150         self._update()
    151         self._update_text_clipper_padding()
    152 
    153     def deselect(self):
    154         self._selected = False
    155         self._update()
    156         self._update_text_clipper_padding()
    157 
    158     def set_label(self, text):
    159         self._label.text = text
    160 
    161     def Select(self, rev, *args):
    162         self.select(SortDirection.from_legacy_reversed_sort(rev))
    163 
    164     def Deselect(self):
    165         self.deselect()
    166 
    167     def OnClick(self, *args):
    168         if self._on_click is not None:
    169             PlaySound(uiconst.SOUND_BUTTON_CLICK)
    170             self._on_click()
    171 
    172     def OnDblClick(self, *args):
    173         if self._on_double_click is not None:
    174             self._on_double_click()
    175 
    176     def OnMouseEnter(self, *args):
    177         self._hovered = True
    178         PlaySound(uiconst.SOUND_BUTTON_HOVER)
    179         self._update()
    180 
    181     def OnMouseExit(self, *args):
    182         self._hovered = False
    183         self._update()
    184 
    185     def GetMenu(self, *args):
    186         if self._get_menu is not None:
    187             return self._get_menu()
    188 
    189     def GetHeaderHeight(self):
    190         return max(24, self._label.textheight)
    191 
    192     def GetHint(self):
    193         if self._header_hint:
    194             if uicore.uilib.auxMouseOver is self._label:
    195                 uicore.uilib.auxiliaryTooltip = None
    196             return self._header_hint
    197         if uicore.uilib.auxMouseOver is self._label:
    198             return
    199         if self._label is not None and self._label.IsPartiallyClipped(self._label.parent):
    200             return self._text
    201 
    202 
    203 class ScaleHandle(Container):
    204     _handle_ghost_visible = False
    205     _hovered = False
    206 
    207     def __init__(self, on_scale_start = None, on_scale_move = None, on_scale_end = None, on_double_click = None, name = 'scaler', state = uiconst.UI_NORMAL, cursor = uiconst.UICORSOR_HORIZONTAL_RESIZE, hint_delegate = None, **kwargs):
    208         self._hint_delegate = hint_delegate
    209         self._scaling = False
    210         self.on_double_click = on_double_click
    211         self.on_scale_start = on_scale_start
    212         self.on_scale_move = on_scale_move
    213         self.on_scale_end = on_scale_end
    214         super(ScaleHandle, self).__init__(name=name, cursor=cursor, state=state, **kwargs)
    215         self._handle = ResizeHandle(parent=self, align=uiconst.TOALL, orientation=Axis.VERTICAL, state=uiconst.UI_DISABLED, padding=(0, 4, 0, 4))
    216 
    217     @property
    218     def handle_ghost_visible(self):
    219         return self._handle_ghost_visible
    220 
    221     @handle_ghost_visible.setter
    222     def handle_ghost_visible(self, value):
    223         if self._handle_ghost_visible != value:
    224             self._handle_ghost_visible = value
    225             self._update_handle_ghost()
    226 
    227     def _update_handle_ghost(self):
    228         self._handle.show_line = self._handle_ghost_visible and not self._hovered
    229 
    230     def OnMouseDown(self, button):
    231         if button == uiconst.MOUSELEFT:
    232             self._scaling = True
    233             if self.on_scale_start is not None:
    234                 self.on_scale_start()
    235 
    236     def OnMouseMove(self, *args):
    237         self._handle.OnMouseMove(*args)
    238         if self._scaling and self.on_scale_move is not None:
    239             self.on_scale_move()
    240 
    241     def OnMouseEnter(self, *args):
    242         self._hovered = True
    243         self._handle.OnMouseEnter(*args)
    244         self._update_handle_ghost()
    245 
    246     def OnMouseExit(self, *args):
    247         self._hovered = False
    248         self._handle.OnMouseExit(*args)
    249         self._update_handle_ghost()
    250 
    251     def OnMouseUp(self, button):
    252         if self._scaling and button == uiconst.MOUSELEFT:
    253             self._scaling = False
    254             if self.on_scale_end is not None:
    255                 self.on_scale_end()
    256 
    257     def OnDblClick(self, *args):
    258         if self.on_double_click is not None:
    259             self.on_double_click()
    260 
    261     def GetHint(self):
    262         if self._hint_delegate is not None:
    263             return self._hint_delegate.GetHint()
    264 
    265     def GetTooltipPosition(self):
    266         if self._hint_delegate is not None:
    267             interest_rect, is_blocked = GetPanelInterestFromObject(self._hint_delegate)
    268             return interest_rect