colored BListView/BListItem/BStringItem

Forum thread started by TmTFx on Sat, 2011-05-28 09:58

I'm trying to write a simple news feed reader in python.
I implemented a listview for the newspapers and a listview for the news of the selected newspaper
Now i'm trying to make the news listview colored but i'm find hard to do it.
I found some sample code that maybe can help here:

http://haiku-os.org/legacy-docs/bebook/BListItem_Overview.html

but it's in C++
and i'm not sure how to implement it in python

is there some easy way to make a BStringItem colored? or can someone help me translate that class to python?

Comments

Re: colored BListView/BListItem/BStringItem

Making a colored BStringItem isn't very difficult. The big thing is to subclass it and implement DrawItem(). You *might* be able to even get away with something like this:

ColoredStringItem::DrawItem(BView *owner, BRect frame, bool complete)
{
    owner->SetLowColor(128,128,255);
    owner->SetHighColor(0,0,0);
    BStringItem::DrawItem(owner, frame, false);
}

This may or may not work, depending on the BStringItem implementation. Worst case you could grab a copy of BListItem.cpp from the source tree to look at how they did it.

Re: colored BListView/BListItem/BStringItem

Thank you! :)

I created this BListItem Class:

class NewsItem(BListItem):
	nocolor = (0, 0, 0, 0)
	def __init__(self, name,color):
		self.name = name
		self.color=color
		BListItem.__init__(self)
	def DrawItem(self, owner, frame, complete):
		if complete:
			owner.SetHighColor(self.nocolor)
			owner.FillRect(frame)
		owner.SetHighColor(self.color)
		owner.MovePenTo(frame[0],frame[3])
		owner.DrawString(self.name)
 
	def Text(self):
		return self.name

but now i have a little problem, when i select in the listview those colored items, they aren't coloured as a normal selection(gray background), they have still the same background color (white) so i can't understand what i have selected