Previous Up Next

KPlug Glade Tutorial

Glade FAQS

I've tried to answer a few common questions here. I'll add more if I think of them, or people ask me them. Please refer to the official Glade FAQ, available from the Glade Homepage for more information. Also refer to the help pages listed on the page after this one in this tutorial.

 
 
 
Where do I get Glade?
You can download Glade from the Glade webpage at http://glade.gnome.org. It also is available as an rpm. Try rpmfind.net. It comes with several distributions of Linux as well.
 
How do I start Glade?
Type glade on the command line. Or click on the glade selection from the main menu of Gnome. In RedHat distros it's under mainmenu->programs->development.
 
Where do I find example code written with Glade?
The glade tarball comes with an example editor. It's simple, but illustrates the main points of linking signal handlers to code in callbacks. Of course there is the example used in this tutorial as well. You can get the code here. Finally, many many applications for Gnome are built with glade. See the glade homepage for a list of some of them. Most of them are open source, check out their code.
 
I need to add a signal handler. How?
Select the widget to which you want to add the handler. In the Glade Properties window, go to the 'signal' tab. Next to the signal field is a button labeled '...'. Click the button, and select the signal you want to handle. Hit ok. Glade will make a default handler name for you, these are quite descriptive and useful, so just hit the 'Add' button at the bottom of the window. It'll add the signal handler to callbacks.c the next time you save the project and build your code.
 
I added a handler to callbacks.c by hand and it doesn't work! Why?

Could be several reasons for this. You forgot the function prototype in callbacks.h. You forgot to set up a callback and handler in the Properties window of Glade. Many of the widgets, when they are created in interface.c refer to the handler names. In other words, you can't add by hand, the widget won't have been created to recognize it, because there is no reference to the function in the create_widgetname function in interface.c.

Sometimes you will have to add a function to callbacks.c that wasn't created by Glade. I did this in the example for the option menu. In that case, make it a static function, don't prototype it in callbacks.h and you should be fine.

 
What's all this other stuff under the Signals Tab, in the Properties Window?
Those are areas where you can enter code directly. Only do this for short bits of code (like on a delete_event for the main window). I have to admit I don't personally use this, but I tend to do things the hard way.
 
How do I break up a big project?
Use the project options to break a big project up into smaller ones. For instance, the main part of your project would build the interface.c, support.c, main.c, callbacks.c files, and all the support files. The subseqent, dependent, parts would have renamed files (ie interface1.c, callbacks1.c). You probably won't need the support.c and main.c files for these parts, unless you intend to test them separately before combining them into the final product. Remember you will have to add entries for your dependent part files in Makefile.am.
 
What are all these different GTK_XXX and GNOME_XXX macros for?
Gtk+ and hence Gnome widgets are all based on classes (like in C+, but this isn't C plus. See C can do C+! :)). The classes are hierarchical, but all are basically the 'same' in that a GTK_EDITABLE is also a GTK_WIDGET. You use the macros to access different aspects of the widget. For instance, when refering to a text box, upon creation, it's a GTK_WIDGET. But when you want to stick text into it, it's a GTK_EDITABLE. Yes, it's confusing. If you have trouble with your code, this is one place to look for the culprit.
 
The help file says the function is deprecated, what now?
Don't use it. Or use it and expect you'll have to change it some day. Some of the functions in Gtk+ 1.2 are deprecated. This is because they will eventually be phased out. Your code won't run when that happens. So try and use the substitutes they suggest.
 
What about Gnome 2.0 and Gtk+ 2.0?
Yea, I'm looking forward to porting all my code over to these too. Actually, Gnome 2.0 looks pretty exciting to me, so it won't be that bad. Basically some of the widgets are deprecated in 2.0. When Gnome 2.0 and Gtk+ 2.0 come out and are standard, you'll probably want to port your code. I'm sure Glade will have a 2.0 port as well, although I'm certainly not in the know about that. Ask the wonderful creator and coder of Glade :).

Previous Up Next