GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Jul 29, 2014 6:49 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Questions about aligment of the widgets
PostPosted: Sun Apr 06, 2008 7:02 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
Hi all: I'm almost a virgin to gtk. And I made my first GUI, here's the code:
Code:
#include <gtk/gtk.h>

GtkWidget *edit1;

void callback (GtkWidget *widget, gpointer data) {
   GtkWidget *dialog;
     
    dialog = gtk_file_chooser_dialog_new("Open File", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
     
    if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
         char *filename;
         filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
         gtk_entry_set_text(GTK_ENTRY(edit1), filename);
    }
     
    gtk_widget_destroy (dialog);
}

gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) {
    return (FALSE);
}

void destroy (GtkWidget *widget, gpointer data) {
    gtk_main_quit ();
}

int main(int argc, char* argv[]) {
   GtkWidget *window;
   GtkWidget *vbox1;
   GtkWidget *hbox1;
   GtkWidget *vbox2;
   GtkWidget *button1;
   GtkWidget *label1;
   GtkWidget *label2;
   GtkWidget *edit2;
   
   gtk_init (&argc, &argv);
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(window), "gMD5 v0.1 - TMNT");
   gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
   gtk_container_border_width(GTK_CONTAINER(window), 10);
   gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL);
    gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(destroy), NULL);
   
    vbox1 = gtk_vbox_new(FALSE, 5);
    hbox1 = gtk_hbox_new(FALSE, 5);
    vbox2 = gtk_vbox_new(TRUE, 5);
    gtk_container_add(GTK_CONTAINER(window), vbox1);
     
   label1 = gtk_label_new("Selecciona el archivo:");
   gtk_box_pack_start(GTK_BOX(vbox1), label1, FALSE, TRUE, 0);
   
   gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, FALSE, 0);
   
   edit1 = gtk_entry_new();
   gtk_box_pack_start(GTK_BOX(hbox1), edit1, FALSE, FALSE, 0);
      
   button1 = gtk_button_new_with_label("Buscar...");   
   gtk_signal_connect (GTK_OBJECT(button1), "clicked", GTK_SIGNAL_FUNC(callback), (gpointer)"boo para data");
   gtk_box_pack_start(GTK_BOX(hbox1), button1, FALSE, FALSE, 0);
   
   gtk_box_pack_start(GTK_BOX(vbox1), vbox2, FALSE, FALSE, 0);
   
   label2 = gtk_label_new("MD5 del fichero:");
   gtk_box_pack_start(GTK_BOX(vbox2), label2, FALSE, FALSE, 0);
   
   edit2 = gtk_entry_new();
   gtk_box_pack_start(GTK_BOX(vbox2), edit2, FALSE, FALSE, 0);
   
    gtk_widget_show_all(window);
    gtk_main ();
   return 0;
}

The result is this image:
Image
My questions is:
a) How can I align to the left the labels.
b) How can I align to the right the button so the first entry becomes more larger.
c) Is there a way to put widgets (labels, entries, buttons, etc) based on (X,Y) params instead of using hbox and vbox?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 06, 2008 8:40 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
(1) You must place each label into a GtkAlignment widget and then put that alignment into the GtkVBox. This will allow you to justify the widget to the left as long as you do not force it to take up 100% of the widget's space.

(2) In the gtk_box_pack_start() function, set the entry to expand (TRUE) and the button to not expand (FALSE). You should set both fill options to TRUE as well.

(3) You can use a GtkFixed widget, but you should _NOT_ use this widget. Proportional alignment allows GTK+ to properly adjust for other themes, fonts, sizes, languages, etc. If you use a GtkFixed, a button might look correct at font size 12, but overlap another widget at font size 14.

These topics are all covered in great detail in my book, Foundations of GTK+ Development, at http://www.gtkbook.com if you are interested.[/url]

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: Book
PostPosted: Mon Apr 07, 2008 8:43 pm 
Offline
Familiar Face

Joined: Mon Apr 07, 2008 8:33 pm
Posts: 11
Hi Andrew,

I have your Book "Foundations of GTK+ Development". Good Book. Could you please tell me which chapter or page number did you mentioned or example using " GtkAlignment ".

Thanks
Ram Das


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 10:02 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
Hi openldev, thanks for your post.

3) Yeah, I test it and is better with hbox and vbox, even is better with table grid.
2) Stil working, but I think that I understrand.
1) Yeah, agree with above, I was searching and there are not many examples about GtkAlignment, even gtk_set_alignement is very odd :s

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 10:22 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
RamDas: The book does not cover GtkAlignment. I was referring to fixed and box packing.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 6:11 pm 
Offline
Familiar Face

Joined: Mon Apr 07, 2008 8:33 pm
Posts: 11
Hi Andrew,

But still your book is really good. Thank you for sharing your knowledge through book. Because there is not many books in GTK+ that covering updated version of latest GTK+ Toolkit for beginners or medium level user.

Well, I have a question. I was trying to add following line in to the example of your " Using GLib's GKeyFile Parser " article in the " http://www.gtkbook.com/tutorial.php?page=keyfile "

Code:
     g_key_file_set_integer    (keyfile, "username","Int",100); 
     g_key_file_set_string    (keyfile, "network","IPADDRESS","172.16.1.201"); 


But I found no change in the "keyfile.conf". The file seem to be unchanged by above code. How to change or create Group_Name, Key and Value? I can't see anything in here either http://library.gnome.org/devel/glib/sta ... set-string

Please help

Ram Das


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 9:02 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
All that function does is edit the GKeyFile object. You have to convert the object to a string with g_key_file_to_data() and then save it to the file to see any changes. (Sorry that wasn't clear. I'll update the tutorial to explicitly state that.)

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 9:55 pm 
Offline
Familiar Face

Joined: Mon Apr 07, 2008 8:33 pm
Posts: 11
Thank you for your reply Andrew. I found a working example that will do to Create, Read and Modify a configuration file using "Key-value file parser"

Here is the link. Not only API but also contain an example.
http://cfergeau.free.fr/glib/glib-Key-value-file-parser.html

Look at the wrong link which I have visited earlier. I can see only API reference here ( May be old version of the document..?) But always an example make more sense than spending lot of time to figure it out how to do looking at the plain API.
http://library.gnome.org/devel/glib/stable/glib-Key-value-file-parser.html#g-key-file-set-string

Thanks
Ram Das


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group