From a0971ef7196b13d2e1b8f3d23d388d336073c38e Mon Sep 17 00:00:00 2001 From: Werner F Bruhin Date: Wed, 28 May 2014 11:41:48 +0200 Subject: [PATCH] - allow to define a 'Focus' colour as an alternative to the pulse on focus --- demo/agw/AquaButton.py | 8 +++++++- unittests/test_lib_agw_aquabutton.py | 1 + wx/lib/agw/aquabutton.py | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/demo/agw/AquaButton.py b/demo/agw/AquaButton.py index ce4e66ed..b1d82131 100644 --- a/demo/agw/AquaButton.py +++ b/demo/agw/AquaButton.py @@ -39,6 +39,7 @@ class AquaButtonDemo(wx.Panel): self.backColour = wx.ColourPickerCtrl(self.mainPanel, colour=self.btn2.GetBackgroundColour()) self.hoverColour = wx.ColourPickerCtrl(self.mainPanel, colour=self.btn2.GetHoverColour()) + self.focusColour = wx.ColourPickerCtrl(self.mainPanel, colour=self.btn2.GetHoverColour()) self.textColour = wx.ColourPickerCtrl(self.mainPanel, colour=self.btn2.GetForegroundColour()) self.pulseCheck = wx.CheckBox(self.mainPanel, -1, "Pulse On Focus") @@ -52,7 +53,7 @@ class AquaButtonDemo(wx.Panel): mainSizer = wx.BoxSizer(wx.VERTICAL) btnSizer = wx.FlexGridSizer(2, 2, 15, 15) - colourSizer = wx.FlexGridSizer(2, 3, 1, 10) + colourSizer = wx.FlexGridSizer(2, 4, 1, 10) btnSizer.Add(self.btn1, 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL) btnSizer.Add(self.pulseCheck, 0, wx.ALIGN_CENTER_VERTICAL) @@ -61,14 +62,17 @@ class AquaButtonDemo(wx.Panel): labelBack = wx.StaticText(self.mainPanel, -1, "Background Colour") labelHover = wx.StaticText(self.mainPanel, -1, "Hover Colour") + labelFocus = wx.StaticText(self.mainPanel, -1, "Focus Colour") labelText = wx.StaticText(self.mainPanel, -1, "Text Colour") colourSizer.Add(labelBack) colourSizer.Add(labelHover) + colourSizer.Add(labelFocus) colourSizer.Add(labelText) colourSizer.Add(self.backColour, 0, wx.EXPAND) colourSizer.Add(self.hoverColour, 0, wx.EXPAND) + colourSizer.Add(self.focusColour, 0, wx.EXPAND) colourSizer.Add(self.textColour, 0, wx.EXPAND) btnSizer.Add(colourSizer, 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL) @@ -112,6 +116,8 @@ class AquaButtonDemo(wx.Panel): self.btn2.SetBackgroundColour(colour) elif obj == self.hoverColour: self.btn2.SetHoverColour(colour) + elif obj == self.focusColour: + self.btn2.SetFocusColour(colour) else: self.btn2.SetForegroundColour(colour) diff --git a/unittests/test_lib_agw_aquabutton.py b/unittests/test_lib_agw_aquabutton.py index a4087584..b8612e04 100644 --- a/unittests/test_lib_agw_aquabutton.py +++ b/unittests/test_lib_agw_aquabutton.py @@ -35,6 +35,7 @@ class lib_agw_aquabutton_Tests(wtc.WidgetTestCase): btn2.SetShadowColour(wx.Colour('grey')) btn2.SetRectColour(wx.WHITE) btn2.SetHoverColour(wx.BLACK) + btn2.SetFocusColour(wx.GREEN) btn3 = AB.AquaToggleButton(self.frame, -1, None, 'Toggle') btn3.SetToggle(True) diff --git a/wx/lib/agw/aquabutton.py b/wx/lib/agw/aquabutton.py index f443cd08..bd630e16 100644 --- a/wx/lib/agw/aquabutton.py +++ b/wx/lib/agw/aquabutton.py @@ -222,6 +222,7 @@ class AquaButton(wx.Control): else: self._backColour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_ACTIVECAPTION) self._hoverColour = self.LightColour(self._backColour, 30) + self._focusColour = self.LightColour(self._backColour, 40) self._disableColour = self.LightColour(self._backColour, 70) self._textColour = wx.WHITE self._shadowColour = wx.Colour("grey") @@ -294,6 +295,9 @@ class AquaButton(wx.Control): elif self._mouseAction == HOVER: clr = self._hoverColour + elif self._hasFocus: + clr = self._focusColour + elif not self.IsEnabled(): clr = self._disableColour @@ -827,6 +831,27 @@ class AquaButton(wx.Control): return self._textColour + def SetFocusColour(self, colour): + """ + Sets the button colour when the button has focus. + + :param `colour`: a valid :class:`Colour` object. + """ + + self._focusColour = colour + self.Invalidate() + + + def GetFocusColour(self): + """ + Returns the button colour when the button has focus. + + :return: An instance of :class:`Colour`. + """ + + return self._hoverColour + + def Invalidate(self): """ Invalidate the saved bitmap and refresh the button. """