class ButtonBase(uiprimitives.Container): """ An abstract button that others inherit from """ __guid__ = 'neocom.ButtonBase' __notifyevents__ = ['ProcessNeocomBlinkPulse'] default_name = 'ButtonBase' default_state = uiconst.UI_NORMAL default_align = uiconst.TOPLEFT default_isDraggable = True PADHORIZONTAL = 6 PADVERTICAL = 4 ACTIVEFILL_DEFAULTALPHA = 0.5 ACTIVEFILL_HOVERALPHA = 0.8 def ApplyAttributes(self, attributes): uiprimitives.Container.ApplyAttributes(self, attributes) self.btnData = attributes.btnData self.btnNum = attributes.btnNum self.width = attributes.width self._isDraggable = attributes.get('isDraggable', self.default_isDraggable) self._openNeocomPanel = None self.height = self.width self.top = self.height * self.btnNum self.panel = None self.blinkThread = None self.realTop = self.top self.dragEventCookie = None self.disableClick = False self.iconSize = self.height - 2 * self.PADVERTICAL self.iconTransform = uiprimitives.Transform(name='iconTransform', parent=self, align=uiconst.TOALL, scalingCenter=(0.5, 0.5)) self.iconLabelCont = None if self.btnData.id == 'map_beta': Sprite(parent=self.iconTransform, align=uiconst.TOPLEFT, pos=(0, 0, 11, 29), texturePath='res:/UI/Texture/Shared/betaTag.png', state=uiconst.UI_DISABLED) self.icon = GlowSprite(parent=self.iconTransform, name='icon', state=uiconst.UI_DISABLED, align=uiconst.CENTER, width=self.iconSize, height=self.iconSize, iconOpacity=1.0) self.UpdateIcon() PAD = 1 self.blinkSprite = SpriteThemeColored( bgParent=self, name='blinkSprite', texturePath='res:/UI/Texture/classes/Neocom/buttonBlink.png', state=uiconst.UI_HIDDEN, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW) self.activeFrame = FrameThemeColored( bgParent=self, name='hoverFill', texturePath='res:/UI/Texture/classes/Neocom/buttonActive.png', cornerSize=5, state=uiconst.UI_HIDDEN, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW) self.CheckIfActive() self.dropFrame = uicontrols.Frame(parent=self, name='hoverFrame', color=util.Color.GetGrayRGBA( 1.0, 0.5), state=uiconst.UI_HIDDEN) sm.RegisterNotify(self) def UpdateIcon(self): texturePath = self._GetPathFromIconNum(self.btnData.iconPath) self.icon.SetTexturePath(texturePath) def CheckIfActive(self): if self.btnData.isActive: self.activeFrame.Show() else: self.activeFrame.Hide() def GetIconPath(self): return self._GetPathFromIconNum(self.btnData.iconPath) def _GetPathFromIconNum(self, iconNum): if iconNum.startswith('res:/'): return iconNum parts = iconNum.split('_') if len(parts) == 2: sheet, iconNum = parts iconSize = uix.GetIconSize(sheet) return 'res:/ui/texture/icons/%s_%s_%s.png' % ( int(sheet), int(iconSize), int(iconNum)) elif len(parts) == 4: root, sheet, iconSize, iconNum = parts if root == 'ui': root = 'icons' return 'res:/ui/texture/%s/%s_%s_%s.png' % ( root, int(sheet), int(iconSize), int(iconNum)) else: return neocomCommon.ICONPATH_DEFAULT def IsDraggable(self): return self._isDraggable def SetDraggable(self, isDraggable): self._isDraggable = isDraggable def GetMenu(self): return self.btnData.GetMenu() def LoadTooltipPanel(self, tooltipPanel, *args): isOpen = self._openNeocomPanel and not self._openNeocomPanel.destroyed if isOpen: return tooltipPanel.LoadGeneric3ColumnTemplate() blinkHintStr = None if getattr(self.btnData, 'cmdName', None): cmd = uicore.cmd.commandMap.GetCommandByName(self.btnData.cmdName) tooltipPanel.AddCommandTooltip(cmd) blinkHintStr = self.btnData.blinkHint else: label = None if self.IsSingleWindow(): wnd = self.GetWindow() if not wnd.destroyed: label = wnd.GetCaption() elif self.btnData.children: label = self.btnData.children[0].wnd.GetNeocomGroupLabel() mainStr = label or self.btnData.label tooltipPanel.AddLabelMedium(text=mainStr) self.LoadTooltipPanelDetails(tooltipPanel, self.btnData) if blinkHintStr: tooltipPanel.AddLabelMedium(text=blinkHintStr, width=200, colSpan=tooltipPanel.columns) def LoadTooltipPanelDetails(cls, tooltipPanel, btnData): if btnData.id == 'wallet': showFractions = settings.char.ui.Get('walletShowCents', False) personalWealth = util.FmtISK( sm.GetService('wallet').GetWealth(), showFractions) tooltipPanel.AddLabelValue( label=localization.GetByLabel('Tooltips/Neocom/Balance'), value=personalWealth) canAccess = sm.GetService( 'wallet').HaveReadAccessToCorpWalletDivision( session.corpAccountKey) if canAccess: corpWealth = util.FmtISK( sm.GetService('wallet').GetCorpWealthCached1Min( session.corpAccountKey), showFractions) tooltipPanel.AddLabelValue(label=localization.GetByLabel( 'Tooltips/Neocom/CorporationBalance'), value=corpWealth) def GetTooltipPointer(self): return uiconst.POINT_LEFT_2 def IsSingleWindow(self): return False def OnMouseEnter(self, *args): self.btnData.SetBlinkingOff() self.icon.OnMouseEnter() def OnMouseExit(self, *args): self.icon.OnMouseExit() def OnMouseDown(self, *args): if not self.IsDraggable(): return if not uicore.uilib.leftbtn: return self.isDragging = False self.mouseDownY = uicore.uilib.y if self.dragEventCookie is not None: uicore.event.UnregisterForTriuiEvents(self.dragEventCookie) self.dragEventCookie = uicore.event.RegisterForTriuiEvents( uiconst.UI_MOUSEMOVE, self.OnDrag) uicore.animations.Tr2DScaleTo(self.iconTransform, self.iconTransform.scale, (0.95, 0.95), duration=0.1) self.icon.OnMouseDown() def OnMouseUp(self, *args): if uicore.uilib.mouseOver == self: uicore.animations.Tr2DScaleTo(self.iconTransform, self.iconTransform.scale, (1.0, 1.0), duration=0.1) if self.dragEventCookie is not None: uicore.event.UnregisterForTriuiEvents(self.dragEventCookie) self.dragEventCookie = None self.icon.OnMouseUp() def OnDragEnd(self, *args): uicore.event.UnregisterForTriuiEvents(self.dragEventCookie) self.dragEventCookie = None self.isDragging = False sm.GetService('neocom').OnButtonDragEnd(self) self.CheckIfActive() def OnDrag(self, *args): if math.fabs(self.mouseDownY - uicore.uilib.y) > 5 or self.isDragging: if not self.isDragging: uicore.event.RegisterForTriuiEvents(uiconst.UI_MOUSEUP, self.OnDragEnd) self.disableClick = True self.isDragging = True sm.GetService('neocom').OnButtonDragged(self) return True def OnClick(self, *args): if not self or self.destroyed: return self.btnData.CheckContinueBlinking() if not self.disableClick: self.OnClickCommand() if not self or self.destroyed: return self.disableClick = False if self.dragEventCookie: uicore.event.UnregisterForTriuiEvents(self.dragEventCookie) def OnDblClick(self, *args): """ Swallow double click event so that we don't get two OnClick events """ pass def OnClickCommand(self): """ Overridden by subclasses """ pass def OnSwitched(self): uicore.effect.MorphUIMassSpringDamper(item=self, attrname='opacity', float=1, newVal=1.0, minVal=0, maxVal=2.0, dampRatio=0.45, frequency=15.0, initSpeed=0, maxTime=4.0, callback=None, initVal=0.0) self.isDragging = False self.disableClick = False def GetDragData(self, *args): if self.btnData.isDraggable: return [self.btnData] def BlinkOnce(self, duration=0.7): self.blinkSprite.Show() uicore.animations.SpSwoopBlink(self.blinkSprite, rotation=math.pi * 0.75, duration=duration) def ProcessNeocomBlinkPulse(self): if self.btnData.isBlinking: self.BlinkOnce() def OnDropData(self, source, dropData): if not sm.GetService('neocom').IsValidDropData(dropData): return index = self.btnData.parent.children.index(self.btnData) sm.GetService('neocom').OnBtnDataDropped(dropData[0], index) def OnDragEnter(self, panelEntry, dropData): if not sm.GetService('neocom').IsValidDropData(dropData): return sm.GetService('neocom').OnButtonDragEnter(self.btnData, dropData[0]) uthread.new(self.ShowPanelOnMouseHoverThread) def OnDragExit(self, *args): sm.GetService('neocom').OnButtonDragExit(self.btnData, args) def ToggleNeocomPanel(self): isOpen = self._openNeocomPanel and not self._openNeocomPanel.destroyed sm.GetService('neocom').CloseAllPanels() if isOpen: self._openNeocomPanel = None else: self._openNeocomPanel = sm.GetService('neocom').ShowPanel( triggerCont=self, panelClass=self.GetPanelClass(), panelAlign=neocomCommon.PANEL_SHOWONSIDE, parent=uicore.layer.abovemain, btnData=self.btnData) RefreshTooltipForOwner(self) def ShowPanelOnMouseHoverThread(self): if len(self.btnData.children) <= 1: return blue.pyos.synchro.Sleep(500) if not self or self.destroyed: return if uicore.uilib.mouseOver == self: self.ToggleNeocomPanel() def GetPanelClass(self): return neocomPanels.PanelGroup def SetAsActive(self): self.btnData.isActive = True self.activeFrame.state = uiconst.UI_DISABLED def SetAsInactive(self): self.btnData.isActive = False self.activeFrame.state = uiconst.UI_HIDDEN
class ToggleButtonGroupButton(Container): OPACITY_SELECTED = 1.0 OPACITY_HOVER = 0.125 TEXT_TOPMARGIN = 4 default_padRight = 1 default_align = uiconst.TOLEFT_PROP default_state = uiconst.UI_NORMAL default_iconSize = 32 default_colorSelected = None default_iconOpacity = 1.0 default_showBg = True def ApplyAttributes(self, attributes): Container.ApplyAttributes(self, attributes) self.controller = attributes.controller self.btnID = attributes.Get('btnID', None) self.panel = attributes.Get('panel', None) self.colorSelected = attributes.Get('colorSelected', self.default_colorSelected) label = attributes.Get('label', None) iconPath = attributes.Get('iconPath', None) iconSize = attributes.Get('iconSize', None) iconSize = iconSize or self.default_iconSize iconOpacity = attributes.get('iconOpacity', self.default_iconOpacity) self.hint = attributes.Get('hint', None) self.isSelected = False self.isDisabled = attributes.Get('isDisabled', False) self.showBg = attributes.Get('showBg', self.default_showBg) self.ConstructLayout(iconOpacity, iconPath, iconSize, label) self.selectedBG = RaisedUnderlay(bgParent=self, color=self.colorSelected, isGlowEdgeRotated=True) if not self.showBg: self.selectedBG.display = False if self.isDisabled: self.SetDisabled() def ConstructLayout(self, iconOpacity, iconPath, iconSize, label): if iconPath: self.AddIcon(self, iconOpacity, iconPath, iconSize) self.label = None else: clipper = Container(parent=self, clipChildren=True) self.AddLabel(clipper, label) self.icon = None def AddIcon(self, parent, iconOpacity, iconPath, iconSize): self.icon = GlowSprite(parent=parent, align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=iconSize, height=iconSize, texturePath=iconPath, iconOpacity=iconOpacity, color=Color.GRAY6) def AddLabel(self, parent, label): self.label = LabelThemeColored(text=label, parent=parent, align=uiconst.CENTER, fontsize=EVE_SMALL_FONTSIZE) def GetAutoHeight(self): if self.label: return self.label.textheight + self.TEXT_TOPMARGIN * 2 if self.icon: return self.icon.height return 0 def SetDisabled(self): self.isDisabled = True if self.icon: self.icon.opacity = 0.1 if self.label: self.label.opacity = 0.1 if self.showBg: self.selectedBG.SetDisabled() def SetEnabled(self): self.isDisabled = False if self.showBg: self.selectedBG.SetEnabled() def OnMouseEnter(self, *args): if not self.isSelected and not self.isDisabled: self.selectedBG.OnMouseEnter() if self.icon: self.icon.OnMouseEnter() else: uicore.animations.FadeTo(self.label, self.label.opacity, OPACITY_LABEL_HOVER, duration=uiconst.TIME_ENTRY) def OnMouseExit(self, *args): if self.isDisabled: return if not self.isSelected: self.selectedBG.OnMouseExit() if self.icon: self.icon.OnMouseExit() elif not self.isSelected: uicore.animations.FadeTo(self.label, self.label.opacity, OPACITY_LABEL_IDLE, duration=uiconst.TIME_EXIT) def OnMouseDown(self, *args): if self.isDisabled: return if self.icon: self.icon.OnMouseDown() self.selectedBG.OnMouseDown() def OnMouseUp(self, *args): if self.isDisabled: return if self.icon: self.icon.OnMouseUp() self.selectedBG.OnMouseUp() def SetSelected(self, animate=True): self.isSelected = True if not self.showBg: self.selectedBG.display = True self.selectedBG.Select() if self.label: self.label.opacity = OPACITY_LABEL_HOVER if self.icon: self.icon.OnMouseExit() def SetDeselected(self, animate=True): self.isSelected = False if self.label: self.label.opacity = 1.0 if self.isDisabled: return if not self.showBg: self.selectedBG.display = False self.selectedBG.Deselect() def IsSelected(self): return self.isSelected def OnClick(self, *args): if not self.isDisabled: self.controller.Select(self)
class Button(ButtonCore): __guid__ = 'uicontrols.Button' default_alwaysLite = False default_iconSize = 32 default_icon = None default_color = None def ApplyAttributes(self, attributes): self.color = attributes.get('color', self.default_color) self.iconPath = attributes.get('icon', self.default_icon) self.iconSize = attributes.get('iconSize', self.default_iconSize) args = attributes.get('args', None) ButtonCore.ApplyAttributes(self, attributes) if args == 'self': self.args = self def Prepare_(self): self.sr.label = LabelThemeColored( parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, opacity=OPACITY_LABEL_IDLE, fontsize=10) if self.iconPath is not None: if self.iconSize: width = self.iconSize height = self.iconSize else: width = height = min(self.width, self.height) self.icon = GlowSprite(parent=self, state=uiconst.UI_DISABLED, align=uiconst.CENTER, pos=(0, 0, width, height), texturePath=self.iconPath, color=self.color, iconOpacity=0.75) self.sr.label.state = uiconst.UI_HIDDEN self.width = width + 4 self.height = height + 4 else: self.icon = None self.sr.hilite = Fill(bgParent=self, color=(0.7, 0.7, 0.7, 0.5), state=uiconst.UI_HIDDEN) self.sr.activeframe = FrameThemeColored( parent=self, name='activeline', state=uiconst.UI_HIDDEN, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, opacity=0.1) self.underlay = RaisedUnderlay(name='backgroundFrame', bgParent=self, state=uiconst.UI_DISABLED, color=self.color) def Update_Size_(self): if self.iconPath is None: self.width = min( 256, self.fixedwidth or max(40, self.sr.label.width + 20)) self.height = self.fixedheight or max( 18, min(32, self.sr.label.textheight + 4)) def SetLabel_(self, label): if not self or self.destroyed: return text = self.text = label self.sr.label.text = text self.Update_Size_() def OnSetFocus(self, *args): if self.disabled: return if self and not self.destroyed and self.parent and self.parent.name == 'inlines': if self.parent.parent and self.parent.parent.sr.node: browser = uiutil.GetBrowser(self) if browser: uthread.new(browser.ShowObject, self) if self and not self.destroyed and self.sr and self.sr.activeframe: self.sr.activeframe.state = uiconst.UI_DISABLED btns = self.GetDefaultBtnsInSameWnd() if btns: self.SetWndDefaultFrameState(btns, 0) def OnMouseEnter(self, *args): self.Blink(False) if not self.disabled: self.underlay.OnMouseEnter() if self.icon: self.icon.OnMouseEnter() else: uicore.animations.FadeTo(self.sr.label, self.sr.label.opacity, OPACITY_LABEL_HOVER, duration=uiconst.TIME_ENTRY) def OnMouseExit(self, *args): self.underlay.OnMouseExit() if self.icon: self.icon.OnMouseExit() else: uicore.animations.FadeTo(self.sr.label, self.sr.label.opacity, OPACITY_LABEL_IDLE, duration=uiconst.TIME_EXIT) def OnMouseDown(self, *args): if self.disabled: return if self.mousedownfunc: if type(self.args) == tuple: self.mousedownfunc(*self.args) else: self.mousedownfunc(self.args or self) self.underlay.OnMouseDown() if self.icon: self.icon.OnMouseDown() else: uicore.animations.FadeTo(self.sr.label, self.sr.label.opacity, OPACITY_LABEL_MOUSEDOWN, duration=0.3) def OnMouseUp(self, *args): if self.mouseupfunc: if type(self.args) == tuple: self.mouseupfunc(*self.args) else: self.mouseupfunc(self.args or self) if not self.disabled: self.underlay.OnMouseUp() if self.icon: self.icon.OnMouseUp() else: uicore.animations.FadeTo(self.sr.label, self.sr.label.opacity, OPACITY_LABEL_HOVER) def Confirm(self, *args): ButtonCore.Confirm(self) self.underlay.Blink() def SetColor(self, color): self.underlay.SetFixedColor(color) def Disable(self): ButtonCore.Disable(self) self.underlay.SetDisabled() def Enable(self): ButtonCore.Enable(self) self.underlay.SetEnabled() def Blink(self, on_off=1, blinks=1000, time=800): self.blinking = on_off if on_off: self.underlay.Blink(blinks) else: self.underlay.StopBlink()
class ToggleButtonGroupButton(Container): OPACITY_SELECTED = 1.0 OPACITY_HOVER = 0.125 default_padRight = 1 default_align = uiconst.TOLEFT_PROP default_state = uiconst.UI_NORMAL default_iconSize = 32 default_colorSelected = None def ApplyAttributes(self, attributes): Container.ApplyAttributes(self, attributes) self.controller = attributes.controller self.btnID = attributes.Get('btnID', None) self.panel = attributes.Get('panel', None) self.colorSelected = attributes.Get('colorSelected', self.default_colorSelected) label = attributes.Get('label', None) iconPath = attributes.Get('iconPath', None) iconSize = attributes.Get('iconSize', None) iconSize = iconSize or self.default_iconSize self.hint = attributes.Get('hint', None) self.isSelected = False self.isDisabled = attributes.Get('isDisabled', False) if iconPath: self.icon = GlowSprite(parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=iconSize, height=iconSize, texturePath=iconPath, iconOpacity=0.75, color=Color.WHITE) self.label = None else: self.label = LabelUnderlay(text=label, parent=self, align=uiconst.CENTER, fontsize=10) self.icon = None self.selectedBG = RaisedUnderlay(bgParent=self, color=self.colorSelected, isGlowEdgeRotated=True) if self.isDisabled: self.SetDisabled() def SetDisabled(self): self.isDisabled = True if self.icon: self.icon.opacity = 0.1 if self.label: self.label.opacity = 0.1 self.selectedBG.SetDisabled() def SetEnabled(self): self.isDisabled = False self.selectedBG.SetEnabled() def OnMouseEnter(self, *args): if not self.isSelected and not self.isDisabled: self.selectedBG.OnMouseEnter() if self.icon: self.icon.OnMouseEnter() else: uicore.animations.FadeTo(self.label, self.label.opacity, 1.5, duration=uiconst.TIME_ENTRY) def OnMouseExit(self, *args): if self.isDisabled: return if not self.isSelected: self.selectedBG.OnMouseExit() if self.icon: self.icon.OnMouseExit() elif not self.isSelected: uicore.animations.FadeTo(self.label, self.label.opacity, 1.0, duration=uiconst.TIME_EXIT) def OnMouseDown(self, *args): if self.isDisabled: return if self.icon: self.icon.OnMouseDown() self.selectedBG.OnMouseDown() def OnMouseUp(self, *args): if self.isDisabled: return if self.icon: self.icon.OnMouseUp() self.selectedBG.OnMouseUp() def SetSelected(self, animate=True): self.isSelected = True self.selectedBG.Select() if self.label: self.label.opacity = 1.5 if self.icon: self.icon.OnMouseExit() def SetDeselected(self, animate=True): self.isSelected = False if self.label: self.label.opacity = 1.0 if self.isDisabled: return self.selectedBG.Deselect() def IsSelected(self): return self.isSelected def OnClick(self, *args): if not self.isDisabled: self.controller.Select(self)