Re: EuGTK: notebook control stuff

new topic     » goto parent     » topic index » view thread      » older message » newer message
include GtkEngine.e 
 
constant win = create(GtkWindow) 
connect(win,"destroy","Quit") 
set(win,"border width",10) 
set(win,"background","darkgray") 
set(win,"icon from file","~/demos/thumbnails/mongoose.png") 
 
constant panel = create(GtkBox,1) 
add(win,panel) 
 
constant notebook = create(GtkNotebook) 
set(notebook,"size request",200,200) 
set(notebook,"background","cornsilk") 
add(panel,notebook) 
 
-- Build custom notebook tabs; 
-- tabs have to respond to two different signals: 
-- 1 - click on tab to change current notebook page, 
-- 2 - click on tab's stop icon to remove the page 
 
constant stop = create(GdkPixbuf,"~/demos/thumbnails/icon-stop.png",15,15) 
 
object pg = repeat(0,5), tab = pg, lbl = pg, img = pg, btn = pg 
object pgtxt 
 
for i = 1 to length(pg) do 
 
	pg[i] = create(GtkBox,1) -- container for page content; 
	pgtxt = create(GtkLabel) -- some content to prove we have changed pages 
	set(pgtxt,"font","Purisa, URW Chancery L 18") 
	set(pgtxt,"markup",sprintf("This text is on page %d",i)) 
	add(pg[i],pgtxt) 
	 
	tab[i] = create(GtkBox,0) -- container for tab content; 
	lbl[i] = create(GtkLabel,sprintf("Page %d",i)) -- tab label 
	img[i] = create(GtkImage,stop) -- image for this tab 
	btn[i] = create(GtkToolButton,,"DeletePage",pg[i]) -- send handle of pg to remove funk 
	--(see note 1) 
	set(btn[i],"tooltip text",sprintf("Click to remove tab %d",i)) 
	set(lbl[i],"tooltip text","Click to change to this page") 
	set(btn[i],"icon widget",img[i]) -- sets tab icon 
	add(tab[i],{lbl[i],btn[i]}) -- adds text and icon to the tab 
	show_all(tab[i]) -- contents are not automatically shown  
	 
	set(notebook,"append page",pg[i],tab[i]) 
	 
end for 
 
show_all(win) 
main() 
 
global function DeletePage(atom tb, object pg) 
-- tb is the toolbutton clicked,  
-- pg is the page which has this tb on its tab; 
--(see note 2) 
-- To delete a page, 
-- we have to get the CURRENT page number assigned to pg, 
-- since it changes as pages are removed (or added, reordered, etc) 
pg = get(notebook,"page num",pg) -- current # 
set(notebook,"remove page",pg) -- get rid of it 
return 1 
end function 
 
--(1) if you want to use this to edit files, and need to save files before 
-- closing the page or whatever, you can attach the filename to the  
-- 'stop' toolbutton: 
/* 

set(btn[i],"data","filename",file[i])  
*/  
--(2) and then retrieve the filename before the page is deleted; 
/* 

file = get(tb,"data","filename") 
*/ 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu