[wxPython-users] Bitmap text only writes in black under Linux
Steve Holden
steve at holdenweb.com
Mon Jun 12 15:21:12 PDT 2006
Robin Dunn wrote:
> Steve Holden wrote:
>
>> Another little problem I've uncovered as move testing from Windows to
>> Linux is in writing text to a bitmap. Since the program was
>> originally PIL-based the code is ugly (until I have time to rewrite
>> it completely in wx* primitives), but on Windows it has the merit of
>> working.
>>
>> On Linux, however, the first problem I had to face is that a
>> wx.EmptyBitmap doesn't get created with all-black content on Linux
>> like it does on Windows; I overcame that by creating a PIL image and
>> converting it to a bitmap.
>
>
>
>> One definite problem I have discovered is that the width and height
>> of the text returned by GetTextExtent() in the code above appears,
>> according to debugging prints, to be (0, 0) on Ubuntu Linux, while on
>> Windows I get definite sizes. When the background is non-black I do
>> see (black) text, but this makes me wonder whether there's some font
>> oddity or subtlety I have overlooked.
>
>
>
> What version are you using? This works for me with 2.6.3.2, (running in
> a PyShell):
>
> >>> import wx
> >>> f = wx.Frame(None)
> >>> p = wx.Panel(f)
> >>> f.Show()
> True
> >>> b = wx.EmptyBitmap(200,100)
> >>> dc = wx.MemoryDC()
> >>> dc.SelectObject(b)
> >>> dc.SetBackground(wx.Brush("black"))
> >>> dc.Clear()
> >>> dc.SetTextForeground(wx.Colour(173, 216, 230))
> >>> dc.GetTextExtent("Hello Steve")
> (94, 19)
> >>> dc.DrawText("Hello Steve", 10,10)
> >>> dc.SelectObject(wx.NullBitmap)
> >>> sb = wx.StaticBitmap(p, -1, b, (20,20))
> >>>
>
Thanks for the code sample. I'm away from the machine for the next two
days, but I'll try it when I get back home.
The software could well be out of date as it's either just what was
delivered with Ubuntu Breezy Badger or a copy I downloaded when that
release was new. So I'll update it on principle anyway (but after trying
your suggested code on the old version for reference).
Thanks, also, for showing me how I might migrate away from PIL - it's
not that I don't like PIL, but I'm not doing anything I couldn't do
natively within wx, I suspect. Terrific support! How's the OSCON
tutorial coming?
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the wxpython-users
mailing list