[wxPython] ListItems

Hi,

I was hoping someone could help me with changing the color of a single item in
the ListCtrl. The docs talk about modifying a ListItem, but I haven't been
able to successfully get it to work. Any one have any sample code?

-Mike

I think that is not posible, at least on win9x, because a native widget is
used.
If you need a visual efects in a row, maybe you could use a diferent icon
or you could use the new wxGrid instead, wxGrid may be configured
cell by cell if you need.

Cristian

···

----- Original Message -----
From: Mike G Miller <Mike.G.Miller@disney.com>
To: <wxpython-users@wxwindows.org>
Sent: Monday, August 07, 2000 9:13 PM
Subject: [wxPython] ListItems

Hi,

I was hoping someone could help me with changing the color of a single

item in

the ListCtrl. The docs talk about modifying a ListItem, but I haven't

been

able to successfully get it to work. Any one have any sample code?

-Mike

_______________________________________________
wxPython-users mailing list wxPython-users@wxwindows.org
http://wxwindows.org/mailman/listinfo/wxpython-users

Hi Mike,

Mike G Miller wrote:

Hi,

I was hoping someone could help me with changing the color of a single item in
the ListCtrl. The docs talk about modifying a ListItem, but I haven't been
able to successfully get it to work. Any one have any sample code?

-Mike

