Overflow error in CustomTreeCtrl

Hi Andrea and others,

One of my (Task Coach) users reported the following traceback:

Traceback (most recent call last):
File “taskcoach.pyw”, line 4, in
File "taskcoach.pyo
", line 79, in start
File “taskcoach.pyo”, line 31, in init
File “taskcoach.pyo”, line 60, in init
File “gui\mainwindow.pyo”, line 55, in init
File “gui\mainwindow.pyo”, line 67, in createWindowComponents

File “gui\mainwindow.pyo”, line 104, in createFilterSideBar
File “gui\filter.pyo”, line 128, in init
File “gui\filter.pyo”, line 146, in createInterior
File “widgets\treectrl.pyo”, line 461, in init

File “widgets\treectrl.pyo”, line 427, in init
File “widgets\itemctrl.pyo”, line 45, in init
File “widgets\itemctrl.pyo”, line 91, in init
File “wx\lib\customtreectrl.pyo”, line 1794, in init

File “wx_gdi.pyo”, line 114, in init
OverflowError: in method ‘new_Colour’, expected argument 3 of type ‘byte’

Line 1794 is the init of CustomTreeCtrl. The relevant lines are these, the last line is 1794:

btnshadow = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW)
self._hilightUnfocusedBrush = wx.Brush(btnshadow)
r, g, b = btnshadow.Red(), btnshadow.Green(), btnshadow.Blue()
backcolour = ((r >> 1) - 20, (g >> 1) - 20, (b >> 1) - 20)

backcolour = wx.Colour(backcolour[0], backcolour[1], backcolour[2])

Apparently the (b>>1) -20 gets too big for the button shows colour on my user’s platform (Windows, don’t know what version, let me know if it matters).

I’ve opened a bug report at SF: http://sourceforge.net/tracker/index.php?func=detail&aid=1645080&group_id=9863&atid=109863

Cheers, Frank

Hi Frank,

One of my (Task Coach) users reported the following traceback:

Traceback (most recent call last):
  File "taskcoach.pyw", line 4, in <module>
  File "taskcoach.pyo ", line 79, in start
  File "taskcoach.pyo", line 31, in __init__
  File "taskcoach.pyo", line 60, in init
  File "gui\mainwindow.pyo", line 55, in __init__
  File "gui\mainwindow.pyo", line 67, in createWindowComponents
  File "gui\mainwindow.pyo", line 104, in createFilterSideBar
  File "gui\filter.pyo", line 128, in __init__
  File "gui\filter.pyo", line 146, in createInterior
  File "widgets\treectrl.pyo", line 461, in __init__
  File "widgets\treectrl.pyo", line 427, in __init__
  File "widgets\itemctrl.pyo", line 45, in __init__
  File "widgets\itemctrl.pyo", line 91, in __init__
  File "wx\lib\customtreectrl.pyo", line 1794, in __init__
  File "wx\_gdi.pyo", line 114, in __init__
OverflowError: in method 'new_Colour', expected argument 3 of type 'byte'

Line 1794 is the __init__ of CustomTreeCtrl. The relevant lines are these,
the last line is 1794:

btnshadow = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW)
self._hilightUnfocusedBrush = wx.Brush(btnshadow)
r, g, b = btnshadow.Red(), btnshadow.Green(), btnshadow.Blue()
backcolour = ((r >> 1) - 20, (g >> 1) - 20, (b >> 1) - 20)
backcolour = wx.Colour(backcolour[0], backcolour[1], backcolour[2])

Apparently the (b>>1) -20 gets too big for the button shows colour on my
user's platform (Windows, don't know what version, let me know if it
matters).

No, it's a misleading error: it's not too big, it's less than zero:

bluelist =
for b in xrange(0, 256):

... bluelist.append((b>>1)-20)
...

max(bluelist)

107

min(bluelist)

-20

colour = wx.Colour(200, 200, -20)

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python25\Lib\site-packages\wx-2.8-msw-ansi\wx\_gdi.py",
line 114, in __init__
    _gdi_.Colour_swiginit(self,_gdi_.new_Colour(*args, **kwargs))
OverflowError: in method 'new_Colour', expected argument 3 of type 'byte'

It's of course Windows, which other platform could ever generate this
kind of problems? Let me guess, does your user have a custom theme on
Windows? It seems like in this theme, the Blue() component of
wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW) is less than 40
(so b >> 1 -20 is less than 0). The only workaround I can see is to
check for the colour component value before creating the colour:

if r < 0: r = 0
if g < 0: g = 0
if b < 0: b = 0

(!!!)

Andrea.

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

It’s of course Windows, which other platform could ever generate this
kind of problems? Let me guess, does your user have a custom theme on
Windows?

I don’t know for sure, but I think so because this is the first time this issue has been reported.

It seems like in this theme, the Blue() component of
wx.SystemSettings_GetColour
(wx.SYS_COLOUR_BTNSHADOW) is less than 40
(so b >> 1 -20 is less than 0). The only workaround I can see is to
check for the colour component value before creating the colour:

if r < 0: r = 0
if g < 0: g = 0

if b < 0: b = 0

Yeah, or use max((b >>1) -20, 0).

Do you want me to provide a patch?

Cheers, Frank

···

2007/1/26, Andrea Gavana andrea.gavana@gmail.com:

Hi Frank,

> It's of course Windows, which other platform could ever generate this
> kind of problems? Let me guess, does your user have a custom theme on
> Windows?

I don't know for sure, but I think so because this is the first time this
issue has been reported.

> It seems like in this theme, the Blue() component of
> wx.SystemSettings_GetColour (wx.SYS_COLOUR_BTNSHADOW) is less than 40
> (so b >> 1 -20 is less than 0). The only workaround I can see is to
> check for the colour component value before creating the colour:
>
> if r < 0: r = 0
> if g < 0: g = 0
> if b < 0: b = 0

Yeah, or use max((b >>1) -20, 0).

Do you want me to provide a patch?

Yes please, if you can: I cannot access CVS from work, so I cannot
create patches. I believe Robin will incorporate it in the next
wxPython release.

Thank you.

Andrea.

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

···

On 1/26/07, Frank Niessink <frank@niessink.com> wrote:

2007/1/26, Andrea Gavana <andrea.gavana@gmail.com>:

The patch is here: http://sourceforge.net/tracker/index.php?func=detail&aid=1645253&group_id=9863&atid=309863

I wasn’t sure what diff options are preferred so I simply used: cvs diff > diff.txt

Hope that that’s ok.

Cheers, Frank

···

2007/1/26, Andrea Gavana andrea.gavana@gmail.com:

Do you want me to provide a patch?

Yes please, if you can: I cannot access CVS from work, so I cannot
create patches. I believe Robin will incorporate it in the next
wxPython release.

Frank Niessink wrote:

2007/1/26, Andrea Gavana <andrea.gavana@gmail.com <mailto:andrea.gavana@gmail.com>>:

     > Do you want me to provide a patch?

    Yes please, if you can: I cannot access CVS from work, so I cannot
    create patches. I believe Robin will incorporate it in the next
    wxPython release.

The patch is here: http://sourceforge.net/tracker/index.php?func=detail&aid=1645253&group_id=9863&atid=309863

I wasn't sure what diff options are preferred so I simply used: cvs diff <filename> > diff.txt

Hope that that's ok.

The unified diff format is preferred, but this one is simple enough that it doesn't matter. Thanks!

···

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