GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Sep 01, 2014 6:36 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: GTK C programming - building a screen
PostPosted: Tue Feb 14, 2012 1:38 am 
Offline
Familiar Face

Joined: Mon May 05, 2008 3:38 am
Posts: 12
I'm having a problem building a screen the way I want. I want 2 title lines followed by another line with 3 buttons. I will be adding more buttons later in another vbox underneath all of this.

The code snippet for generating the screen follows:

Code:
     gtk_init (&argc, &argv);

     opening_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     gtk_widget_set_size_request (opening_window, 640,480);
     gtk_window_set_position (GTK_WINDOW(opening_window), GTK_WIN_POS_CENTER);
     g_signal_connect (G_OBJECT (opening_window), "delete_event",
                       G_CALLBACK (do_exit), NULL);
     g_signal_connect (G_OBJECT (opening_window), "destroy",
                       G_CALLBACK (do_exit), NULL);
     gtk_container_set_border_width (GTK_CONTAINER(opening_window), 20);

     vbox0 = gtk_vbox_new(FALSE,0);
     gtk_widget_set_size_request(vbox0,638,478);
     gtk_container_add (GTK_CONTAINER (opening_window), vbox0);
     gtk_widget_show(vbox0);


     vbox1 = gtk_vbox_new(FALSE,0);
     gtk_widget_set_size_request(vbox1,600,100);
     gtk_container_add (GTK_CONTAINER (vbox0), vbox1);
     gtk_widget_show(vbox1);


     label1 = gtk_label_new("THE GNOME SHELL gnome-shell.css EDITOR");
     gtk_widget_set_size_request(label1,600,25);
     gtk_container_add (GTK_CONTAINER (vbox1), label1);
     gtk_widget_show(label1);


     label2 = gtk_label_new("Selections");
     gtk_widget_set_size_request(label2,600,25);
     gtk_container_add (GTK_CONTAINER (vbox1), label2);
     gtk_widget_show(label2);


     hbox1 = gtk_hbox_new(FALSE,0);
     gtk_container_add (GTK_CONTAINER (vbox1), hbox1);
     gtk_widget_set_size_request(hbox1,600,25);
     gtk_widget_show(hbox1);


     open_existing = gtk_button_new_with_label ("Open Existing CSS File");
     gtk_widget_set_size_request(open_existing,24,25);
     gtk_box_pack_start(GTK_BOX (hbox1),
                   open_existing,
                   FALSE,
                   FALSE,
                   2);
g_signal_connect (G_OBJECT (open_existing), "pressed",
                  G_CALLBACK (get_color), NULL);
     gtk_widget_show(open_existing);

     new_file = gtk_button_new_with_label ("New CSS File From Template");
     gtk_widget_set_size_request(new_file,30,25);
     gtk_box_pack_start(GTK_BOX (hbox1),
                   new_file,
                   FALSE,
                   FALSE,
                   2);
g_signal_connect (G_OBJECT (new_file), "pressed",
                  G_CALLBACK (get_color), NULL);
     gtk_widget_show(new_file);


     save_file = gtk_button_new_with_label ("Save CSS File");
     gtk_widget_set_size_request(save_file,16,25);
     gtk_box_pack_start(GTK_BOX (hbox1),
                   save_file,
                   FALSE,
                   FALSE,
                   2);
g_signal_connect (G_OBJECT (save_file), "pressed",
                  G_CALLBACK (get_color), NULL);
     gtk_widget_show(save_file);

     vbox2 = gtk_vbox_new(FALSE,0);
     gtk_widget_set_size_request(vbox1,600,250);
     gtk_container_add (GTK_CONTAINER (vbox0), vbox2);
     gtk_widget_show(vbox2);

