I have found that wx.lib.agw.flatnotebook.FlatNotebook does not work
when colors are specified as tuples. They must be wx.Colour instances
instead.
Other wx windows accept color parameter as tuples and as wx.Colour
instances
(e.g. wx.Frame - SetBackgroundColour). The documentation of wx.Colour
says:
In wxPython there are typemaps that will automatically convert from a
colour name,
from a '#RRGGBB' colour hex value string, or from a 3 or 4 integer
tuple to a
wx.Colour object when calling C++ methods that expect a wxColour. This
means
that the following are all equivallent:
win.SetBackgroundColour(wxColour(0,0,255))
win.SetBackgroundColour('BLUE')
win.SetBackgroundColour('#0000FF')
win.SetBackgroundColour((0,0,255))
I looked into the sourcecode of flatnotebook and found that the
problem is that
color attributes are accessed with Red()/Green()/Blue() methods. For a
test I replaced these
methods with indexes (e.g. colour.Red() -> colour[0]). After this
change the
colors can be specified as tuples or wx.Colour instances, but strings
like
'#0000FF' are still not possible.
It is not a big problem but it would be fine when all types of colors
would be
possible in all window-types to avoid such pitfalls. Are there any
plans for such
a change ?
Here is a sample-code for demonstration (tested with wx version
2.8.10.1 and 2.9.2.4):
import wx
import wx.lib.agw.flatnotebook as fnb
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "TestFrame")
#bgcolor = wx.Colour(255,200,200) # this works for the
Frame and the FlatNotebook
bgcolor = (255,200,200) # this does not work for
FlatNotebook
#bgcolor = '#FFC8C8' # this does not work for
FlatNotebook
self.SetBackgroundColour(bgcolor)
book = fnb.FlatNotebook(self, wx.ID_ANY)
book.SetTabAreaColour(bgcolor)
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
sizer.Add(book, 1, wx.EXPAND)
page1 = wx.Panel(self)
book.AddPage(page1, "Page1")
app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()