Cannot override GetSelectedTextColour() for HtmlListBox -- virtual functions not implemented?

I’m new to wxPython, and am building an app for deployment on both Mac OS X and Windows. I have got most of it all working, but am having a problem with the Mac OS X build.

I have an HtmlListBox with a custom background colour, which is working fine across platforms. However, whilst on Windows the text colour goes white when an item is selected (so the text is still readable), on OS X the text stays black and is thus difficult to read.

The Phoenix documentations for HtmlListBox (http://wxpython.org/Phoenix/docs/html/html.HtmlListBox.html) suggests thatI should be able to override GetSelectedTextColour() in order to correct this issue. However, whatever I try I cannot make this work and a dir(wx.HtmlListBox) suggests that that function is never there for HtmlListBox.

I had a dig about in the wxPython source. I noticed that in ‘wxPython/src/_vscroll.i’ that there is a comment at the top of the file:

// Base classes. I don’t expect that these will ever be used directly from
// Python, (especially being derived from) so I own’t worry about making their
// virutals overridable. They’re just defined here for their public methods.

Then further down (line 907 for me) in the same file I find a ‘TODO’ block about the GetSelectedTextColour() function, with a commented out line:

// virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;

Unfortunately, I’m not much of a C programmer, and have never previously heard of SWIG so I have been unable to manage to build and patch swig 1.3.29 and get the --reswig flag for the build script working. It has been an intensely frustrating few hours, as I’d like to know whether the fix is as simple as uncommenting that line!

Questions:

  1. Is GetSelectedTextColour() meant to be implemented? If so - am I doing something wrong when I just try adding it to my sub-class of HtmlListBox?

  2. If I did work out SWIG - is commenting out that line really all there is to it?

Asides:

  1. Should OS X not be changing the text colour by default anyway? In native widgets the text does invert (to white) for the same background colour.

  2. I tried using HTML tags to alter the text colour on select, but it always just goes to black whatever (unselected cells I can colour as I want).

  3. I can/have hacked around this problem by just patching the white text directly into the wxPython source as I’ll be packaging the app with py2app on OS X so can include my patched version with it. I just didn’t want to give up on getting the correct solution!

Many thanks in advance!

Tom Anthony wrote:

I'm new to wxPython, and am building an app for deployment on both Mac
OS X and Windows. I have got most of it all working, but am having a
problem with the Mac OS X build.

I have an HtmlListBox with a custom background colour, which is working
fine across platforms. However, whilst on Windows the text colour goes
white when an item is selected (so the text is still readable), on OS X
the text stays black and is thus difficult to read.

The Phoenix documentations for HtmlListBox
(http://wxpython.org/Phoenix/docs/html/html.HtmlListBox.html) suggests
thatI should be able to override GetSelectedTextColour() in order to
correct this issue. However, whatever I try I cannot make this work and
a dir(wx.HtmlListBox) suggests that that function is never there for
HtmlListBox.

I had a dig about in the wxPython source. I noticed that in
'wxPython/src/_vscroll.i' that there is a comment at the top of the file:

    // Base classes. I don't expect that these will ever be used
    directly from
    // Python, (especially being derived from) so I own't worry about
    making their
    // virutals overridable. They're just defined here for their public
    methods.

Then further down (line 907 for me) in the same file I find a 'TODO'
block about the GetSelectedTextColour() function, with a commented out line:

    // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;

Unfortunately, I'm not much of a C programmer, and have never previously
heard of SWIG so I have been unable to manage to build and patch swig
1.3.29 and get the --reswig flag for the build script working. It has
been an intensely frustrating few hours, as I'd like to know whether the
fix is as simple as uncommenting that line!

Questions:

1) Is GetSelectedTextColour() meant to be implemented? If so - am I
doing something wrong when I just try adding it to my sub-class of
HtmlListBox?
2) If I did work out SWIG - is commenting out that line really all there
is to it?

Yes, it should probably be overridable. No, there would be lots more to do for it. In order to make virtual C++ methods overridable in Python for wxPython Classic there are some hoops that need to be jumped though in the wrapper code to make it work. It's possible, but not simple. The fact that the C++ method is protected instead of public adds some flames to the hoops because the wrapper code doesn't have direct access to it in the wx class.

In Phoenix it is automatic in most common cases, so it is easy to support overriding C++ virtuals.

Asides:

1) Should OS X not be changing the text colour by default anyway? In
native widgets the text does invert (to white) for the same background
colour.

Perhaps, but it may just be defaulting to the stock system color for selections and it happens to clash with your selection background color in this case.

···

--
Robin Dunn
Software Craftsman