class PanelEntryBase(uiprimitives.Container): __guid__ = 'neocom.PanelEntryBase' __notifyevents__ = ['ProcessNeocomBlinkPulse'] isDragObject = True default_state = uiconst.UI_NORMAL default_align = uiconst.TOTOP default_icon = None default_height = 42 def ApplyAttributes(self, attributes): uiprimitives.Container.ApplyAttributes(self, attributes) sm.RegisterNotify(self) self.btnData = attributes.btnData if hasattr(self.btnData, 'panelEntryHeight'): self.height = self.btnData.panelEntryHeight self.blinkThread = None self._openNeocomPanel = None self.main = uiprimitives.Container(parent=self, name='main') self.hoverBG = uicontrols.Frame( bgParent=self.main, texturePath='res:/UI/Texture/classes/Neocom/panelEntryBG.png', opacity=0.0) if self.btnData.id == 'map_beta' and IsMapBetaEnabled(): Sprite(parent=self.main, align=uiconst.TOPLEFT, pos=(10, 2, 11, 29), texturePath='res:/UI/Texture/Shared/betaTag.png', state=uiconst.UI_DISABLED) size = self.height - 4 self.icon = GlowSprite(parent=self.main, name='icon', state=uiconst.UI_DISABLED, texturePath=self.GetIconPath(), pos=(10, 2, size, size), iconOpacity=0.75) self.label = uicontrols.Label(parent=self.main, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, text=self.GetLabel(), autowidth=True, autoheight=True, left=self.icon.left + self.icon.width + 8) if settings.char.ui.Get('neocomAlign', uiconst.TOLEFT) == uiconst.TOLEFT: rotation = 0.0 else: rotation = math.pi self.expanderIcon = uicontrols.Icon(parent=self, name='expanderIcon', align=uiconst.CENTERRIGHT, left=10, icon='ui_38_16_228', rotation=rotation) self.SetExpanderState() self.blinkSprite = uiprimitives.Sprite( bgParent=self, name='blinkSprite', texturePath='res:/UI/Texture/classes/Neocom/panelEntryBG.png', state=uiconst.UI_HIDDEN, opacity=1.0) def GetIconPath(self): return self.btnData.iconPath or neocomCommon.ICONPATH_DEFAULT def PrepareDrag(self, dragContainer, dragSource): dragContainer.width = dragContainer.height = 48 icon = uicontrols.Icon(parent=dragContainer, name='icon', state=uiconst.UI_DISABLED, icon=self.GetIconPath(), size=48, ignoreSize=True) Frame(parent=dragContainer, name='baseFrame', state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Shared/buttonDOT.png', color=(1.0, 1.0, 1.0, 1.0), cornerSize=8, spriteEffect=trinity.TR2_SFX_DOT, blendMode=trinity.TR2_SBM_ADD) Frame(parent=dragContainer, offset=-9, cornerSize=13, name='shadow', state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Shared/bigButtonShadow.png') return (0, 0) def HasOpenPanel(self): return self._openNeocomPanel is not None and not self._openNeocomPanel.destroyed def SetExpanderState(self): self.HideExpander() def ShowExpander(self): self.expanderIcon.state = uiconst.UI_DISABLED def HideExpander(self): self.expanderIcon.state = uiconst.UI_HIDDEN def OnClick(self, *args): self.btnData.CheckContinueBlinking() self.OnClickCommand() sm.GetService('neocom').CloseAllPanels() def OnClickCommand(self): pass def GetLabel(self): label = None if self.btnData.cmdName: cmd = uicore.cmd.commandMap.GetCommandByName(self.btnData.cmdName) if cmd and cmd.callback: label = cmd.GetName() return label or self.btnData.label def GetRequiredWidth(self): return self.label.width + self.icon.width + 35 def GetMenu(self): return self.btnData.GetMenu() def LoadTooltipPanel(self, tooltipPanel, *args): tooltipPanel.LoadGeneric3ColumnTemplate() if getattr(self.btnData, 'cmdName', None): cmd = uicore.cmd.commandMap.GetCommandByName(self.btnData.cmdName) tooltipPanel.AddCommandTooltip(cmd) ButtonBase.LoadTooltipPanelDetails(self, tooltipPanel, self.btnData) def GetTooltipPointer(self): return uiconst.POINT_LEFT_2 def OnMouseEnter(self, *args): sm.GetService('neocom').CloseChildrenPanels(self.btnData.parent) uicore.animations.FadeIn(self.hoverBG, duration=0.3) self.icon.OnMouseEnter() def OnMouseExit(self, *args): uicore.animations.FadeOut(self.hoverBG, duration=0.3) self.icon.OnMouseExit() def GetDragData(self, *args): if self.btnData.isDraggable: return [self.btnData] def BlinkOnce(self): self.blinkSprite.Show() uicore.animations.SpSwoopBlink(self.blinkSprite, rotation=math.pi, duration=1.0) def ProcessNeocomBlinkPulse(self): if self.btnData.isBlinking: self.BlinkOnce()
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 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 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 MenuEntryViewCore(Container): __guid__ = 'uicls.MenuEntryViewCore' LABELVERTICALPADDING = 2 LABELHORIZONTALPADDING = 8 default_fontsize = 10 default_fontStyle = None default_fontFamily = None default_fontPath = None def ApplyAttributes(self, attributes): Container.ApplyAttributes(self, attributes) self.fontStyle = attributes.get('fontStyle', self.default_fontStyle) self.fontFamily = attributes.get('fontFamily', self.default_fontFamily) self.fontPath = attributes.get('fontPath', self.default_fontPath) self.fontsize = attributes.get('fontsize', self.default_fontsize) self.cursor = 1 self.clicked = 0 self.submenu = None self.submenuview = None self.sr.hilite = None self.Prepare() def Prepare(self, *args): self.Prepare_Triangle_() self.Prepare_Label_() self.sr.label.OnMouseDown = self.OnMouseDown self.sr.label.OnMouseUp = self.OnMouseUp def Prepare_Triangle_(self, *args): self.triangle = GlowSprite( parent=self, align=uiconst.CENTERRIGHT, state=uiconst.UI_HIDDEN, idx=0, texturePath='res:/UI/Texture/Icons/1_16_14.png', pos=(0, 0, 16, 16)) def Prepare_Label_(self, *args): label = Label(parent=self, pos=(8, 1, 0, 0), align=uiconst.CENTERLEFT, letterspace=1, fontStyle=self.fontStyle, fontFamily=self.fontFamily, fontPath=self.fontPath, fontsize=self.fontsize, state=uiconst.UI_DISABLED) self.sr.label = label def Prepare_Hilite_(self, *args): self.sr.hilite = ListEntryUnderlay(parent=self) def Setup(self, entry, size, menu, identifier): text = entry.caption self.sr.label.fontsize = size self.sr.label.text = text self.menu = menu menuIconSize = menu.iconSize icon = None if menuIconSize: icon = Sprite(parent=self, pos=(0, 0, menuIconSize, menuIconSize), align=uiconst.RELATIVE, idx=0, state=uiconst.UI_DISABLED, name='icon') icon.LoadIcon(entry.icon or 'ui_1_16_101', ignoreSize=True) self.sr.label.left += menuIconSize self.id = identifier if not entry.enabled: if icon: icon.SetAlpha(0.5) self.sr.label.SetRGB(1.0, 1.0, 1.0, 0.5) if isinstance(entry.value, basestring): self.sr.label.text += ' (' + entry.value + ')' self.width = self.sr.label.textwidth + self.sr.label.left + self.LABELHORIZONTALPADDING self.height = max(menuIconSize, self.sr.label.textheight + self.LABELVERTICALPADDING) if not entry.enabled: self.state = uiconst.UI_DISABLED if isinstance(entry.value, (list, tuple)): self.triangle.state = uiconst.UI_DISABLED self.submenu = entry.value def _OnClose(self): if self.submenuview is not None and not self.submenuview.destroyed: self.submenuview.Close() self.submenuview = None self.menu = None self.submenu = None self.expandTimer = None self.collapseTimer = None Container._OnClose(self) def OnMouseDown(self, *etc): uthread.new(self.MouseDown) def MouseDown(self): if not self.destroyed and self.submenu: self.Expand() def OnMouseUp(self, *etc): if not self.submenu and uicore.uilib.mouseOver in (self, self.sr.label): self.menu.ActivateEntry(self.id) uthread.new(CloseContextMenus) def OnMouseEnter(self, *args): uicore.Message('ContextMenuEnter') if self.sr.hilite is None: self.Prepare_Hilite_() self.sr.hilite.ShowHilite() self.expandTimer = AutoTimer(10, self.ExpandMenu) if self.triangle.display: self.triangle.OnMouseEnter() def ExpandMenu(self): for each in self.parent.children: if each != self and getattr(each, 'submenuview', None): each.Collapse() self.expandTimer = None if uicore.uilib.mouseOver in (self, self.sr.label) and self.submenu: self.Expand() def OnMouseExit(self, *args): if self.sr.hilite: self.sr.hilite.HideHilite() if self.triangle.display: self.triangle.OnMouseExit() def toggle(self): if self.submenuview: self.Collapse() else: self.Expand() def Collapse(self): self.collapseTimer = None if self.submenuview and self.submenuview.destroyed: self.submenuview = None elif self.submenuview: self.submenuview.Collapse() self.submenuview = None def Expand(self): if not self.submenuview: for each in self.parent.children: if each != self and getattr(each, 'submenuview', None): each.Collapse() if self.submenu[0] == 'isDynamic': menu = CreateMenuView( CreateMenuFromList(apply(self.submenu[1], self.submenu[2])), self.parent) else: menu = CreateMenuView(CreateMenuFromList(self.submenu), self.parent) if not menu: return w = uicore.desktop.width h = uicore.desktop.height aL, aT, aW, aH = self.GetAbsolute() menu.top = max(0, min(h - menu.height, aT)) if aL + aW + menu.width <= w: menu.left = aL + aW + 2 else: aL, aT, aW, aH = self.GetAbsolute() menu.left = aL - menu.width + 5 uicore.layer.menu.children.insert(0, menu) if self.destroyed: CloseContextMenus() return self.submenuview = menu
class RadialMenuActionBase(uiprimitives.Transform): """ this is the base for the buttons in the radial menu """ __guid__ = 'uicls.RadialMenuActionBase' default_left = 0 default_top = 0 default_align = uiconst.CENTERTOP default_state = uiconst.UI_NORMAL moveOverSliceBasePath = 'res:/UI/Texture/classes/RadialMenu/mouseOver_%s.png' selelectedBasePath = 'res:/UI/Texture/classes/RadialMenu/selected_%s.png' emptySliceBasePath = 'res:/UI/Texture/classes/RadialMenu/emptySlice_%s.png' sliceBasePath = 'res:/UI/Texture/classes/RadialMenu/slice_%s.png' default_width = 100 default_height = 70 default_fullWidth = default_width default_fullHeight = default_height def ApplyAttributes(self, attributes): uiprimitives.Transform.ApplyAttributes(self, attributes) self.degree = attributes.get('degree', 0) self.func = None self.funcArgs = None self.itemID = attributes.itemID self.isDisabled = False self.degreeWidth = attributes.degreeWidth self.labelPath = '' self.labelText = '' self.isEmpty = attributes.get('isEmpty', False) self.commandName = None self.isHilighted = False self.fullWidth = attributes.sizeInfo.buttonWidth self.fullHeight = attributes.sizeInfo.buttonHeight iconPar = uiprimitives.Transform(parent=self, name='iconPar', pos=(0, 3, 32, 32), state=uiconst.UI_DISABLED, align=uiconst.CENTER) iconPar.rotation = mathUtil.DegToRad(self.degree) self.icon = GlowSprite(parent=iconPar, name='icon', pos=(0, 0, 32, 32), state=uiconst.UI_DISABLED, align=uiconst.CENTER) selectionSlice = SpriteUnderlay(parent=self, name='selectionSlice', state=uiconst.UI_DISABLED, texturePath=self.selelectedBasePath % self.degreeWidth, align=uiconst.TOALL, opacity=0.9) selectionSlice.display = False self.selectionSlice = selectionSlice if self.isEmpty: sliceTexturePath = self.emptySliceBasePath % self.degreeWidth else: sliceTexturePath = self.sliceBasePath % self.degreeWidth self.hilite = SpriteUnderlay(parent=self, name='hilite', state=uiconst.UI_DISABLED, texturePath=self.selelectedBasePath % self.degreeWidth, align=uiconst.TOALL, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, opacity=0.0) self.availableSlice = SpriteUnderlay(parent=self, name='availableSlice', state=uiconst.UI_DISABLED, texturePath=sliceTexturePath, align=uiconst.TOALL, opacity=attributes.get( 'buttonBackgroundOpacity', 0.8)) self.unavailableSlice = SpriteUnderlay( parent=self, name='unavailableSlice', state=uiconst.UI_DISABLED, texturePath=sliceTexturePath, align=uiconst.TOALL, colorType=uiconst.COLORTYPE_UIBASE, opacity=0.85) self.unavailableSlice.display = False self.sliceInUse = self.availableSlice def SetButtonInfo(self, labelPath, labelArgs, buttonInfo=None, isEnabled=True, iconTexturePath=None): self.labelPath = labelPath if isEnabled: self.labelText = localization.GetByLabel(labelPath, **labelArgs) else: self.labelText = '' self.name = 'actionButton_%s' % labelPath.split('/')[-1] if isEnabled: self.SetEnabled() else: self.SetDisabled() if iconTexturePath is not None: self.SetIcon(iconTexturePath) if buttonInfo is None: return buttonFunc = buttonInfo.func buttonFuncArgs = buttonInfo.funcArgs if not isinstance(buttonFunc, (types.MethodType, types.LambdaType)): return self.func = buttonFunc self.funcArgs = buttonFuncArgs self.commandName = getattr(buttonInfo, 'commandName', None) @telemetry.ZONE_METHOD def ShowButtonHilite(self): if self.isHilighted: return uicore.animations.FadeTo(self.hilite, self.hilite.opacity, 0.15, duration=uiconst.TIME_ENTRY) self.isHilighted = True sm.GetService('audio').SendUIEvent('ui_radial_mouseover_play') self.icon.OnMouseEnter() @telemetry.ZONE_METHOD def HideButtonHilite(self): if not self.isHilighted: return uicore.animations.FadeTo(self.hilite, self.hilite.opacity, 0.0, duration=uiconst.TIME_EXIT) self.isHilighted = False self.sliceInUse.Show() if self.isDisabled: self.icon.opacity = 0.4 else: self.icon.opacity = 1.0 self.icon.OnMouseExit() def ShowSelectionSlice(self): self.availableSlice.display = False self.unavailableSlice.display = False self.selectionSlice.display = True def SetIcon(self, texturePath): self.icon.SetTexturePath(texturePath) def SetDisabled(self): if self.sliceInUse != self.unavailableSlice: self.sliceInUse = self.unavailableSlice self.availableSlice.display = False self.unavailableSlice.display = True self.isDisabled = True self.icon.opacity = 0.4 def SetEnabled(self): if self.sliceInUse != self.availableSlice: self.sliceInUse = self.availableSlice self.unavailableSlice.display = False self.availableSlice.display = True self.isDisabled = False self.icon.opacity = 1.0 def AnimateSize(self, sizeRatio=0.5, duration=0.5, grow=True): if grow: startHeight = sizeRatio * self.fullHeight startWidth = sizeRatio * self.fullWidth endHeight = self.fullHeight endWidth = self.fullWidth else: startHeight = self.height startWidth = self.width endHeight = sizeRatio * self.fullHeight endWidth = sizeRatio * self.fullWidth uicore.animations.MorphScalar(self, 'height', startVal=startHeight, endVal=endHeight, duration=duration) uicore.animations.MorphScalar(self, 'width', startVal=startWidth, endVal=endWidth, duration=duration) def SelectButtonSlice(self, duration=0.5): self.ShowSelectionSlice() animationDuration = uix.GetTiDiAdjustedAnimationTime(duration, minTiDiValue=0.1, minValue=0.02) curvePoints = ([0.0, 0], [0.5, -10], [1, -10]) uicore.animations.MorphScalar(self, 'top', duration=animationDuration, curveType=curvePoints, sleep=False) curvePoints = ([0.0, self.selectionSlice.opacity ], [0.5, self.selectionSlice.opacity], [0.6, 1.5], [0.7, 0.5], [0.8, 1.5], [1, 0]) uicore.animations.MorphScalar(self, 'opacity', duration=animationDuration, curveType=curvePoints, sleep=True)
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)