[wxPython] button.py -- Great!!

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] button.py -- Great!!

Gordon Williams
Robin Dunn wrote:
I decided that the library needed a good example of how to do things
likethis, so here it is. The attached module should be just dropped into
yourwxPython/lib directory, and you'll be all set. It contains four
genericbutton classes: wxGenButton, wxGenBitmapButton, wxGenToggleButton,
andwxGenBitmapToggleButton. I don't think there is anything in there
thatrelies on new features since 2.1.11, but if something blows up let me
know.I've only tested them on MSW so far, but GTK should be okay too.


Hi All,

This is great!  Thanks for the example.  I learnt a lot.  Now I can get on
with some real work :)

I have some suggestions before you put it into production (sorry about
messing with your code):

1) Add some button active colour so the button is lighter in the depressed
state using wxSYS_COLOUR_3DLIGHT

    def InitColours(self):
        self.upFaceClr=
wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNFACE) #gw change
        self.downFaceClr  =
wxSystemSettings_GetSystemColour(wxSYS_COLOUR_3DLIGHT) #gw change
        self.textClr    =
wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNTEXT) #gw change
#gw removed

        shadowClr    =
wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNSHADOW)
        highlightClr =
wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNHIGHLIGHT)
        self.shadowPen    = wxPen(shadowClr, 1, wxSOLID)
        self.highlightPen = wxPen(highlightClr, 1, wxSOLID)

        self.focusIndPen  = wxPen(self.textClr, 1, wxUSER_DASH) #gw change


    def OnPaint(self, event):
        (width, height) = self.GetClientSizeTuple()
        x1 = y1 = 0
        x2 = width-1
        y2 = height-1
        dc = wxPaintDC(self)
        if self.up:
            dc.SetBackground(wxBrush(self.upFaceClr, wxSOLID)) #gw change
        else:
            dc.SetBackground(wxBrush(self.downFaceClr, wxSOLID)) #gw change
        dc.Clear()
        self.DrawBezel(dc, x1, y1, x2, y2)
        self.DrawLabel(dc, width, height)
        if self.hasFocus and self.useFocusInd:
            self.DrawFocusIndicator(dc, width, height)



2) Currently the default size of the wxGenButton is different from the
wxButton, both in height and width.  If you supply text that is too large,
it spills out of the button.  It would be nice if the default size would be
the same and expand to allow for the length of the text.  How do they
calculate default size for a normal wxButton?

3) As mentioned earlier, it complains about font.Ok



And a question:  When you use SetUseFocusIndicator(FALSE) it removes the
focus indicator but it still accepts a focus.  Therefore the button will
change if a key hit. Is there a way so the button will not have any focus
at all.  Therefore, when you hit the tab key it will by-pass the button
altogether?

Thanks again

Gordon Williams



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

[wxPython] Re: button.py -- Great!!

Robin Dunn
>
> I have some suggestions before you put it into production (sorry about
> messing with your code):
>
> 1) Add some button active colour so the button is lighter in the depressed
> state using wxSYS_COLOUR_3DLIGHT

Yep.  I had thought too of that but hadn't gotten to it yet.  I'd also like
to figure out a way to recalulate this color as well as the shadow and
highlight edge colors if the programmer changes the background color.  For
example if I call SetBackgroundColour(wxBLUE) then currently the extra colors
stay the same as the system defaults.


>
> 2) Currently the default size of the wxGenButton is different from the
> wxButton, both in height and width.  If you supply text that is too large,
> it spills out of the button.  It would be nice if the default size would be
> the same and expand to allow for the length of the text.  How do they
> calculate default size for a normal wxButton?
>

Already done in my working copy.  The one issue remaining is that the default
size is calculated in the __init__ method but the programmer may change the
size of the bezel later with SetBezelWidth, which can make the default size
really stupid looking...


> 3) As mentioned earlier, it complains about font.Ok
>

This will change with the next release of wxPython...


> And a question:  When you use SetUseFocusIndicator(FALSE) it removes the
> focus indicator but it still accepts a focus.  Therefore the button will
> change if a key hit. Is there a way so the button will not have any focus
> at all.  Therefore, when you hit the tab key it will by-pass the button
> altogether?
>

Use the wxWindow.Enable method.  The button classes check IsEnabled() before
doing anything, and the wxDialog and wxPanel check it before tabing to the
subwindows.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users