ListItem SetBackgroundColour

51 views
Skip to first unread message

Raphael Mayoraz

unread,
Dec 15, 2009, 2:27:55 PM12/15/09
to wxpytho...@googlegroups.com
Hello,

I'd like to override SetBackgroundColour() for a listItem object in
order to draw the background colour on a given rectangle and not for the
entire item background like it does now. Is that doable, and if yes, how ?

I was thinking of just creating a DC and display it, but I cannot figure
how to have it appear on top of the list.

(Yes, I know, this could be done with no code writing in
UltimateListCtrl, but that class has some limitations I'd like to avoid).

Thanks.

Raphael

Andrea Gavana

unread,
Dec 15, 2009, 2:49:20 PM12/15/09
to wxpytho...@googlegroups.com
Hi,

2009/12/15 Raphael Mayoraz:
> Hello,
>
> I'd like to override SetBackgroundColour() for a listItem object in
> order to draw the background colour on a given rectangle and not for the
> entire item background like it does now. Is that doable, and if yes, how ?

As I have already told you, you can *not* draw a wx.ListCtrl sub-item
differently from the other sub-items. wx.ListCtrl assigns a background
colour (and other properties) for the whole row, not on a sub-item
base, and the behaviour can not be changed as the class is a wrapped
wxWidgets one.

> (Yes, I know, this could be done with no code writing in
> UltimateListCtrl, but that class has some limitations I'd like to avoid).

Care to elaborate? Which kind of limitations? As far as I know,
UltimateListCtrl and wx.ListCtrl behave the same way.

Andrea.

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

Raphael Mayoraz

unread,
Dec 15, 2009, 3:14:32 PM12/15/09
to wxpytho...@googlegroups.com
Yes, I will elaborate, but just got some emergencies on my table :-(
, so ... later.

Thanks.

Raphael

Raphael Mayoraz

unread,
Dec 15, 2009, 4:53:00 PM12/15/09
to wxpytho...@googlegroups.com
Andrea,

(This may be of some interest for people who are frequently asking about
wx.ListCtrl, ObjectListView, UltimateListCtrl)

Now, elaborating, and sorry if this is a bit long.

First, I'm by far not an expert, and probably quickly hits walls that
experienced users would not.

Now, I need to display a list that can have a few thousands rows and a
few tens columns. The data are from a list of dictionaries, where each
dictionary is a row (an "item"), and each key in the dictionary is a
column (a "sub-item"). Columns display would be customisable, but there
would be no column dragging (for now at least). Very important: each
cell (?sub-item") could be edited (and NOT just the item "Label"), and
the editor type would be defined by column. Also important, I'd like to
play with cell background colour, add icons in cells left or right
aligned, but with no fixed, width, possibly also play with text format
(bold, colour). The editors I forsee are: text ctrl, checkbox,
combobox, any kind of dialog (like color dialog). Sorting on some
columns would be cool too, as well as basic search features.

I know, wx.Grid is a solution, but I wanted to avoid all the work around
custom renderer and custom editors, also there are several things
described above that would need to be coded.

I tried ObjectListView which is really great, and does *almost*
everything I need in a very slick way. Especially, the populating of the
list is great, as well as the setup of columns and cell editors. The
"FastObjectListView" is doing its impressive "fast" job. Appreciated too
the built in "sort", the search ctrl that's comes with the demo etc. But
it has two limitations: fixed size of images (and not right alignement),
no "per sub-item" background color and text color/font. And I understand
this is because it is derived from wx.ListCtrl.

So, I tried UltimateListCtrl, very impressive, but got a few problems
doing what I want: here are the most important:
- The sub-item editing is limited to the first "Label" column. I wrote
my own class to have the ExpandoTextCtrl come on double click for each
cell. Had to figure out what is the UltimateListCtrl object vs. the
UltimateListMainWindow object and how the methods are calling each
other, but after some sweat, that works ok now.
- I got pretty frustrated with the item._* attributes. I could retrive
the text info (or background colour) of a sub-item, but not the data
(._data) or pyData. Seems like we can give a text value per sub-item,
but no data, this can go to the first sub-item in the row only. I'm
probably missing something here, but in general, I found that ULC is
still close to wx.ListCtrl in that it is based mostly on what's in the
"Label" column. I really need something where the first column is
nothing different than the other columns.
- Tried to add a combobox in each cell of a column. Easy to be shown,
but with 1000 items, I would create 1000 comboBox objects with 1000
associated event handlers ... Exactly what I'd like to avoid. So,
started to created a custom renderer, and a custom editor ... well,
that's like using wx.Grid, isn't it.
In conclusion, I still think the class is great, but may be not
appropriate to my needs.

So, I think I guess I need to just into wx.Grid, or forget about
background colors and text color in cells. Too bad, because all those
3rd party classes are really great, and just missing a small bit.

Anyway thanks for all the work.

Raphael

Andrea Gavana

unread,
Dec 15, 2009, 5:05:25 PM12/15/09
to wxpytho...@googlegroups.com
Hi,

2009/12/15 Raphael Mayoraz <may...@netplus.ch>:
> So, I tried UltimateListCtrl, very impressive, but got a few problems
> doing what I want: here are the most important:
> - The sub-item editing is limited to the first "Label" column. I wrote
> my own class to have the ExpandoTextCtrl come on double click for each
> cell. Had to figure out what is the UltimateListCtrl object vs. the
> UltimateListMainWindow object and how the methods are calling each
> other, but after some sweat, that works ok now.

As I told you some time ago, you could have simply borrowed the code
in wx.lib.mixins.listctrl (and specifically the TextEditMixin class)
and change the wx.TextCtrl into an ExpandoTextCtrl.

> - I got pretty frustrated with the item._* attributes. I could retrive
> the text info (or background colour) of a sub-item, but not the data
> (._data) or pyData. Seems like we can give a text value per sub-item,
> but no data, this can go to the first sub-item in the row only. I'm
> probably missing something here, but in general, I found that ULC is
> still close to wx.ListCtrl in that it is based mostly on what's in the
> "Label" column. I really need something where the first column is
> nothing different than the other columns.

If you take a look at how sub-items handle their own background/text
colours and fonts, it would not be complicated to add a feature to
have data and pyData per sub-item. Plus, you could contribute it back
to the community as a patch :-D

> - Tried to add a combobox in each cell of a column. Easy to be shown,
> but with 1000 items, I would create 1000 comboBox objects with 1000
> associated event handlers ... Exactly what I'd like to avoid. So,
> started to created a custom renderer, and a custom editor ... well,
> that's like using wx.Grid, isn't it.

It is, this is why custom renderers and custom editors exist both for
wxGrid and ULC (and other complex classes). There is no way to avoid
it, unless there were already in the source code some classes to
handle custom renderers and editors for the most common widgets
(textctrl, combobox, datepicker and so on). This would be another
useful addition to ULC, and also worth another patch :-D

Raphael Mayoraz

unread,
Dec 15, 2009, 5:28:04 PM12/15/09
to wxpytho...@googlegroups.com
Hmmm, just about the TextEditMixin class, it did that, but than EVERY
cell has that
text editor. The way I'd like to do it is:
OnDoubleClick(self, event):
... get row and column of the "clicked" cell
... get sub-item data, in which I would store the information about
the editor to be used
if subItem._pyData[0] == 'textCtrl':
... start my text control editor
if subItem._pyData[0] == 'comboBox':
... start my comboBox editor, using pyData[1] as the list to be
used in the comboBox.

etc.

Or something similar (but not more complex)

I'll give some thought if I want to continue digging in the ULC or just
give up.

If I have some code that I feel can be valuable to the community, I'll
share it.

Thanks.

Raphael
Reply all
Reply to author
Forward
0 new messages