/*
     filemenu = gtk_menu_item_new_with_label ("File");
     filemenu_menu = gtk_menu_new();
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(filemenu), filemenu_menu);
     gtk_menu_shell_append(GTK_MENU_SHELL(menubar), filemenu);
     gtk_widget_show(filemenu);
     gtk_widget_show(filemenu_menu);


     filenew = gtk_menu_item_new_with_label ("New");
     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu_menu), filenew);
     gtk_widget_show(filenew);
     g_signal_connect(G_OBJECT (filenew), "activate", NULL)
;


     fileopen = gtk_menu_item_new_with_label ("Open");
     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu_menu), fileopen);
     gtk_widget_show(fileopen);
     g_signal_connect(G_OBJECT (fileopen), "activate", NULL);


     filesave = gtk_menu_item_new_with_label ("Save");
     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu_menu), filesave);
     gtk_widget_show(filesave);
     g_signal_connect(G_OBJECT (filesave), "activate", NULL);


     filequit = gtk_menu_item_new_with_label ("Quit");
     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu_menu), filequit);
     gtk_widget_show(filequit);
     g_signal_connect(G_OBJECT (filequit), "activate", NULL);



     whatmenu = gtk_menu_item_new_with_label ("Select Area To Modify");
     whatmenu_menu = gtk_menu_new();
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(whatmenu), whatmenu_menu);
     gtk_menu_shell_append(GTK_MENU_SHELL(menubar), whatmenu);
     gtk_widget_show(whatmenu);
     gtk_widget_show(whatmenu_menu);
     gtk_widget_show(menubar);



     whatmenu_1 = gtk_menu_item_new_with_label ("Panel Options");
     gtk_menu_shell_append(GTK_MENU_SHELL(whatmenu_menu), whatmenu_1);
     gtk_widget_show(whatmenu_1);
     g_signal_connect(G_OBJECT (whatmenu_1), "activate", G_CALLBACK (panel_options), NULL);


button1 = gtk_button_new_with_label ("test color selection");
gtk_box_pack_start(GTK_BOX (vbox1),
                   button1,
                   FALSE,
                   FALSE,
                   2);
gtk_widget_set_size_request(button1,50,15);
g_signal_connect (G_OBJECT (button1), "pressed",
                  G_CALLBACK (get_color), NULL);
gtk_widget_show(button1);

button2 = gtk_button_new_with_label ("test font selection");
gtk_container_add (GTK_CONTAINER (vbox1), button2);
g_signal_connect (G_OBJECT (button1), "pressed",
                  G_CALLBACK (get_font), NULL);
gtk_widget_show(button2);
*/




/*
   Start the processing
*/

    gtk_widget_show_all (opening_window);

    gtk_main ();
   
    return 0;
}
[img]     gtk_init (&argc, &argv);

     opening_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     gtk_widget_set_size_request (opening_window, 640,480);
     gtk_window_set_position (GTK_WINDOW(opening_window), GTK_WIN_POS_CENTER);
     g_signal_connect (G_OBJECT (opening_window), "delete_event",
                       G_CALLBACK (do_exit), NULL);
     g_signal_connect (G_OBJECT (opening_window), "destroy",
                       G_CALLBACK (do_exit), NULL);
     gtk_container_set_border_width (GTK_CONTAINER(opening_window), 20);

     vbox0 = gtk_vbox_new(FALSE,0);
     gtk_widget_set_size_request(vbox0,638,478);
     gtk_container_add (GTK_CONTAINER (opening_window), vbox0);
     gtk_widget_show(vbox0);


     vbox1 = gtk_vbox_new(FALSE,0);
     gtk_widget_set_size_request(vbox1,600,100);
     gtk_container_add (GTK_CONTAINER (vbox0), vbox1);
     gtk_widget_show(vbox1);


     label1 = gtk_label_new("THE GNOME SHELL gnome-shell.css EDITOR");
     gtk_widget_set_size_request(label1,600,25);
     gtk_container_add (GTK_CONTAINER (vbox1), label1);
     gtk_widget_show(label1);


     label2 = gtk_label_new("Selections");
     gtk_widget_set_size_request(label2,600,25);
     gtk_container_add (GTK_CONTAINER (vbox1), label2);
     gtk_widget_show(label2);


     hbox1 = gtk_hbox_new(FALSE,0);
     gtk_container_add (GTK_CONTAINER (vbox1), hbox1);
     gtk_widget_set_size_request(hbox1,600,25);
     gtk_widget_show(hbox1);


     open_existing = gtk_button_new_with_label ("Open Existing CSS File");
     gtk_widget_set_size_request(open_existing,24,25);
     gtk_box_pack_start(GTK_BOX (hbox1),
                   open_existing,
                   FALSE,
                   FALSE,
                   2);
g_signal_connect (G_OBJECT (open_existing), "pressed",
                  G_CALLBACK (get_color), NULL);
     gtk_widget_show(open_existing);

     new_file = gtk_button_new_with_label ("New CSS File From Template");
     gtk_widget_set_size_request(new_file,30,25);
     gtk_box_pack_start(GTK_BOX (hbox1),
                   new_file,
                   FALSE,
                   FALSE,
                   2);
