alertBanner.py (7467B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\alertBanner.py 2 import enum 3 from carbonui import ButtonStyle, Density, uiconst, TextColor, Align 4 from carbonui.primitives.frame import Frame 5 from carbonui.text.styles import TextBody 6 from carbonui.control.button import Button 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.containerAutoSize import ContainerAutoSize 9 from carbonui.primitives.fill import Fill 10 from carbonui.primitives.sprite import Sprite 11 from carbonui.uianimations import animations 12 from eve.client.script.ui.control.infoIcon import AttentionGlyphIcon, CheckMarkGlyphIcon, ExclamationMarkGlyphIcon, InfoGlyphIcon, WarningGlyphIcon 13 from eve.client.script.ui.eveColor import OMEGA_YELLOW 14 from eve.client.script.ui.eveThemeColor import THEME_ALERT, THEME_FOCUS, THEME_FOCUSDARK 15 16 class AlertBannerStatus(enum.Enum): 17 DANGER = (TextColor.DANGER, WarningGlyphIcon, ButtonStyle.DANGER) 18 WARNING = (THEME_ALERT, ExclamationMarkGlyphIcon, ButtonStyle.WARNING) 19 SUCCESS = (TextColor.SUCCESS, CheckMarkGlyphIcon, ButtonStyle.SUCCESS) 20 INFO = (THEME_FOCUSDARK, InfoGlyphIcon, ButtonStyle.NORMAL) 21 ATTENTION = (OMEGA_YELLOW, AttentionGlyphIcon, ButtonStyle.MONETIZATION) 22 23 def __init__(self, color, icon, button_style): 24 self.color = color 25 self.icon_class = icon 26 self.button_style = button_style 27 28 29 class AlertBanner(Container): 30 default_name = 'alertBanner' 31 32 def __init__(self, status, message, cutoff = False, add_button = False, button_label = '', button_func = None, *args, **kwargs): 33 self._message = message 34 self._status = status 35 self._color = status.color 36 self._icon_class = status.icon_class 37 self._button_style = status.button_style 38 self._add_button = add_button 39 self._cutoff = cutoff 40 self.button_label = button_label 41 self.button_func = button_func 42 super(AlertBanner, self).__init__(*args, **kwargs) 43 self.Load() 44 45 @property 46 def message(self): 47 return self._message 48 49 @message.setter 50 def message(self, value): 51 self._message = value 52 self._label.text = value 53 54 def construct_left_corner_with_fill(self): 55 Sprite(parent=self, name='cornerTop', align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Shared/cornerTop.png', color=self._color, width=8, height=8, opacity=1.0) 56 Sprite(parent=self, name='cornerBottom', align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Shared/cornerBottom.png', color=self._color, width=12, height=12, opacity=0.6) 57 cont_left = ContainerAutoSize(parent=self, name='leftFill', align=uiconst.TOLEFT, padTop=12, width=12) 58 Fill(bgParent=cont_left, color=self._color, opacity=0.6) 59 60 def construct_button(self): 61 cont_button = ContainerAutoSize(parent=self, name='cont_button', alignMode=uiconst.CENTERRIGHT, align=uiconst.TORIGHT) 62 cont_button_inner = ContainerAutoSize(parent=cont_button, name='cont_button_inner', align=uiconst.CENTERRIGHT) 63 self.button_obj = Button(parent=cont_button_inner, name='button', align=uiconst.CENTERRIGHT, density=Density.COMPACT, style=self._button_style, padding=4 if self._cutoff else 8, func=self.button_func, label=self.button_label, state=uiconst.UI_NORMAL) 64 65 def Load(self): 66 if self._cutoff: 67 Frame(bgParent=self, name='bg', align=Align.TOALL, texturePath='res:/UI/Texture/classes/Button/background_cut_bottom_right.png', cornerSize=9, color=self._color[:3] + (0.6,), padLeft=12) 68 else: 69 Fill(bgParent=self, color=self._color, padLeft=12, opacity=0.6) 70 self.construct_left_corner_with_fill() 71 self._icon_class(name='icon', parent=self, align=uiconst.TOLEFT, state=uiconst.UI_DISABLED, width=16, height=16) 72 if self._add_button: 73 self.construct_button() 74 self._label = TextBody(name='message', parent=self, align=uiconst.CENTERLEFT, padding=(36, 12, 0, 13), text=self._message, state=uiconst.UI_NORMAL, color=TextColor.HIGHLIGHT, autoFadeSides=16) 75 76 def set_message(self, message, animate = True): 77 self.message = message 78 if animate: 79 self._label.opacity = 0 80 animations.FadeIn(self._label, duration=0.2) 81 82 83 class AlertBannerAutoSize(ContainerAutoSize): 84 default_height = 30 85 default_alignMode = uiconst.TOLEFT 86 87 def __init__(self, status, message, add_button = False, button_label = '', button_func = None, *args, **kwargs): 88 self._message = message 89 self._status = status 90 self._color = status.color 91 self._icon_class = status.icon_class 92 self._button_style = status.button_style 93 self._add_button = add_button 94 if self._add_button: 95 self.button_label = button_label 96 self.button_func = button_func 97 super(AlertBannerAutoSize, self).__init__(*args, **kwargs) 98 self.construct() 99 100 def construct(self): 101 self.construct_left_corner_with_fill() 102 self.construct_content() 103 if self._add_button: 104 self.construct_button() 105 106 def construct_left_corner_with_fill(self): 107 left_cont = Container(parent=self, name='left_cont', align=uiconst.TOLEFT, width=12) 108 corner_cont = Container(parent=left_cont, name='corner_cont', align=uiconst.TOPLEFT, width=16, height=30) 109 Sprite(parent=corner_cont, name='cornerTop', align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Shared/cornerTop.png', color=self._color, width=8, height=8, opacity=1.0) 110 Sprite(parent=corner_cont, name='cornerBottom', align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Shared/cornerBottom.png', color=self._color, width=12, height=12, opacity=0.6) 111 Fill(bgParent=left_cont, color=self._color, opacity=0.6, padTop=12) 112 113 def construct_content(self): 114 content_cont = ContainerAutoSize(parent=self, name='content_cont', align=uiconst.TOLEFT) 115 Frame(bgParent=content_cont, name='bg', align=Align.TOALL, texturePath='res:/UI/Texture/classes/Button/background_cut_bottom_right.png', cornerSize=9, color=self._color[:3] + (0.6,)) 116 icon_cont = Container(parent=content_cont, name='icon_cont', align=uiconst.TOLEFT, width=16, height=16) 117 self._icon_class(name='icon', parent=icon_cont, align=uiconst.TOLEFT, state=uiconst.UI_DISABLED, width=16, height=16) 118 label_cont = ContainerAutoSize(parent=content_cont, name='label_cont', align=uiconst.TOLEFT) 119 self._label = TextBody(name='message', parent=label_cont, align=uiconst.CENTERLEFT, padding=(14, 0, 14, 0), text=self._message, state=uiconst.UI_NORMAL, color=TextColor.HIGHLIGHT, autoFadeSides=16) 120 content_cont.height = self._label.textheight + 8 121 if self._add_button: 122 self.construct_button(content_cont) 123 124 def construct_button(self, parent): 125 cont_button = ContainerAutoSize(parent=parent, name='cont_button', alignMode=uiconst.CENTERRIGHT, align=uiconst.TOLEFT) 126 cont_button_inner = ContainerAutoSize(parent=cont_button, name='cont_button_inner', align=uiconst.CENTERRIGHT) 127 self.button_obj = Button(parent=cont_button_inner, name='button', align=uiconst.CENTERRIGHT, density=Density.COMPACT, style=self._button_style, padding=4, func=self.button_func, label=self.button_label, state=uiconst.UI_NORMAL)