This works for me on wxMSW (NT, don't know about 95) and wxGTK.

Given listCtrl and you want to colour the idx'th item:

    item = listCtrl.GetItem(idx)
    item.SetBackgroundColour(wxColour(123, 123, 213))
    listCtrl.SetItem(item)

···

--
Riaan >>> a='a=%s;a%%`a`';a%`a`
___________________________________________________
Boa Constructor - RAD GUI building IDE for wxPython
     http://boa-constructor.sourceforge.net

I was hoping someone could help me with changing the color of a single

item in

the ListCtrl. The docs talk about modifying a ListItem, but I haven't

been

able to successfully get it to work. Any one have any sample code?

        item = self.list.GetItem(itemID)
        item.SetTextColour(wxBLUE)
        self.list.SetItem(item)

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!

In article <010f01c00100$e85e0f00$0b01a8c0@ARES>, Robin Dunn
<robin@alldunn.com> writes

I was hoping someone could help me with changing the color of a single

item in

the ListCtrl. The docs talk about modifying a ListItem, but I haven't

been

able to successfully get it to work. Any one have any sample code?

       item = self.list.GetItem(itemID)
       item.SetTextColour(wxBLUE)
       self.list.SetItem(item)

--

funny I see no change at all after I changed the wxListCtrl.py demo so
the setup loop looked like

        for x in range(len(items)):
            key, data = items
            self.list.InsertImageStringItem(x, data[0], idx1)
            self.list.SetStringItem(x, 1, data[1])
            self.list.SetStringItem(x, 2, data[2])
            self.list.SetItemData(x, key)
            if data[0]=='Billy Joel':
                i = self.list.GetItem(x,0)
                i.SetTextColour(wxBLUE)
                i = self.list.GetItem(x,1)
                i.SetTextColour(wxRED)
                i = self.list.GetItem(x,2)
                i.SetBackgroundColour(wxBLUE)
            elif data[0]=='bad English':
                i = self.list.GetItem(x)
                i.SetTextColour(wxBLUE)

···

--
Robin Becker

Robin Becker wrote:

In article <010f01c00100$e85e0f00$0b01a8c0@ARES>, Robin Dunn
<robin@alldunn.com> writes
>>
>> I was hoping someone could help me with changing the color of a single
>item in
>> the ListCtrl. The docs talk about modifying a ListItem, but I haven't
>been
>> able to successfully get it to work. Any one have any sample code?
>>
>
> item = self.list.GetItem(itemID)
> item.SetTextColour(wxBLUE)
> self.list.SetItem(item)
>
>--
funny I see no change at all after I changed the wxListCtrl.py demo so
the setup loop looked like

        for x in range(len(items)):
            key, data = items
            self.list.InsertImageStringItem(x, data[0], idx1)
            self.list.SetStringItem(x, 1, data[1])
            self.list.SetStringItem(x, 2, data[2])
            self.list.SetItemData(x, key)
            if data[0]=='Billy Joel':
                i = self.list.GetItem(x,0)
                i.SetTextColour(wxBLUE)

You have to update the wxListCtrl after modyfying the wxListItem, add:

                  self.list.SetItem(i)

···

                i = self.list.GetItem(x,1)
                i.SetTextColour(wxRED)
                i = self.list.GetItem(x,2)
                i.SetBackgroundColour(wxBLUE)
            elif data[0]=='bad English':
                i = self.list.GetItem(x)
                i.SetTextColour(wxBLUE)

--
Robin Becker

_______________________________________________
wxPython-users mailing list wxPython-users@wxwindows.org
http://wxwindows.org/mailman/listinfo/wxpython-users

--
Riaan >>> a='a=%s;a%%`a`';a%`a`
___________________________________________________
Boa Constructor - RAD GUI building IDE for wxPython
     http://boa-constructor.sourceforge.net

writes
...
OK I did this
        for x in range(len(items)):
            key, data = items[x]
            self.list.InsertImageStringItem(x, data[0], idx1)
            self.list.SetStringItem(x, 1, data[1])
            self.list.SetStringItem(x, 2, data[2])
            self.list.SetItemData(x, key)
            if data[0]=='Billy Joel':
                i = self.list.GetItem(x,0)
                i.SetTextColour(wxBLUE)
                self.list.SetItem(i)
                i = self.list.GetItem(x,1)
                i.SetTextColour(wxRED)
                self.list.SetItem(i)
                i = self.list.GetItem(x,2)
                i.SetBackgroundColour(wxBLUE)
                self.list.SetItem(i)
            elif data[0]=='Bad English':
                i = self.list.GetItem(x,1)
                i.SetBackgroundColour(wxRED)
                i.SetTextColour(wxBLUE)
                self.list.SetItem(i)

but Billy Joel comes out all columns white background blue text and Bad
English comes out all red bg and blue text. It seems that I don't have
control over the individual columns. A poor design to say the least.

···

In article <399047FF.BF368131@e.co.za>, Riaan Booysen <riaan@e.co.za>
--
Robin Becker

I want to set a specific column of a wxListCtrl to use a different font
and like Robin below have found that the .SetItem(ItemId) call affects all
columns, even though ItemId is unique to the column.

After reading the WxWindows help file, I have convinced myself that there
is a separate instance of wxListItem for each column item and printing the
values of the class members confirms this. The only thing I don't
understand is in the description of wxListCtrl::GetItem where it adds

"You must call info.SetId() to se ID of item you're interested in before
calling this method."

This obviously contains a typo so I can't follow what it is trying to say,
especially as I can't find any reference to a SetId() method anywhere.

Hopefully this a red-herring that doesn't affect the wxPython
implementation, but could an expert please confirm that what I am
attempting *ought* to work.

Regards,
David Hughes

···

In article <399047FF.BF368131@e.co.za>, Riaan Booysen <riaan@e.co.za>
writes
...
OK I did this
        for x in range(len(items)):
            key, data = items
            self.list.InsertImageStringItem(x, data[0], idx1)
            self.list.SetStringItem(x, 1, data[1])
            self.list.SetStringItem(x, 2, data[2])
            self.list.SetItemData(x, key)
            if data[0]=='Billy Joel':
                i = self.list.GetItem(x,0)
                i.SetTextColour(wxBLUE)
                self.list.SetItem(i)
                i = self.list.GetItem(x,1)
                i.SetTextColour(wxRED)
                self.list.SetItem(i)
                i = self.list.GetItem(x,2)
                i.SetBackgroundColour(wxBLUE)
                self.list.SetItem(i)
            elif data[0]=='Bad English':
                i = self.list.GetItem(x,1)
                i.SetBackgroundColour(wxRED)
                i.SetTextColour(wxBLUE)
                self.list.SetItem(i)

but Billy Joel comes out all columns white background blue text and Bad
English comes out all red bg and blue text. It seems that I don't have
control over the individual columns. A poor design to say the least.
--
Robin Becker

David Hughes wrote:

I want to set a specific column of a wxListCtrl to use a different font
and like Robin below have found that the .SetItem(ItemId) call affects all
columns, even though ItemId is unique to the column.

One colour / font per row.

After reading the WxWindows help file, I have convinced myself that there
is a separate instance of wxListItem for each column item and printing the
values of the class members confirms this. The only thing I don't
understand is in the description of wxListCtrl::GetItem where it adds

Yes, there is a separate wxListItem for each column.

"You must call info.SetId() to se ID of item you're interested in before
calling this method."

This is not applicable to wxPython as the GetItem method in wxPython
does
not take a wxListItem as a parameter, it takes the ID and optionally the
column number.

This obviously contains a typo so I can't follow what it is trying to say,
especially as I can't find any reference to a SetId() method anywhere.

wxListItem does have a method named SetId() (check the source,
wxListItem
is not documented)

···

--
Riaan >>> a='a=%s;a%%`a`';a%`a`
___________________________________________________
Boa Constructor - RAD GUI building IDE for wxPython
     http://boa-constructor.sourceforge.net

>
> I want to set a specific column of a wxListCtrl to use a different
> font and have found that the .SetItem(ItemId) call affects all
> columns, even though ItemId is unique to the column.

One colour / font per row.

.....

Riaan

That's a pity, I have got numeric columns that really must be in a
fixed-width font but the corresponding descriptive text looks much better
when it's proportionally spaced :frowning:

Thanks for the prompt reply.

David