g_signal_connect (G_OBJECT (new_file), "pressed",
                  G_CALLBACK (get_color), NULL);
     gtk_widget_show(new_file);


     save_file = gtk_button_new_with_label ("Save CSS File");
     gtk_widget_set_size_request(save_file,16,25);
     gtk_box_pack_start(GTK_BOX (hbox1),
                   save_file,
                   FALSE,
                   FALSE,
                   2);
g_signal_connect (G_OBJECT (save_file), "pressed",
                  G_CALLBACK (get_color), NULL);
     gtk_widget_show(save_file);

     vbox2 = gtk_vbox_new(FALSE,0);
     gtk_widget_set_size_request(vbox1,600,250);
     gtk_container_add (GTK_CONTAINER (vbox0), vbox2);
     gtk_widget_show(vbox2);

/*
     filemenu = gtk_menu_item_new_with_label ("File");
     filemenu_menu = gtk_menu_new();
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(filemenu), filemenu_menu);
     gtk_menu_shell_append(GTK_MENU_SHELL(menubar), filemenu);
     gtk_widget_show(filemenu);
     gtk_widget_show(filemenu_menu);


     filenew = gtk_menu_item_new_with_label ("New");
     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu_menu), filenew);
     gtk_widget_show(filenew);
     g_signal_connect(G_OBJECT (filenew), "activate", NULL)
;


     fileopen = gtk_menu_item_new_with_label ("Open");
     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu_menu), fileopen);
     gtk_widget_show(fileopen);
     g_signal_connect(G_OBJECT (fileopen), "activate", NULL);


     filesave = gtk_menu_item_new_with_label ("Save");
     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu_menu), filesave);
     gtk_widget_show(filesave);
     g_signal_connect(G_OBJECT (filesave), "activate", NULL);


     filequit = gtk_menu_item_new_with_label ("Quit");
     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu_menu), filequit);
     gtk_widget_show(filequit);
     g_signal_connect(G_OBJECT (filequit), "activate", NULL);



     whatmenu = gtk_menu_item_new_with_label ("Select Area To Modify");
     whatmenu_menu = gtk_menu_new();
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(whatmenu), whatmenu_menu);
     gtk_menu_shell_append(GTK_MENU_SHELL(menubar), whatmenu);
     gtk_widget_show(whatmenu);
     gtk_widget_show(whatmenu_menu);
     gtk_widget_show(menubar);



     whatmenu_1 = gtk_menu_item_new_with_label ("Panel Options");
     gtk_menu_shell_append(GTK_MENU_SHELL(whatmenu_menu), whatmenu_1);
     gtk_widget_show(whatmenu_1);
     g_signal_connect(G_OBJECT (whatmenu_1), "activate", G_CALLBACK (panel_options), NULL);


button1 = gtk_button_new_with_label ("test color selection");
gtk_box_pack_start(GTK_BOX (vbox1),
                   button1,
                   FALSE,
                   FALSE,
                   2);
gtk_widget_set_size_request(button1,50,15);
g_signal_connect (G_OBJECT (button1), "pressed",
                  G_CALLBACK (get_color), NULL);
gtk_widget_show(button1);

button2 = gtk_button_new_with_label ("test font selection");
gtk_container_add (GTK_CONTAINER (vbox1), button2);
g_signal_connect (G_OBJECT (button1), "pressed",
                  G_CALLBACK (get_font), NULL);
gtk_widget_show(button2);
*/




/*
   Start the processing
*/

    gtk_widget_show_all (opening_window);

    gtk_main ();
   
    return 0;
}
]


EDIT: Figured out how to attach the screen shot of the screen that is generated.

EDIT-EDIT: I take it back - I can't attach the screen shot either as jpg, gif or png - says the file name is invalid. What are the valid image types?

I would appreciate any input at all on this!

Thanks in advance!
Dave ;)


Top
 Profile  
 
 Post subject: Re: GTK C programming - building a screen
PostPosted: Tue Feb 14, 2012 9:20 am 
Offline
Familiar Face

Joined: Mon May 05, 2008 3:38 am
Posts: 12
It would appear that in place of gtk_container_add I needed to pack the box instead. That appears to have worked.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot] 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