FlatNotebook and color parameters as tuples

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

You could make the change yourself and submit a patch. Probably the best would be to convert parameters to a wx.Colour upon entry to the FNB functions if the parameter is not already a wx.Colour. That way the internal code that is expecting a wx.Colour object will not have to be modified. Something like this would probably work, where clr is the incoming parameter:

     if isinstance(clr, (list, tuple)):
         clr = wx.Colour(*clr)
     elif isinstance(clr, basestring):
         clr = wx.Colour(clr)

···

On 10/26/11 7:07 AM, ErwinP wrote:

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 ?

--
Robin Dunn
Software Craftsman

Hi All,

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 ?

You could make the change yourself and submit a patch. Probably the best would be to convert parameters to a wx.Colour upon entry to the FNB functions if the parameter is not already a wx.Colour. That way the internal code that is expecting a wx.Colour object will not have to be modified. Something like this would probably work, where clr is the incoming parameter:

if isinstance(clr, (list, tuple)):

    clr = wx.Colour(*clr)

elif isinstance(clr, basestring):

    clr = wx.Colour(clr)

Applied in SVN for FlatNotebook, please let me know if it does what you asked for.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 26 October 2011 20:02, Robin Dunn wrote:

On 10/26/11 7:07 AM, ErwinP wrote:

import wx

Hi Andrea,

The string version does not work in FormatColour:

wrong:
    elif isinstance(clr, basestring):
        colour = wx.Colour(colour)

correct:
    elif isinstance(colour, basestring):
        c = wx.Colour()
        c.SetFromName(colour)
        colour = c

Erwin

···

On 26 Okt., 21:12, Andrea Gavana <andrea.gav...@gmail.com> wrote:

Hi All,

On 26 October 2011 20:02, Robin Dunn wrote:

> On 10/26/11 7:07 AM, ErwinP wrote:

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

> You could make the change yourself and submit a patch. Probably the best
> would be to convert parameters to a wx.Colour upon entry to the FNB
> functions if the parameter is not already a wx.Colour. That way the
> internal code that is expecting a wx.Colour object will not have to be
> modified. Something like this would probably work, where clr is the
> incoming parameter:

> if isinstance(clr, (list, tuple)):
> clr = wx.Colour(*clr)
> elif isinstance(clr, basestring):
> clr = wx.Colour(clr)

Applied in SVN for FlatNotebook, please let me know if it does what you
asked for.

Andrea.

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

>>> import PyQt4.QtGui

Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named PyQt4.QtGui

>>> import pygtk

Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named pygtk

>>> import wx

Hi Andrea,

The string version does not work in FormatColour:

wrong:

elif isinstance(clr, basestring):

    colour = wx.Colour(colour)

correct:

elif isinstance(colour, basestring):

    c = wx.Colour()

    c.SetFromName(colour)

    colour = c

Thanks, fixed in SVN using wx.NamedColour for string inputs.

Andrea.

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

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 27 October 2011 00:45, ErwinP wrote:

import wx

Hi,

There is still a typo:
wrong:
    elif isinstance(clr, basestring):
correct:
    elif isinstance(colour, basestring):

Ewin

···

On 27 Okt., 22:35, Andrea Gavana <andrea.gav...@gmail.com> wrote:

On 27 October 2011 00:45, ErwinP wrote:

> Hi Andrea,

> The string version does not work in FormatColour:

> wrong:
> elif isinstance(clr, basestring):
> colour = wx.Colour(colour)

> correct:
> elif isinstance(colour, basestring):
> c = wx.Colour()
> c.SetFromName(colour)
> colour = c

Thanks, fixed in SVN using wx.NamedColour for string inputs.

Andrea.

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

>>> import PyQt4.QtGui

Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named PyQt4.QtGui

>>> import pygtk

Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named pygtk

>>> import wx

Thanks, re-fixed in SVN… I’m very sloppy tonight…

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://xoomer.alice.it/infinity77/

···

On 28 October 2011 00:06, ErwinP wrote:

On 27 Okt., 22:35, Andrea Gavana andrea.gav...@gmail.com wrote:

On 27 October 2011 00:45, ErwinP wrote:

Hi Andrea,

The string version does not work in FormatColour:

wrong:

elif isinstance(clr, basestring):

   colour = wx.Colour(colour)

correct:

elif isinstance(colour, basestring):

   c = wx.Colour()
   c.SetFromName(colour)
   colour = c

Thanks, fixed in SVN using wx.NamedColour for string inputs.Hi,

There is still a typo:

wrong:

elif isinstance(clr, basestring):

correct:

elif isinstance(colour, basestring):