[wxPython-users] Bitmap text only writes in black under Linux

Robin Dunn robin at alldunn.com
Mon Jun 12 10:40:23 PDT 2006


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))
  >>>

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list