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 

Attaching a glade file into another glade file.

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
abxccd
Familiar Face


Joined: 06 Mar 2010
Posts: 39

PostPosted: Sun Mar 14, 2010 4:51 am    Post subject: Attaching a glade file into another glade file. Reply with quote

Hi everyone,

I am currently developing a GTK app using C. My interfaces are designed using Glade and then loaded via a GTK builder.

I would like to design more "screens" using Glade, but without a main window. What I would like to do is then to attach those glade files into a vbox in the main window at run time.

Does anyone know how to do this?

Cheers :)
Back to top
tadeboro
Never Seen the Sunlight


Joined: 23 Jul 2008
Posts: 2114
Location: Slovenia

PostPosted: Sun Mar 14, 2010 10:10 am    Post subject: Reply with quote

Hello.

If you're using Glade >= 3.6, you can simply right-click a widget that you wish to have as toplevel in your UI file and select "Add widget as toplevel". This way you can create parts of your GUI that are later added into proper container.

In order to place loaded parts into "master" UI, you'll have to obtain parts via gtk_builder_get_object() and then manually pack them into master using normal methods (gtk_box_pack_*(), gtk_container_add(), ...).

Tadej
Back to top
abxccd
Familiar Face


Joined: 06 Mar 2010
Posts: 39

PostPosted: Sun Mar 14, 2010 11:19 am    Post subject: Reply with quote

Thank you for your reply tadeboro. Your introduction to using Glade was very helpful btw :)

I have tried your suggestion, but is currently facing this error:

Code: (C)
1
(myapp:2333): Gtk-CRITICAL **: gtk_box_pack: assertion `GTK_IS_WIDGET (child)' failed


Basically, what I am attempting to do is that when a button is clicked it will load an external glade file without a window as its top level, then attach it.

Previously, I have loaded the main window using gtk_builder, and showed the window. The builder is then unreferenced.

The code for my call back for the button is as follows:
Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

void cb_button( GtkWidget *widget, gpointer data ){
    GtkBuilder *builder;

    GError* error = NULL;
    GtkWidget *extvbox;

    builder = gtk_builder_new ();
    if (!gtk_builder_add_from_file (builder, ABOUT_UI, &error)){
        g_warning ("Couldn't load builder file: %s", error->message);
        g_error_free (error);
       
    }


    extvbox = GTK_WIDGET (gtk_builder_get_object (builder, "myvbox"));  <----CODE SEEMS TO FAIL STARTING HERE
   
printf ("%s", gtk_widget_get_name(aboutvbox)); <----RETURNS (null)

}


It quite strange that the builder I just loaded is unable to find the requested widget.

Do you know how to fix this?

Cheers :)
Back to top
abxccd
Familiar Face


Joined: 06 Mar 2010
Posts: 39

PostPosted: Mon Mar 15, 2010 5:39 am    Post subject: Reply with quote

Looks like the path to my gui was the wrong one. All fixed now :)
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