ctrltab.py (7891B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\ctrltab.py 2 import math 3 import localization 4 import uthread 5 from carbonui import uiconst 6 from carbonui.control.window import Window 7 from carbonui.primitives.frame import Frame 8 from carbonui.window.stack import WindowStack 9 from carbonui.primitives.container import Container 10 from carbonui.primitives.fill import Fill 11 from carbonui.uicore import uicore 12 from eve.client.script.ui import eveThemeColor 13 from eve.client.script.ui.control import eveIcon, eveLabel 14 ICONWIDTH = 50 15 SPACINGWIDTH = 6 16 NUMCOLS = 5 17 BORDER = 5 18 BLOCKSIZE = ICONWIDTH + SPACINGWIDTH 19 FRAMECOLOR = (0.3, 0.3, 0.3, 0.5) 20 FILLCOLOR = (0.0, 0.0, 0.0, 0.8) 21 SELECTCOLOR = eveThemeColor.THEME_FOCUS.rgb + (0.2,) 22 23 class CtrlTabWindow(Window): 24 __guid__ = 'form.CtrlTabWindow' 25 default_windowID = 'CtrlTabWindow' 26 default_apply_content_padding = False 27 28 def ApplyAttributes(self, attributes): 29 Window.ApplyAttributes(self, attributes) 30 self.caption = self.name = 'CtrlTabWindow' 31 self.HideHeader() 32 self.MakeUncollapseable() 33 self.MakeUnMinimizable() 34 self.MakeUnResizeable() 35 self.MakeUnKillable() 36 self.MakeUnstackable() 37 uicore.event.RegisterForTriuiEvents(uiconst.UI_MOUSEDOWN, self.OnGlobalMouseDown) 38 self.currOpenWindows = uicore.registry.GetWindows()[:] 39 self.showOrHide = self.AllWindowsMinimized() 40 self.selectionBoxIndex = None 41 self.windowIcons = [] 42 self.showOrHideMessage = [localization.GetByLabel('UI/Common/Windows/HideWindows'), localization.GetByLabel('UI/Common/Windows/ShowWindows')][self.showOrHide] 43 self.InitializeWindowIcons() 44 self.numIcons = len(self.windowIcons) 45 self.numRows = int(math.ceil(float(self.numIcons) / float(NUMCOLS))) 46 if self.numRows > 1: 47 self.xShift = 0 48 else: 49 self.xShift = (NUMCOLS - self.numIcons) * BLOCKSIZE / 2 50 uthread.new(self.SetWindowSize) 51 self.RenderIcons() 52 self.sr.selectionBox = Container(name='selectionBox', parent=self.sr.main, align=uiconst.RELATIVE, pos=(SPACINGWIDTH, 53 SPACINGWIDTH, 54 ICONWIDTH, 55 ICONWIDTH)) 56 Fill(parent=self.sr.selectionBox, color=SELECTCOLOR) 57 self.sr.selectionBoxMouse = Container(name='selectionBox', parent=self.sr.main, align=uiconst.RELATIVE, pos=(SPACINGWIDTH, 58 SPACINGWIDTH, 59 ICONWIDTH, 60 ICONWIDTH), state=uiconst.UI_HIDDEN) 61 Fill(parent=self.sr.selectionBoxMouse, color=SELECTCOLOR) 62 self.sr.windowText = eveLabel.EveLabelLarge(parent=self.sr.main, align=uiconst.TOBOTTOM, color=(1, 1, 1, 1), state=uiconst.UI_DISABLED, padding=BORDER) 63 64 def SetWindowSize(self): 65 width = BLOCKSIZE * NUMCOLS + SPACINGWIDTH + 2 * BORDER + 2 66 height = BLOCKSIZE * self.numRows + 3 * BORDER + self.sr.windowText.height 67 self.width, _ = self.GetWindowSizeForContentSize(width=width) 68 self.height = height 69 70 def InitializeWindowIcons(self): 71 currOpenWindows = [ wnd for wnd in uicore.registry.GetWindows() if not isinstance(wnd, WindowStack) ] 72 currOpenWindows.sort(key=lambda x: uicore.registry.windowsActiveTimes.get(x.windowID, None), reverse=True) 73 self.windowIcons = [] 74 i = 0 75 for w in currOpenWindows: 76 if not isinstance(w, Window) or w == self: 77 continue 78 if w.icon and isinstance(w.icon, basestring) and w.icon.startswith('c_'): 79 iconNum = 'ui_105_64_45' 80 else: 81 iconNum = w.icon 82 self.windowIcons.append({'id': i, 83 'name': w.windowID, 84 'caption': w.caption, 85 'iconNum': iconNum}) 86 i += 1 87 88 self.windowIcons.append({'id': len(self.windowIcons), 89 'name': self.showOrHideMessage, 90 'caption': self.showOrHideMessage, 91 'iconNum': 'res:/UI/texture/WindowIcons/hidewindows.png', 92 'isShowOrHideIcon': True}) 93 94 def RenderSelectionBox(self): 95 self.sr.selectionBox.left, self.sr.selectionBox.top = self.IndexToPosition(self.selectionBoxIndex) 96 97 def RenderSelectionBoxMouse(self): 98 self.sr.selectionBox.left, self.sr.selectionBox.top = self.IndexToPosition(self.selectionBoxIndex) 99 100 def RenderIcons(self): 101 for i, w in enumerate(self.windowIcons): 102 x, y = self.IndexToPosition(i) 103 icon = eveIcon.Icon(icon=w['iconNum'], parent=self.sr.main, pos=(x, 104 y, 105 ICONWIDTH, 106 ICONWIDTH), ignoreSize=1) 107 icon.OnMouseEnter = (self.OnMouseEnterIcon, w) 108 icon.OnMouseExit = self.OnMouseLeaveIcon 109 icon.OnClick = (self.OnMouseClickIcon, w) 110 111 def SetText(self, text): 112 self.sr.windowText.text = '<center>' + text 113 self.SetWindowSize() 114 115 def OnMouseEnterIcon(self, icon): 116 if icon['id'] != self.selectionBoxIndex: 117 self.sr.selectionBoxMouse.state = uiconst.UI_NORMAL 118 self.sr.selectionBoxMouse.left, self.sr.selectionBoxMouse.top = self.IndexToPosition(icon['id']) 119 self.SetText(icon['caption']) 120 121 def OnMouseLeaveIcon(self): 122 self.sr.selectionBoxMouse.state = uiconst.UI_HIDDEN 123 if self.selectionBoxIndex is not None: 124 self.SetText(self.windowIcons[self.selectionBoxIndex]['caption']) 125 126 def OnMouseClickIcon(self, icon): 127 self.selectionBoxIndex = icon['id'] 128 self.ChooseHilited() 129 130 def IndexToPosition(self, index): 131 colNum = index % NUMCOLS 132 rowNum = (index - colNum) / NUMCOLS 133 xPos = self.xShift + SPACINGWIDTH + colNum * BLOCKSIZE + BORDER 134 yPos = SPACINGWIDTH + rowNum * BLOCKSIZE + BORDER 135 return (xPos, yPos) 136 137 def Next(self): 138 self.Maximize() 139 if self.selectionBoxIndex is None: 140 self.selectionBoxIndex = 1 if self.numIcons else 0 141 else: 142 self.selectionBoxIndex = self.selectionBoxIndex + 1 143 if self.selectionBoxIndex >= self.numIcons: 144 self.selectionBoxIndex = 0 145 self.RenderSelectionBox() 146 caption = self.windowIcons[self.selectionBoxIndex]['caption'] 147 if caption is None or len(caption) == 0: 148 self.SetText(' ') 149 else: 150 self.SetText(self.windowIcons[self.selectionBoxIndex]['caption']) 151 152 def Prev(self): 153 self.Maximize() 154 if self.selectionBoxIndex is None: 155 self.selectionBoxIndex = self.numIcons - 1 156 else: 157 self.selectionBoxIndex = self.selectionBoxIndex - 1 158 if self.selectionBoxIndex < 0: 159 self.selectionBoxIndex = self.numIcons - 1 160 self.RenderSelectionBox() 161 caption = self.windowIcons[self.selectionBoxIndex]['caption'] 162 if caption is None or len(caption) == 0: 163 self.SetText(' ') 164 else: 165 self.SetText(self.windowIcons[self.selectionBoxIndex]['caption']) 166 167 def ChooseHilited(self): 168 winIcon = self.windowIcons[self.selectionBoxIndex] 169 if 'isShowOrHideIcon' in winIcon: 170 self.showOrHide = int(not self.showOrHide) 171 if self.showOrHide: 172 uicore.cmd.CmdMinimizeAllWindows() 173 else: 174 uicore.cmd.CmdMaximizeAllWindows() 175 else: 176 win = Window.GetIfOpen(windowID=winIcon['name']) 177 self.currOpenWindows.remove(win) 178 self.currOpenWindows.insert(0, win) 179 win.Maximize() 180 self.Close() 181 182 def AllWindowsMinimized(self): 183 for w in self.currOpenWindows: 184 if w.state != uiconst.UI_HIDDEN and not w.stacked and w.IsMinimizable(): 185 return False 186 187 return True 188 189 def OnGlobalMouseDown(self, downOn, *args, **kw): 190 if not downOn.IsUnder(self.sr.main): 191 self.Close()