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

section.py (8889B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\section.py
      2 from carbonui import uiconst
      3 from carbonui.primitives.container import Container
      4 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      5 from carbonui.primitives.fill import Fill
      6 from carbonui.primitives.frame import Frame
      7 from carbonui.uianimations import animations
      8 from carbonui.util.color import Color
      9 from eve.client.script.ui.control.eveLabel import EveHeaderMedium
     10 COLOR_BG = (0, 0, 0, 0.25)
     11 COLOR_HEADER = (0.5, 0.5, 0.5, 0.3)
     12 COLOR_SUBSECTION_FRAME = (0.15, 0.15, 0.15, 1.0)
     13 
     14 class ChildBypassMixin(object):
     15 
     16     def TurnOnBypassToMainCont(self):
     17         self.children.insert = self._InsertChild
     18         self.children.append = self._AppendChild
     19         self.children.remove = self._RemoveChild
     20 
     21     def _InsertChild(self, idx, obj):
     22         self.mainCont.children.insert(idx, obj)
     23 
     24     def _AppendChild(self, obj):
     25         self.mainCont.children.append(obj)
     26 
     27     def _RemoveChild(self, obj):
     28         self.mainCont.children.remove(obj)
     29 
     30     def Flush(self):
     31         self.mainCont.Flush()
     32 
     33 
     34 class Section(ChildBypassMixin, Container):
     35     default_name = 'Section'
     36     default_inside_padding = (10, 10, 10, 10)
     37     default_headerText = ''
     38 
     39     def ApplyAttributes(self, attributes):
     40         super(Section, self).ApplyAttributes(attributes)
     41         self.headerText = attributes.Get('headerText', self.default_headerText)
     42         self.mainContainerPadding = attributes.Get('insidePadding', self.default_inside_padding)
     43         self.__ConstructLayout()
     44         self.TurnOnBypassToMainCont()
     45 
     46     def __ConstructLayout(self):
     47         self._ConstructHeader()
     48         self._ConstructMainContainer()
     49         self._ConstructFrame()
     50 
     51     def _ConstructHeader(self):
     52         self.headerCont = Header(parent=self, align=uiconst.TOTOP, text=self.headerText)
     53 
     54     def _ConstructMainContainer(self):
     55         self.mainCont = Container(name='mainCont', parent=self, padding=self.mainContainerPadding)
     56 
     57     def _ConstructFrame(self):
     58         Frame(bgParent=self, texturePath='res:/UI/Texture/Shared/DarkStyle/panel1Corner_Solid.png', cornerSize=9, color=COLOR_BG)
     59 
     60     def SetText(self, text):
     61         self.headerCont.SetText(text)
     62 
     63 
     64 class SectionAutoSize(ChildBypassMixin, ContainerAutoSize):
     65     default_name = 'SectionAutoSize'
     66     default_inside_padding = (10, 10, 10, 10)
     67     default_headerText = ''
     68     default_mirrored = False
     69     default_color = COLOR_BG
     70 
     71     def ApplyAttributes(self, attributes):
     72         super(SectionAutoSize, self).ApplyAttributes(attributes)
     73         self.headerText = attributes.Get('headerText', self.default_headerText)
     74         self.mainContainerPadding = attributes.Get('insidePadding', self.default_inside_padding)
     75         self.mirrored = attributes.get('mirrored', self.default_mirrored)
     76         self.color = attributes.get('color', self.default_color)
     77         self.__ConstructLayout()
     78         self.TurnOnBypassToMainCont()
     79 
     80     def __ConstructLayout(self):
     81         self._ConstructHeader()
     82         self._ConstructMainContainer()
     83         self._ConstructFrame()
     84 
     85     def _ConstructHeader(self):
     86         self.headerCont = Header(parent=self, align=uiconst.TOTOP, text=self.headerText)
     87 
     88     def _ConstructMainContainer(self):
     89         self.mainCont = ContainerAutoSize(name='mainCont', parent=self, align=uiconst.TOTOP, padding=self.mainContainerPadding, alignMode=self.alignMode)
     90 
     91     def _ConstructFrame(self):
     92         self.frame = Frame(bgParent=self, texturePath=self._GetFrameTexturePath(), cornerSize=9, color=self._bgColor or self.color)
     93 
     94     def _GetFrameTexturePath(self):
     95         if self.mirrored:
     96             return 'res:/UI/Texture/Shared/DarkStyle/panel1Corner_SolidMirrored.png'
     97         return 'res:/UI/Texture/Shared/DarkStyle/panel1Corner_Solid.png'
     98 
     99     def SetText(self, text):
    100         self.headerCont.SetText(text)
    101 
    102     def _SetupBackground(self):
    103         pass
    104 
    105 
    106 class SubSection(ChildBypassMixin, Container):
    107     default_name = 'SubSection'
    108     default_inside_padding = (6, 6, 6, 6)
    109     default_headerText = ''
    110     default_stroked = True
    111     default_frameColor = COLOR_SUBSECTION_FRAME
    112 
    113     def ApplyAttributes(self, attributes):
    114         super(SubSection, self).ApplyAttributes(attributes)
    115         self.headerText = attributes.Get('headerText', self.default_headerText)
    116         self.mainContainerPadding = attributes.Get('insidePadding', self.default_inside_padding)
    117         self.stroked = attributes.Get('stroked', self.default_stroked)
    118         self.frameColor = attributes.Get('frameColor', self.default_frameColor)
    119         self.__ConstructLayout()
    120         self.TurnOnBypassToMainCont()
    121 
    122     def __ConstructLayout(self):
    123         self.caption = EveHeaderMedium(parent=self, align=uiconst.TOTOP, text=self.headerText, padBottom=2)
    124         self.mainCont = Container(name='mainCont', parent=self, padding=self.mainContainerPadding)
    125         self._ConstructFrame()
    126 
    127     def _ConstructFrame(self):
    128         texturePath = 'res:/UI/Texture/Shared/DarkStyle/panel1Corner_Solid.png'
    129         if self.stroked:
    130             texturePath = 'res:/UI/Texture/Shared/DarkStyle/panel1Corner_Stroke.png'
    131         Frame(bgParent=self, texturePath=texturePath, cornerSize=9, color=self.frameColor, padTop=18)
    132 
    133     def SetText(self, text):
    134         self.caption.SetText(text)
    135 
    136 
    137 class SubSectionAutoSize(ChildBypassMixin, ContainerAutoSize):
    138     default_name = 'SubSectionAutoSize'
    139     default_inside_padding = (6, 6, 6, 6)
    140     default_headerText = ''
    141     default_framePadTop = 18
    142 
    143     def ApplyAttributes(self, attributes):
    144         super(SubSectionAutoSize, self).ApplyAttributes(attributes)
    145         self.headerText = attributes.Get('headerText', self.default_headerText)
    146         self.mainContainerPadding = attributes.Get('insidePadding', self.default_inside_padding)
    147         self.frame = None
    148         self._ConstructLayout()
    149         self.TurnOnBypassToMainCont()
    150 
    151     def _ConstructLayout(self):
    152         self._ConstructCaption()
    153         self._ConstructMainCont()
    154         self._ConstructFrame()
    155         self.fill = None
    156 
    157     def _ConstructCaption(self):
    158         self.caption = EveHeaderMedium(parent=self, align=uiconst.TOTOP, text=self.headerText, padBottom=2)
    159 
    160     def _ConstructMainCont(self):
    161         self.mainCont = ContainerAutoSize(name='mainCont', parent=self, align=uiconst.TOTOP, padding=self.mainContainerPadding, alignMode=self.alignMode)
    162 
    163     def _ConstructFrame(self):
    164         self.frame = Frame(bgParent=self, texturePath='res:/UI/Texture/Shared/DarkStyle/panel1Corner_Stroke.png', cornerSize=9, color=COLOR_SUBSECTION_FRAME, padTop=self.default_framePadTop)
    165 
    166     def CheckConstructFill(self):
    167         if not self.fill:
    168             self.fill = Frame(bgParent=self, texturePath='res:/UI/Texture/Shared/DarkStyle/panel1Corner_Solid.png', cornerSize=9, padding=(6, 24, 6, 6), color=(1.0, 1.0, 1.0, 0.5))
    169 
    170     def SetText(self, text):
    171         self.caption.SetText(text)
    172 
    173     def Blink(self, color):
    174         self.CheckConstructFill()
    175         self.fill.Show()
    176         if self.frame:
    177             self.frame.SetRGBA(*color)
    178             animations.FadeTo(self.frame, 0.2, 1.0, duration=1.5, curveType=uiconst.ANIM_WAVE, loops=uiconst.ANIM_REPEAT)
    179         self.fill.SetRGBA(*self._GetFillColor(color))
    180         animations.FadeTo(self.fill, 0.1, 0.15, duration=1.5, curveType=uiconst.ANIM_WAVE, loops=uiconst.ANIM_REPEAT)
    181 
    182     @staticmethod
    183     def _GetFillColor(color):
    184         return Color(*color).SetOpacity(0.15).GetRGBA()
    185 
    186     def StopBlink(self):
    187         if self.frame:
    188             self.frame.StopAnimations()
    189             self.frame.SetRGBA(*COLOR_SUBSECTION_FRAME)
    190         if self.fill:
    191             self.fill.StopAnimations()
    192             self.fill.opacity = 0.0
    193 
    194     def SetColor(self, color):
    195         self._SetFrameColor(color)
    196         if self.fill:
    197             self._SetFillColor(color)
    198 
    199     def _SetFrameColor(self, color):
    200         color = Color(*color).SetOpacity(self.frame.opacity).GetRGBA()
    201         self.frame.SetRGBA(*color)
    202 
    203     def _SetFillColor(self, color):
    204         color = Color(*color).SetOpacity(self.fill.opacity).GetRGBA()
    205         self.fill.SetRGBA(*color)
    206 
    207 
    208 class Header(Container):
    209     default_name = 'Header'
    210     default_bgColor = COLOR_HEADER
    211     default_height = 24
    212     default_labelAlign = uiconst.CENTER
    213     default_labelLeft = 0
    214 
    215     def ApplyAttributes(self, attributes):
    216         super(Header, self).ApplyAttributes(attributes)
    217         labelAlign = attributes.get('labelAlign', self.default_labelAlign)
    218         labelLeft = attributes.get('labelLeft', self.default_labelLeft)
    219         text = attributes.text
    220         Fill(parent=self, align=uiconst.TOLEFT, width=2, color=Color.WHITE, opacity=0.75)
    221         self.label = EveHeaderMedium(parent=self, align=labelAlign, text=text, left=labelLeft)
    222 
    223     def SetText(self, text):
    224         self.label.SetText(text)
    225 
    226     def GetText(self):
    227         return self.label.GetText()