collapseLine.py (5225B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\collapseLine.py 2 import math 3 from carbonui.control.buttonIcon import ButtonIcon 4 from carbonui.primitives.container import Container 5 import carbonui.const as uiconst 6 from carbonui.primitives.transform import Transform 7 from clientsettings.setting import UserSettingBool 8 from carbonui.uianimations import animations 9 from signals import Signal 10 ANIM_DURATION = 0.5 11 SIDE_ALIGNMENTS = (uiconst.TOLEFT, 12 uiconst.TORIGHT, 13 uiconst.TOLEFT_NOPUSH, 14 uiconst.TORIGHT_NOPUSH, 15 uiconst.TOTOP_PROP, 16 uiconst.TOBOTTOM_PROP) 17 HORIZONTAL_ALIGNMENT = (uiconst.TOTOP, 18 uiconst.TOBOTTOM, 19 uiconst.TOTOP_NOPUSH, 20 uiconst.TOBOTTOM_NOPUSH, 21 uiconst.TOTOP_PROP, 22 uiconst.TOBOTTOM_PROP) 23 24 class CollapseLine(Container): 25 default_name = 'collapseLine' 26 default_align = uiconst.TORIGHT 27 default_height = 20 28 default_width = 20 29 30 def ApplyAttributes(self, attributes): 31 super(CollapseLine, self).ApplyAttributes(attributes) 32 settingKey = attributes.get('settingKey', 'collapseLine') 33 self.isCollapsedSetting = UserSettingBool(settings_key=settingKey, default_value=False) 34 isCollapsed = attributes.get('isCollapsed', None) 35 if isCollapsed is None: 36 isCollapsed = self.isCollapsedSetting.get() 37 self.isCollapsed = isCollapsed 38 self.collapsingSection = attributes.get('collapsingSection') 39 self.useCustomTransition = attributes.get('useCustomTransition', False) 40 self.collapsingSectionSize = attributes.get('collapsingSectionWidth', 10) 41 self.on_section_expand = Signal(signalName='on_section_expand') 42 self.on_section_collapse = Signal(signalName='on_section_collapse') 43 self.ContstructUI() 44 self.DoCollapseOrExpand(False) 45 46 def ContstructUI(self): 47 rotation = self._GetRotation() 48 self.btnCont = Transform(parent=self, align=uiconst.CENTER, rotationCenter=(0.5, 0.5), pos=(0, 0, 20, 20), rotation=rotation) 49 self.collapseBtn = ButtonIcon(name='collapseBtn', parent=self.btnCont, align=uiconst.CENTER, width=20, height=20, iconSize=20, texturePath='res:/UI/Texture/shared/collapser.png', func=self.CollapseExpand) 50 51 def _GetRotation(self): 52 rotation = math.pi if self.isCollapsed else 0 53 if self.align in (uiconst.TOLEFT, uiconst.TOLEFT_PROP): 54 rotation -= math.pi 55 if self.align in HORIZONTAL_ALIGNMENT: 56 rotation -= math.pi / 2 57 return rotation 58 59 def SetHint(self, hint): 60 self.collapseBtn.SetHint(hint) 61 62 def SetCollapsingSectionSize(self, value): 63 self.collapsingSectionSize = value 64 65 def CollapseExpand(self, *args): 66 if self.isCollapsed: 67 self.SetExpanded() 68 else: 69 self.SetCollapsed() 70 71 def SetExpanded(self, animate = True): 72 self.isCollapsed = False 73 self.isCollapsedSetting.set(False) 74 self.UpdateIcon(animate) 75 self.on_section_expand(animate) 76 self.DoCollapseOrExpand(animate=animate) 77 78 def SetCollapsed(self, animate = True): 79 self.isCollapsed = True 80 self.isCollapsedSetting.set(True) 81 self.UpdateIcon(animate) 82 self.on_section_collapse(animate) 83 self.DoCollapseOrExpand(animate=animate) 84 85 def UpdateIcon(self, animate = True): 86 rotation = self._GetRotation() 87 if animate: 88 animations.MorphScalar(self.btnCont, 'rotation', self.btnCont.rotation, rotation, duration=0.2) 89 else: 90 self.btnCont.SetRotation(rotation) 91 92 def DoCollapseOrExpand(self, animate = True): 93 if self.useCustomTransition: 94 return 95 if self.align in SIDE_ALIGNMENTS: 96 if self.isCollapsed: 97 self.CollapseSideBar(animate=animate) 98 else: 99 self.ExpandSideBar(animate=animate) 100 if self.align in HORIZONTAL_ALIGNMENT: 101 if self.isCollapsed: 102 self.CollapseHorizontalBar(animate=animate) 103 else: 104 self.ExpandHorizontalBar(animate=animate) 105 106 def ExpandSideBar(self, animate = True): 107 if animate: 108 animations.MorphScalar(self.collapsingSection, 'width', startVal=0, endVal=self.collapsingSectionSize, duration=ANIM_DURATION) 109 else: 110 self.collapsingSection.width = self.collapsingSectionSize 111 112 def CollapseSideBar(self, animate = True): 113 if animate: 114 animations.MorphScalar(self.collapsingSection, 'width', startVal=self.collapsingSection.width, endVal=0, duration=ANIM_DURATION) 115 else: 116 self.collapsingSection.width = 0 117 118 def ExpandHorizontalBar(self, animate = True): 119 if animate: 120 animations.MorphScalar(self.collapsingSection, 'height', startVal=0, endVal=self.collapsingSectionSize, duration=ANIM_DURATION) 121 else: 122 self.collapsingSection.height = self.collapsingSectionSize 123 124 def CollapseHorizontalBar(self, animate = True): 125 if animate: 126 animations.MorphScalar(self.collapsingSection, 'height', startVal=self.collapsingSection.height, endVal=0, duration=ANIM_DURATION) 127 else: 128 self.collapsingSection.height = 0