[wxPython-users] adding control captions on gradient buttonpanel

Andrea Gavana andrea.gavana at gmail.com
Tue Dec 18 16:16:53 PST 2007


Hi,

On Dec 19, 2007 1:10 AM, C M wrote:
> On Dec 18, 2007 4:19 PM, Andrea Gavana <andrea.gavana at gmail.com> wrote:
> > Hi,
> >
> >
> >
> >
> > On Dec 18, 2007 8:14 AM, C M wrote:
> > > I'd like to try to use a ButtonPanel with a gradient to hold some
> controls,
> > > but I also would like to have static text near the controls to indicate
> > > their function or caption them.  But if I just add a wxStaticTextCtrl to
> the
> > > ButtonPanel, the background color of the statictext is used and of
> course it
> > > doesn't look quite right on the gradient (you can see the edges of the
> > > rectangle).
> > >
> > > But with ButtonPanel, there is a main caption text, as well as button
> > > captions, and both of these are done in such a way as they do not
> produce
> > > this problem--they just sit nicely over the gradient.  I don't
> understand
> > > how this is done because I don't yet understand how DC and drawing
> works.
> > >
> > > I was wondering if there is or could be a way to allow placement of text
> on
> > > a gradient ButtonPanel so that it looks good with the gradient? (the
> > > positioning itself may require sizers, but one thing at a time).  And
> can
> > > font and font size also be specified?
> >
> > The only way I can see it right now is to hack the ButtonPanel source
> > code... the problem is, whatever you do with a wx.StaticText, it does
> > not let the underlying "theme" (or gradient) shine through it, it uses
> > its own background colour or the one inherited by its parent (if it is
> > a solid one). Have you tried doing something like:
> >
> > yourStaticText.Bind(wx.EVT_ERASE_BACKGROUND, self.OnErase)
> >
> > def OnErase(self, event):
> >
> >    pass
> >
> > ? I don't know if this will change anything.
>
> Yup, didn't work.

I imagined it... :-(

> > If it doesn't, then you might consider hacking the wx.lib.stattext code to
> try to let the
> > gradient shine through. It would be an easy task to solve if someone
> > could answer to this question:
> >
> > Is there a way to ask a wx.lib.stattext *not* to paint its rectangular
> > background but let the underground colour (parent
> > colour/theme/gradient) shine through?
> >
>
> I'll hope for that answer.  In the meantime, do you happen to understand how
> the main caption is done such that this doesn't have this problem?  Because
> I thought maybe I could try that approach?

Well, I can understand it as I wrote ButtonPanel :-D . Anyway, you can
basically do it with whatever custom panel you want, by defining a
custom event handler for wx.EVT_PAINT event for your panel (self is
your custom panel, a wx.Panel or a wx.PyPanel):

self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

def OnPaint(self, event):
    dc = wx.BufferedPaintDC(self)

    # Here you draw the gradient in the panel and other stuff

    dc.DrawText(self.myText, xPosition, yPosition)

def OnEraseBackground(self, event):
    pass


So, there is nothing that draws the text background/rectangle and then
the underlying theme/gradient shines through.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/




More information about the wxpython-users mailing list