There are versions of the generic buttons classes that use the native
theme to draw the button, so they will end up looking a lot more native.
It's not perfect however so you are on the right track if you want a
truly native button.
You'll need to do something like the following:
* Create a new empty bitmap using wx.EmptyBitmap(width, height). You
can estimate the size needed by taking the size of the bitmap, adding
the size needed to draw the text, and add in some space for margins
between the text and the bitmap, etc. You can measure the size needed
for the text by creating a temporary DC using wx.ClientDC, setting the
desired font and then calling dc.GetTextExtent.
* Create a wx.MemoryDC passing it the empty bitmap you just created.
* Set the dc's background brush to the desired color and then Clear()
the DC.
* Draw the image you want to appear next to the text with DrawBitmap.
* Draw the text with DrawText.
* Destroy the memory DC with Python's del operator. This will release
the bitmap so you can use it with the bitmap button.
* Create and use the bitmap button like normal.
--
Robin Dunn
Software Craftsman
http://wxPython.org
Actually the most important thing that I forgot to mention is that the
native wx.Button in 2.9 will be able to have a bitmap in addition to the
text label. So while seeing an example of the above in the wiki would
be good for the general education of newbies, there will eventually be a
better way to do it. :-)
--To unsubscribe, send email to wxPython-user...@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
If you've got the XP themes active then the native buttons do not draw
with a solid color, but rather use the theme APIs to draw something like
a gradient/texture to give it a 3D rounded look. SystemSettings can
only give you a solid color that is an approximation of what will be
used for the themed widget.
You've got a couple options for a workaround. First you can go ahead
and clear the bitmap's background to the color you get from
SystemSettings, draw your icon and text, and then set the bitmap's mask
to that color. That way the anti-aliased pixels next to the text will
be blended with almost the right color as if the text was drawn directly
on the button, but the rest of it will be transparent and the real
button should show through when it is drawn.
The other option is to use the wx.RendererNative to use the theme to
draw the whole button, not just the bitmap. This is essentially what
the Themed* classes in wx.lib.buttons do.