Re: About Glade



Hi,

Albert Mora wrote:
I've read several times about the convenience of using Glade to design a
GNOME app's GUI, but I also read about not using the generated code.

I neither found an explanation of this behaviour

I can think of the following reasons (there may be others also) why
using generated code is discouraged.
- With the generated code, if you want to change the UI design you need
to change the entire file which has the generated code. But If you load
the widgets on the fly from glade file, using gladeXML, you only need to
change the portion of the code which is affected by the UI change.
- Your program code and interface code is combined, which may not be a
good way. With gladeXML, you can seperate the inteface code from program
code.

not the proper solution
(I read something about using an XML file, but I don't know how to do),
specially using C++, which is the languaje I like most -so I'd use.

You can do the following:

a) Generate the .glade file by using Glade application builder.
b) load the GUI from the .glade file from the program code as shown
below, through an example:

#include <glade/glade-xml.h>
......
......
// Get a reference to the interface from glade file.
 
       gui = glade_xml_new (GMEDIA_PROP_GLADEDIR "gmedia_prop.glade2",
                            "Gmedia_Prop", NULL);
        if (!gui) {
               g_warning ("Could not find gmedia_prop.glade2, reinstall
gmedia_format.\n");
               return;
        }

// Get reference to parent window from glade file..

     window = glade_xml_get_widget (gui, "Gmedia_Prop");
     /*  Show the window and other widgets */ 
     gtk_widget_show_all(window);

// say the UI just has help and close buttons. Now get a reference to
them and attach a callback..

      helpButton = glade_xml_get_widget (gui, "helpButton");
      g_signal_connect (G_OBJECT (helpButton), "clicked", G_CALLBACK
(help_cb), window);
      closeButton = glade_xml_get_widget (gui, "closeButton");
      g_signal_connect (G_OBJECT (closeButton), "clicked", G_CALLBACK
(close_cb), NULL);

Note that, code for building the entire UI is not present here. Instead,
we are just loading the UI on the fly from glade file, and adding
functionality like adding callbacks.

You can refer to gedit (gedit/dialogs directory) code for such examples.

HTH,
Narayana



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]