Re: EuGTK - GtkListStore - color?

new topic     » goto parent     » topic index » view thread      » older message » newer message

To color an entire row, the following works. I had to edit one line in GtkRoutines.e to accomodate it, but it seems like this is the accepted way to do it.

First, edit GtkRoutines.e - line 2353 or so, to read:

     {"insert_column_with_attributes",{P,I,S,P,S,I,S,I,S,I,S,I},I}, 

Then the following will color each line with whatever color is specified with that name.

include GtkEngine.e 
include std/machine.e 
include std/console.e 
 
constant names = { 
{"Jerry S. Smith","green"}, 
{"Jonnie B. Good","yellow"}, 
{"Jason Jones","blue"}, 
{"Susan Black","black"}, 
{"Fred Flintstone","brown"} 
} 
enum COLOR=2 
 
object selection 
 
function Foo(object view) 
	Info(0,"Info","You selected",get(view,"text",1)) 
return 1 
end function 
constant foo = call_back(routine_id("Foo")) 
 
constant win = create(GtkWindow) 
	connect(win,"destroy",quit) 
	set(win,"title","Test 33 - List View") 
	set(win,"position",GTK_WIN_POS_CENTER) 
	set(win,"border width",10) 
	set(win,"default size",400,400) 
 
constant panel = create(GtkVBox) 
	add(win,panel) 
 
constant tv  = create(GtkTreeView) 
	set(tv,"reorderable",TRUE) 
	add(panel,tv) 
 
constant lbl = create(GtkLabel) 
set(lbl,"markup","<span size='small'>Double click on a row to retrieve info\nDrag items to re-order!</span>") 
pack(panel,-lbl) 
 
object renderer1 = create(GtkCellRendererText) 
 
enum NUM=0,NAME,SCORE,COLOUR 
object store = create(GtkListStore,gINT,gSTR,gINT,gSTR) 
	set(tv,"model",store) 
	set(tv,"insert column with attributes",-1,"#",renderer1,"text",NUM,"background",COLOUR) 
	set(tv,"insert column with attributes",-1,"Name",renderer1,"text",NAME) 
	set(tv,"insert column with attributes",-1,"Score",renderer1,"text",SCORE) 
	set(tv,"insert column with attributes",-1,"Color",renderer1,"text",COLOUR) 
	 
object iter = allocate(32) 
	set(tv,"model",store) 
 
for i = 1 to length(names) do 
	set(store,"append",iter) 
	set(store,"set",iter,NUM,i,-1) 
	set(store,"set",iter,NAME,allocate_string(names[i][NAME]),-1) 
	set(store,"set",iter,SCORE,rand(100),-1) 
	set(store,"set",iter,COLOUR,allocate_string(names[i][COLOR]),-1) 
end for 
 
connect(tv,"row-activated",foo) 
 
show_all(win) 
main() 

PS: If you don't want to see the color names displayed on your list, just comment out the line:

	--set(tv,"insert column with attributes",-1,"Color",renderer1,"text",COLOUR) 

PPS: If you want different colors - or no colors - for some columns - IOW, the whole row isn't one color, you need to set up additional renderers for those columns. You can have a separate renderer for each column if you wish.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu