small.py (5255B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\window\header\small.py 2 from carbonui import uiconst 3 from carbonui.primitives.container import Container 4 from carbonui.text.color import TextColor 5 from carbonui.uianimations import animations 6 from carbonui.window.header.base import WindowHeaderBase 7 from carbonui.window.header.caption import WindowCaption 8 9 class SmallWindowHeader(Container, WindowHeaderBase): 10 HAS_SUFFICIENT_BOTTOM_PADDING = True 11 12 def __init__(self, show_caption = True, fixed_height = None): 13 self._show_caption = show_caption 14 self._caption_label = None 15 self._fixed_height = fixed_height 16 super(SmallWindowHeader, self).__init__() 17 18 @staticmethod 19 def caption_font_size(window): 20 return 12 21 22 @staticmethod 23 def caption_color(window): 24 if window.active: 25 return TextColor.HIGHLIGHT 26 elif window.IsLightBackgroundEnabled(): 27 return TextColor.NORMAL 28 else: 29 return TextColor.SECONDARY 30 31 @property 32 def extra_content(self): 33 return self._extra_content 34 35 @property 36 def fixed_height(self): 37 return self._fixed_height 38 39 @fixed_height.setter 40 def fixed_height(self, value): 41 if value != self._fixed_height: 42 self._fixed_height = value 43 window = self.window 44 if window is not None: 45 self._update_height(window) 46 47 @property 48 def show_caption(self): 49 return self._show_caption 50 51 @show_caption.setter 52 def show_caption(self, value): 53 if self._show_caption != value: 54 self._show_caption = value 55 window = self.window 56 if window is not None: 57 self._update_caption(window) 58 59 def mount(self, window): 60 super(SmallWindowHeader, self).mount(window) 61 self._layout(window) 62 self._update_height(window) 63 self._update_caption(window) 64 window.on_active_changed.connect(self._on_active_changed) 65 window.on_caption_changed.connect(self._on_caption_changed) 66 window.on_collapsed_changed.connect(self._on_collapsed_changed) 67 window.on_header_inset_changed.connect(self._on_header_inset_changed) 68 window.on_stacked_changed.connect(self._on_stacked_changed) 69 70 def unmount(self, window): 71 super(SmallWindowHeader, self).unmount(window) 72 window.on_active_changed.disconnect(self._on_active_changed) 73 window.on_caption_changed.disconnect(self._on_caption_changed) 74 window.on_collapsed_changed.disconnect(self._on_collapsed_changed) 75 window.on_header_inset_changed.disconnect(self._on_header_inset_changed) 76 window.on_stacked_changed.disconnect(self._on_stacked_changed) 77 78 def _on_active_changed(self, window): 79 self._update_caption(window, animate=True) 80 81 def _on_caption_changed(self, window): 82 self._update_caption(window) 83 84 def _on_collapsed_changed(self, window): 85 self._update_caption(window, animate=True) 86 87 def _on_header_inset_changed(self, window): 88 self._main_cont.padding = self._desired_padding(window) 89 90 def _on_stacked_changed(self, window): 91 self._update_height(window) 92 93 def _desired_height(self, window): 94 if window.stacked: 95 return 0 96 elif self._fixed_height is not None: 97 return self._fixed_height 98 else: 99 return 32 100 101 @staticmethod 102 def _desired_padding(window): 103 left, right = window.header_inset 104 return (left, 105 0, 106 right, 107 0) 108 109 def _update_height(self, window): 110 self.height = self._desired_height(window) 111 112 def _update_caption(self, window, animate = False): 113 if self._show_caption or window.collapsed: 114 if self._caption_label is None: 115 self._create_caption_label(window) 116 else: 117 self._caption_label.font_size = self.caption_font_size(window) 118 caption_color = self.caption_color(window) 119 if animate: 120 animations.SpColorMorphTo(self._caption_label, startColor=self._caption_label.color, endColor=caption_color, duration=uiconst.TIME_ENTRY) 121 else: 122 self._caption_label.color = caption_color 123 self._caption_label.text = window.caption 124 self._caption_label.padLeft = 0 125 elif not self._show_caption: 126 if self._caption_label is not None: 127 self._caption_label.Close() 128 self._caption_label = None 129 130 def _create_caption_label(self, window): 131 self._caption_label = WindowCaption(parent=self._main_cont, text=window.caption, font_size=self.caption_font_size(window), color=self.caption_color(window), padding=(0, 0, 8, 0)) 132 133 def _layout(self, window): 134 left_inset, right_inset = window.header_inset 135 self._main_cont = Container(name='_main_cont', parent=self, align=uiconst.TOALL, padding=(left_inset, 136 0, 137 right_inset, 138 0)) 139 self._create_caption_label(window) 140 self._extra_content = Container(name='extra_content', parent=self._main_cont, align=uiconst.TOALL, clipChildren=True)