collapseGroup.py (3295B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\collapseGroup.py 2 import eveicon 3 from carbonui.primitives.container import Container 4 from carbonui.primitives.containerAutoSize import ContainerAutoSize 5 from carbonui.primitives.sprite import Sprite 6 from carbonui import Align, uiconst, TextColor 7 from carbonui.text.styles import TextBody 8 from carbonui.control.buttonIcon import ButtonIcon 9 10 class CollapseGroup(ContainerAutoSize): 11 default_state = uiconst.UI_NORMAL 12 default_icon = None 13 default_label = '' 14 default_align = Align.TOTOP 15 default_header_color = (0.6, 0.6, 0.6, 0.2) 16 icon = None 17 text = None 18 header_color = None 19 20 def ApplyAttributes(self, attributes): 21 super(CollapseGroup, self).ApplyAttributes(attributes) 22 self.icon = attributes.Get('icon', self.default_icon) 23 self.text = attributes.Get('text', self.default_label) 24 self.header_color = attributes.Get('headerColor', self.default_header_color) 25 self._construct_layout() 26 27 def _construct_layout(self): 28 self._construct_header() 29 self._construct_main_cont() 30 31 def _construct_header(self): 32 self.headerCont = Container(name='headerCont', parent=self, align=Align.TOTOP, height=32, bgColor=self.header_color) 33 self.headerCont.OnClick = self.OnClick 34 if self.icon: 35 self.iconCont = Container(name='iconCont', parent=self.headerCont, align=Align.TOLEFT, width=24, state=uiconst.UI_DISABLED) 36 self.icon = Sprite(name='icon', parent=self.iconCont, align=Align.CENTERRIGHT, texturePath=self.icon, color=TextColor.SECONDARY, width=16, height=16, state=uiconst.UI_DISABLED) 37 self.expanderCont = Container(name='expanderCont', parent=self.headerCont, align=Align.TORIGHT, width=32, state=uiconst.UI_PICKCHILDREN) 38 self.expanderIcon = ButtonIcon(name='expander', parent=self.expanderCont, align=Align.CENTER, texturePath=eveicon.chevron_up, iconSize=18, func=self.OnClick) 39 self._construct_label() 40 41 def _construct_main_cont(self): 42 self.mainCont = ContainerAutoSize(name='mainCont', parent=self, align=Align.TOTOP, state=uiconst.UI_PICKCHILDREN, padTop=2) 43 44 def _construct_label(self): 45 self.labelCont = Container(name='labelCont', parent=self.headerCont, align=Align.TOALL, state=uiconst.UI_DISABLED, clipChildren=True) 46 self.label = TextBody(name='label', parent=self.labelCont, align=Align.CENTERLEFT, text=self.text, padLeft=8, color=TextColor.NORMAL, state=uiconst.UI_DISABLED, bold=True) 47 48 def OnMouseEnter(self, *args): 49 super(CollapseGroup, self).OnMouseEnter(*args) 50 self.expanderIcon.OnMouseEnter(*args) 51 52 def OnMouseExit(self, *args): 53 super(CollapseGroup, self).OnMouseExit(*args) 54 self.expanderIcon.OnMouseExit(*args) 55 56 def SetCollapsed(self, collapsed): 57 if collapsed: 58 self.mainCont.Hide() 59 self.expanderIcon.SetTexturePath(eveicon.chevron_down) 60 else: 61 self.mainCont.Show() 62 self.expanderIcon.SetTexturePath(eveicon.chevron_up) 63 64 def Toggle(self): 65 self.SetCollapsed(self.mainCont.display) 66 67 def OnClick(self, *args): 68 super(CollapseGroup, self).OnClick(*args) 69 self.Toggle()