Re: EuGTK - GtkListStore - color?

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

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.

Am I missing something obvious? Why wouldn't the following work (at least as a quick&dirty hack) ?

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 lv = List:CreateLV() 
 
constant tv  = List:View(lv, {"#","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(lv, store,i & names[i]) 
end for 
	 
show_all(win) 
main() 
 

Code below handles the dirty work:

 
-- listview.e 
 
include GtkEngine.e 
 
export function CreateLV() 
object renderer = create(GtkCellRendererText)  
object iter = allocate(32) 
return {renderer, iter} 
end function 
 
export function Column(sequence lv, atom tv, sequence title, integer datacolumn) 
	object renderer = lv[1] 
	set(tv,"insert column with attributes",-1,title,render,"text",datacolumn) 
return 1 
end function 
 
export function View(sequence lv, object cols) 
atom tv = create(GtkTreeView) 
for i = 1 to length(cols) do 
	Column(lv,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(sequence lv, atom store, object data) 
	object iter = lv[2] 
	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 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu