button.py (2775B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\entries\button.py 2 from carbon.client.script.environment.AudioUtil import PlaySound 3 from carbonui import Density, fontconst, uiconst 4 from carbonui.button import styling 5 from carbonui.control.button import Button 6 from carbonui.control.scrollentries import SE_BaseClassCore 7 from eve.client.script.ui.control.eveLabel import EveLabelMedium 8 from eve.client.script.ui.util import uix 9 10 class ButtonEntry(SE_BaseClassCore): 11 __guid__ = 'listentry.Button' 12 __params__ = ['label', 'caption', 'OnClick'] 13 default_showHilite = False 14 15 def Startup(self, args): 16 self.sr.label = EveLabelMedium(parent=self, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, left=8, maxLines=1) 17 self.sr.button = Button(parent=self, align=uiconst.CENTERRIGHT, label='', idx=0, density=Density.COMPACT) 18 19 def Load(self, node): 20 self.sr.node = node 21 self._showHilite = node.get('showHilite', self.default_showHilite) 22 maxLines = node.Get('maxLines', 1) 23 self.sr.label.maxLines = maxLines 24 btnWidth = 0 25 if self.sr.node.Get('OnClick', None): 26 self.sr.button.OnClick = (self.OnButtonClicked,) 27 self.sr.button.SetLabel(self.sr.node.caption) 28 self.sr.button.state = uiconst.UI_NORMAL 29 btnWidth = self.sr.button.width 30 else: 31 self.sr.button.state = uiconst.UI_HIDDEN 32 if maxLines != 1: 33 l, t, w, h = self.GetAbsolute() 34 self.sr.label.width = w - btnWidth - self.sr.label.left * 2 35 self.sr.label.text = self.sr.node.label 36 37 def OnButtonClicked(self, *args): 38 PlaySound(uiconst.SOUND_BUTTON_CLICK) 39 args = self.sr.node.Get('args', (None,)) 40 return self.sr.node.OnClick(*(args + (self.sr.button,))) 41 42 def GetHeight(self, *args): 43 node, width = args 44 if node.Get('OnClick', None): 45 btnLabelWidth = uix.GetTextWidth(node.caption, fontsize=fontconst.EVE_MEDIUM_FONTSIZE) 46 btnWidth = min(256, max(48, btnLabelWidth + 24)) 47 btnHeight = styling.get_height(Density.COMPACT) 48 else: 49 btnWidth = 0 50 btnHeight = 0 51 maxLines = node.Get('maxLines', 1) 52 if maxLines == 1: 53 mainLabelHeight = uix.GetTextHeight(node.label, fontsize=fontconst.EVE_MEDIUM_FONTSIZE, maxLines=1) 54 node.height = max(16, mainLabelHeight + 4, btnHeight + 4) 55 else: 56 width = node.Get('entryWidth', 100) - btnWidth 57 mainLabelHeight = uix.GetTextHeight(node.label, width=width, fontsize=fontconst.EVE_MEDIUM_FONTSIZE) 58 node.height = max(16, mainLabelHeight + 4, btnHeight + 4) 59 return node.height