1. EuGTK: notebook control stuff

Hi all,

I have been playing with Irv Mullin's EuGtk library - great contribution Irv! thanks a lot! - but I have some trouble to get the following code to work the way I want to. I have to say that "I don't get it" when it comes to fix the size or position of controls, I guess its done with the "grid" layout but is there any other easier way to do this?something like set(button, width, 20)?? I' ve been navigating with property browser to check aviable methods, etc but I dont seem to find the solution.

Ok, now the question about the notebook control.

I want to create several tabs within a notebook control, eachone conteining an editable text widget for editing different files. I want to maximize the size of the window and the size of the notebook contianer but I dont succeed to achive this.

thanks & regards, Raul Campos

the code (from test42.ex):

include GtkEngine.e 
 
constant win = create(GtkWindow) 
	connect(win,"destroy","Quit") 
	set(win,"position",GTK_WIN_POS_CENTER) 
	set(win,"border width",10) 
	set(win,"default size",400,300) 
    set(win,"icon from file","~/demos/thumbnails/mongoose.png") 
     
constant panel = create(GtkBox,1) 
	add(win,panel) 
 
constant lbl1 = create(GtkLabel) 
	set(lbl1,"markup","<b><u>GtkNotebook</u></b>") 
	set(lbl1,"override font","8") 
	add(panel,lbl1) 
 
constant sep = create(GtkSeparator) 
	add(panel,sep) 
 
constant notebook = create(GtkNotebook) 
	add(panel,notebook) 
 
constant pg1 = create(GtkBox,1) 
	set(notebook,"append page",pg1) 
	add(pg1,create(GtkImage,"~/demos/images/jeff.jpg")) 
 
constant tab2 = create(GtkLabel) 
	set(tab2,"markup","<i><b>LGPL</b></i>") 
 
constant pg2 = create(GtkBox,1) 
	set(notebook,"append page",pg2,tab2) --(3) 
 
constant lbl2 = create(GtkLabel,wrap(LGPL,60)) 
	set(lbl2,"override font","8") 
	set(lbl2,"margin top",10) 
	add(pg2,lbl2) 
 
constant tabpix = create(GtkImage,"~/demos/thumbnails/bar.gif") 
 
 
--------------------------------------- My stuff -------------------- 
 
constant scroller = create(GtkScrolledWindow) 
 
constant tv = create(GtkTextView) 
	set(tv,"wrap mode",GTK_WRAP_WORD_CHAR)	 
	set(tv,"font","Courier 12") 
	add(scroller, tv) 
 
constant buffer = get(tv,"buffer")  
	set(buffer,"text",LGPL) 
 
 
--- 
--- this code runs but gives the following error message: 
--- (test42.ex:1608): Gtk-WARNING **: Attempting to add a widget with type GtkTextView to a container 
--- of type GtkBox, but the widget is already inside a container of type GtkScrolledWindow, please 
--- use gtk_widget_reparent() 
--- 
--- 
--- Note: this has been actually solved 
--- 
 
------------------------------------------------------------- 
 
 
constant pg3 = create(GtkBox,1) 
	set(notebook,"append page",pg3,tabpix) --(4) 
	pack(pg3,scroller,TRUE,TRUE) 
 
add(pg3,tv) 
 
constant btnbox = create(GtkButtonBox) 
	add(btnbox,create(GtkButton,"gtk-quit","Quit")) 
	add(btnbox,create(GtkButton,"gtk-ok","Foo")) 
	pack(pg3,-btnbox) 
 
show_all(win) 
main() 
 
global function Foo() 
Info(win,"OK","Thanks!") 
return 1 
end function 

[added eucode tags -matt]

new topic     » topic index » view message » categorize

2. Re: EuGTK: notebook control stuff

thanks Matt for cleaning up my post. I didn't noticed about the eucode tag, nice feature. smile

new topic     » goto parent     » topic index » view message » categorize

3. Re: EuGTK: notebook control stuff

To answer the first question re: setting the size and position of controls:

Basically, you don't.

Size of controls is best left up to the window manager, since different users have differing needs and preferences. Similar to the way the appearance is left up to the user to adjust, using themes, etc. You normally have the option to tell GTK to either expand the control to take up all available space, or to not expand. See packing in the GTK docs.

Position, similarly, doesn't often use set locations. Instead, GTK uses a packing scheme, where controls are packed into one or more containers. There are just a few kinds of containers, the one you will use most is the GtkBox. When creating a box, you can choose either vertical: <create(GtkBox,1)> or horizontal: <create(GtkBox,0)>

From there, any controls you add to or pack into the box are simply placed below (or to the right) of the previous control.

For fancier layouts, you can either add containers to a parent container to arrange things the way you want, or you can use a grid, where things can be attached 'next to' other things. Look at test34.ex.

Positioning things in a fixed x,y manner is frowned upon.

Now, for the other:

To make the notebook fill the window, change add(panel,notebook) to pack(panel,notebook,TRUE,TRUE) the 2 trues mean EXPAND and FILL

To make the window automatically fill the available screen space on startup, add a line: set(win,"maximize",TRUE).

BTW, I just uploaded a new version to https://sites.google.com/site/euphoriagtk/ which has several bug fixes. Version 4.6.02 has been tested on both 32 and 64 bit machines, with several different Linux distros.

new topic     » goto parent     » topic index » view message » categorize

4. Re: EuGTK: notebook control stuff

thank you very much Irv!

I'll download and test it right now. smile

new topic     » goto parent     » topic index » view message » categorize

5. Re: EuGTK: notebook control stuff

Hi,

please, can someone tell me how do I add to a tab in a notebook the X icon to allow closing the tab?

thanks!

new topic     » goto parent     » topic index » view message » categorize

6. Re: EuGTK: notebook control stuff

Raul said...

Hi,

please, can someone tell me how do I add to a tab in a notebook the X icon to allow closing the tab?

thanks!

I'm not sure what you want to do here. Normally, you don't 'close' a tab, you just open a different page by clicking on some tab other than the current one. There's always one page visible. You can have a button or a link on a notebook page which will change to another page when clicked. I suppose you could use a ToolButton with an X image in it instead of the "Click me" caption if you wanted something smaller than a regular button.

add(pg3,create(GtkButton,"_Click me","go_to_pg",1)) 
 
global function go_to_pg(atom ctl, integer pg) 
return set(notebook,"current page",pg-1) 
end function 

Maybe you're thinking of something like a multi-file editor, where you can close one of the files using its tab. You can remove a page if you don't need it any more:

set(notebook,"remove page",n) -- where n is the page number 

To do this with the name of the file PLUS an icon, you'll probably need to make your own custom button to attach to the tab. I'll try to work up a demo of that, maybe tomorrow.

new topic     » goto parent     » topic index » view message » categorize

7. Re: EuGTK: notebook control stuff

Thanks Irv. Yes, that's exactlly what I'm planning, a multi-file editor and I want to add to the file-tabs an icon to close the opened file at any moment.

new topic     » goto parent     » topic index » view message » categorize

8. Re: EuGTK: notebook control stuff

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 message » categorize

9. Re: EuGTK: notebook control stuff

Thanks for the demo Irv, it will help me a lot.

regards

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu