Exemplo n.º 1
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)
Exemplo n.º 2
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()
Exemplo n.º 3
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)