OwnerDrawn wxListBox

lipid@68k.org wrote:

I've been wanting to have colored text in a list box for a while now, and
I recently noticed the ownerDrawn sample in wxWindows does just that. So
I added the functionality by modifying the wxPython source, adding this in
controls.i in the %addmethods section of wxListBox:

---

[...]

---

And it works! Though I understand this method only works on Windows. And
you must add wxLB_OWNERDRAW to the listbox's style flags.

My questions:

1. Is there some way to do this already without modifying the wxPython
source?

Not with wxListBox because the wxOwnerDrawn base class is not exposed to Python. But, as mentioned in another post, it's not too hard to make a wxListCtrl look like a wxListBox.

2. If not, might a future version allow it?

It's possible, although I would probably do it like this instead:

         void SetItemForegroundColour(int item, const wxColour& c) {
             %#ifdef __WXMSW__
                  if (self->GetWindowStyle() & wxLB_OWNERDRAW)
                      self->GetItem(item)->SetTextColour(c);
             %#endif
         }
         void SetItemBackgroundColour(int item, const wxColour& c) {
             %#ifdef __WXMSW__
                  if (self->GetWindowStyle() & wxLB_OWNERDRAW)
                      self->GetItem(item)->SetBackgroundColour(c);
             %#endif
         }

ยทยทยท

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