switch.py (2404B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\switch.py 2 from carbonui.primitives.container import Container 3 from carbonui.uianimations import animations 4 import carbonui.const as uiconst 5 from eve.client.script.ui.control.themeColored import FillThemeColored, FrameThemeColored 6 COLOR_GREEN = (0.0, 1.0, 0.0, 0.5) 7 COLOR_RED = (1.0, 0.0, 0.0, 0.5) 8 9 class Switch(Container): 10 default_state = uiconst.UI_NORMAL 11 default_align = uiconst.TOPLEFT 12 default_width = 30 13 default_height = 10 14 15 def ApplyAttributes(self, attributes): 16 Container.ApplyAttributes(self, attributes) 17 self.isEnabled = attributes.get('isEnabled', True) 18 self.disabled = False 19 FrameThemeColored(parent=self) 20 btnCont = Container(parent=self) 21 self.onBtn = Container(parent=self, align=uiconst.TOLEFT_PROP, width=0.5, bgColor=COLOR_GREEN, state=uiconst.UI_DISABLED) 22 self.offBtn = Container(parent=self, align=uiconst.TORIGHT_PROP, width=0.5, bgColor=COLOR_RED, state=uiconst.UI_DISABLED) 23 self.knob = FillThemeColored(parent=btnCont, align=uiconst.TOLEFT_PROP, width=0.5, state=uiconst.UI_DISABLED, colorType=uiconst.COLORTYPE_UIHILIGHT, opacity=1.0) 24 self.SetStateNotAnimated() 25 26 def SetStateNotAnimated(self): 27 if self.isEnabled: 28 self.knob.left = self.width / 2 29 else: 30 self.knob.left = 0 31 32 def OnClick(self, *args): 33 if self.disabled: 34 return 35 self.isEnabled = not self.isEnabled 36 self.UpdateKnob() 37 38 def UpdateKnob(self): 39 if self.isEnabled: 40 self.knob.StopAnimations() 41 animations.MorphScalar(self.knob, 'left', startVal=self.knob.left, endVal=self.width / 2, duration=0.1) 42 else: 43 animations.MorphScalar(self.knob, 'left', startVal=self.knob.left, endVal=0, duration=0.1) 44 45 def SetOnline(self): 46 self.isEnabled = True 47 self.UpdateKnob() 48 49 def SetOffline(self): 50 self.isEnabled = False 51 self.UpdateKnob() 52 53 def Close(self): 54 super(Switch, self).Close() 55 56 def Disable(self): 57 self.disabled = True 58 self.opacity = 0.5 59 if self.isEnabled: 60 self.offBtn.opacity = 0.0 61 else: 62 self.onBtn.opacity = 0.0 63 64 def Enable(self): 65 self.disabled = False 66 self.opacity = 1.0