GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Questions about aligment of the widgets

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
Joel



Joined: 06 Apr 2008
Posts: 3

PostPosted: Sun Apr 06, 2008 7:02 pm    Post subject: Questions about aligment of the widgets Reply with quote

Hi all: I'm almost a virgin to gtk. And I made my first GUI, here's the code:
Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

#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:

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
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 376
Location: State College, Pennsylvania

PostPosted: Sun Apr 06, 2008 8:40 pm    Post subject: Reply with quote

(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 www.gtkbook.com if you are interested.[/url]
Back to top
RamDas
Familiar Face


Joined: 07 Apr 2008
Posts: 7

PostPosted: Mon Apr 07, 2008 8:43 pm    Post subject: Book Reply with quote

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
Back to top
Joel



Joined: 06 Apr 2008
Posts: 3

PostPosted: Mon Apr 07, 2008 10:02 pm    Post subject: Reply with quote

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.
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 376
Location: State College, Pennsylvania

PostPosted: Mon Apr 07, 2008 10:22 pm    Post subject: Reply with quote

RamDas: The book does not cover GtkAlignment. I was referring to fixed and box packing.
Back to top
RamDas
Familiar Face


Joined: 07 Apr 2008
Posts: 7

PostPosted: Tue Apr 08, 2008 6:11 pm    Post subject: Reply with quote

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: (C)
1
2
     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/stable/glib-Key-value-file-parser.html#g-key-file-set-string

Please help

Ram Das
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 376
Location: State College, Pennsylvania

PostPosted: Tue Apr 08, 2008 9:02 pm    Post subject: Reply with quote

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.)
Back to top
RamDas
Familiar Face


Joined: 07 Apr 2008
Posts: 7

PostPosted: Tue Apr 08, 2008 9:55 pm    Post subject: Reply with quote

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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP