Re: EuGTK - GtkListStore - color?

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...

We can simplify the list view greatly with the use of a small include file. Here's a simple list program, following it is the include:

include GtkEngine.e 
include ListView.e as List 
 
include machine.e 
 
enum NAME, AGE, PET 
object names = { 
{"Jerry S. Smith",21,"Rover"}, 
{"Jonnie B. Goode",44,"Fluffy"}, 
{"Susan Black",33,"none"}, 
{"Fred Flintstone",55,"Dino"}, 
{"George Burns",112,"cigar"} 
} 
 
constant win = create(GtkWindow) 
	connect(win,"destroy",quit) 
 
constant panel = create(GtkVBox) 
	add(win,panel) 
 
constant tv  = List:View({"#","Name","Age","Pet name"}) -- {column headings} 
	add(panel,tv) 
 
object store = List:Store(gINT,gSTR,gINT,gSTR) -- (column data types) 
	set(tv,"model",store) 
 
for i = 1 to length(names) do -- load the list store with data 
	List:Row(store,i & names[i]) 
end for 
	 
show_all(win) 
main() 
 

Code below handles the dirty work:

 
-- listview.e 
 
include GtkEngine.e 
 
object renderer = create(GtkCellRendererText)  
object iter = allocate(32) 
 
export function Column(atom tv, sequence title, integer datacolumn) 
	set(tv,"insert column with attributes",-1,title,renderer,"text",datacolumn) 
return 1 
end function 
 
export function View(object cols) 
atom tv = create(GtkTreeView) 
for i = 1 to length(cols) do 
	Column(tv,cols[i],i-1) 
end for 
return tv 
end function 
 
export function Store(atom p1=0, atom p2=0, atom p3=0, atom p4=0, atom p5=0, atom p6=0, atom p7=0, atom p8=0) 
atom store = create(GtkListStore,p1,p2,p3,p4,p5,p6,p7,p8) 
return store 
end function 
 
export function Row(atom store, object data) 
	set(store,"insert",iter,99999) 
	for i = 1 to length(data) do 
		set(store,"set",iter,i-1,data[i],-1) 
	end for 
return 1 
end function 
 

The above works fine as long as there is only one list in operation - too bad we don't have some object-oriented abilities, so we could "include ListView.e as ..." more than one instance. As you may remember, some years ago, this accidentally worked, but was soon removed.

In my current translation project I need 5 lists. Does this mean that I should have 5 instances of ListView.e?

include ListView1 as List1 
include ListView2 as List2 
include ListView3 as List3 
include ListView4 as List4 
include ListView5 as List5 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu