class ScrollHandle(Container):
    """
    The handle bar dragged around to control a scroll
    """
    __guid__ = 'uicls._ScrollHandle'
    default_name = 'scrollHandle'
    default_width = 50
    default_height = 50
    OPACITY_INACTIVE = 0.6
    OPACITY_ACTIVE = 1.0

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.sr.hilite = None
        self._dragging = False
        self.Prepare_()

    def Prepare_(self):
        self.hilite = RaisedUnderlay(bgParent=self,
                                     opacity=self.OPACITY_INACTIVE,
                                     hideFrame=True)

    def OnMouseDown(self, btn, *args):
        self.hilite.OnMouseDown()

    def OnMouseMove(self, *etc):
        pass

    def OnMouseUp(self, btn, *args):
        self.hilite.OnMouseUp()

    def AnimEntry(self, duration=0.15):
        self.hilite.OnMouseEnter(duration=duration)
        uicore.animations.FadeTo(self.hilite,
                                 self.hilite.opacity,
                                 self.OPACITY_ACTIVE,
                                 duration=duration)

    def OnMouseEnter(self, *args):
        self.AnimEntry()

    def AnimExit(self, duration=0.5):
        self.hilite.OnMouseExit(duration=duration)
        uicore.animations.FadeTo(self.hilite,
                                 self.hilite.opacity,
                                 self.OPACITY_INACTIVE,
                                 duration=duration)

    def OnMouseExit(self, *args):
        self.AnimExit()
示例#2
0
class BigButton(BaseButton):
    __guid__ = 'xtriui.BigButton'
    default_align = uiconst.TOPLEFT
    default_width = 64
    default_height = 64
    default_name = 'bigButton'
    default_state = uiconst.UI_NORMAL
    OPACITY_IDLE = 0.0
    OPACITY_HOVER = 0.5
    OPACITY_MOUSEDOWN = 0.85

    def Startup(self, width, height, iconMargin=0, iconOpacity=0.75):
        self.sr.icon = GlowSprite(parent=self,
                                  pos=(0, 0, 0, 0),
                                  padding=(iconMargin, iconMargin, iconMargin,
                                           iconMargin),
                                  name='icon',
                                  state=uiconst.UI_DISABLED,
                                  align=uiconst.TOALL,
                                  filter=True,
                                  iconOpacity=iconOpacity)
        self.sr.hilite = Fill(bgParent=self,
                              color=(0.7, 0.7, 0.7, 0.0),
                              state=uiconst.UI_HIDDEN)
        self.setfocus = 0
        self.killfocus = 0
        self.width = width
        self.height = height
        self.sr.smallcaption = None
        self.sr.caption = None
        self.sr.activeHilite = Frame(bgParent=self,
                                     color=(1, 1, 1, 0.3),
                                     state=uiconst.UI_HIDDEN)
        self.AdjustSizeAndPosition(width, height)
        self.underlay = RaisedUnderlay(name='backgroundFrame', bgParent=self)

    def AdjustSizeAndPosition(self, width, height):
        self.sr.enterAlt = min(2, max(6, self.height / 16))

    def SetIconByIconID(self, iconID):
        if iconID is not None:
            self.sr.icon.LoadIcon(iconID)

    def SetTexturePath(self, texturePath):
        self.sr.icon.SetTexturePath(texturePath)

    def SetInCaption(self, capstr):
        if self.sr.caption:
            self.sr.caption.Close()
        if '&' in capstr and ';' in capstr:
            capstr = self.ParseHTML(capstr)
        caption = EveLabelLargeUpper(text=capstr,
                                     parent=self,
                                     idx=0,
                                     align=uiconst.CENTER)
        caption.state = uiconst.UI_DISABLED
        self.sr.caption = caption

    def SetCaption(self, capstr):
        self.SetSmallCaption(capstr)

    def SetSmallCaption(self, capstr, inside=0, maxWidth=None):
        if not self.sr.smallcaption:
            self.sr.smallcaption = EveLabelSmall(text='',
                                                 parent=self,
                                                 state=uiconst.UI_DISABLED,
                                                 idx=0,
                                                 width=self.width)
        self.sr.smallcaption.busy = 1
        if inside:
            self.sr.smallcaption.SetAlign(uiconst.CENTER)
        else:
            self.sr.smallcaption.SetAlign(uiconst.CENTERTOP)
            self.sr.smallcaption.top = self.height + 2
        self.sr.smallcaption.width = maxWidth or self.width
        self.sr.smallcaption.busy = 0
        self.sr.smallcaption.text = '<center>' + capstr

    def ParseHTML(self, text):
        for k in translatetbl:
            text = text.replace(k, translatetbl[k])

        return text

    def OnMouseExit(self, *etc):
        self.underlay.OnMouseExit()
        if self.MouseExit:
            self.MouseExit(self)
        self.timer = None
        self.sr.icon.OnMouseExit()

    def OnMouseEnter(self, *etc):
        eve.Message('CCCellEnter')
        self.underlay.OnMouseEnter()
        if self.MouseEnter:
            self.MouseEnter(self)
        self.sr.icon.OnMouseEnter()

    def OnMouseDown(self, *args):
        if not self.enabled:
            return
        self.Blink(0)
        self.underlay.OnMouseDown()
        self.sr.icon.OnMouseDown()

    def OnMouseUp(self, *args):
        if uicore.uilib.mouseOver == self:
            self.underlay.OnMouseUp()
        self.sr.icon.OnMouseUp()

    def Blink(self, on_off=1, blinks=3):
        if on_off:
            self.sr.hilite.display = True
            uicore.animations.FadeTo(self.sr.hilite,
                                     0.0,
                                     0.3,
                                     duration=0.75,
                                     curveType=uiconst.ANIM_WAVE,
                                     loops=blinks)
        else:
            uicore.animations.FadeOut(self.sr.hilite, 0.0)

    def OnSetFocus(self, *args):
        if self.setfocus:
            self.sr.activeHilite.state = uiconst.UI_DISABLED

    def OnKillFocus(self, *args):
        if self.killfocus:
            self.sr.activeHilite.state = uiconst.UI_HIDDEN
示例#3
0
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()
示例#4
0
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)
示例#5
0
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)