Gnome Programming: Getting Started with Anjuta/Glade
April 20, 2005
Note: This tutorial is no longer current. A new, more up-to-date and in-depth tutorial has been written: Tutorial: Simple Gnome Application Using libglade and C/GTK+
Introduction
Hello, and welcome to my first Gnome application. That's right, this was my first Gnome application. Keep that in mind. I'm not an expert on GTK+ or Gnome development whatsoever. I will do my best to keep this updated with corrections and provide the best information I can. You can learn to program for Gnome right along with me as I learn. It's worth pointing out that although I don't have much experience with GTK and Linux programming, I am an experienced programmer and understand basic C, object oriented programming, data structures, and other concepts that are (I'm assuming) going to be critical. Also, you may want to become more familiar with straight GTK+ programming before moving into Gnome specific programming. There is a tutorial on the GTK website. Personally, I worked through the first 'Hello World' GTK program and am now moving on to Gnome specific GTK programming. As I figure things out I'll pass the information on to you. Part of my reasons for writing this tutorial are due to the lack of up-to-date information on getting over that initial hump in learning to use Anjuta and Glade to develop Gnome applications. I'm not teaching you GTK, nor am I teaching you the C programming language. I'm showing you how I got started using Anjuta and Glad. I will be using the C language (although not much just yet!). This tutorial will go over the creation of a Gnome application called "Hello World" which looks something like:
You'll notice that it's a real, Gnome looking application. It doesn't do much, but it look cool! When we click the 'File' -> 'New' menu item, another dialog box will be show that looks like:

Sources of Information
I did a bit of reading and browsing the internet before embarking on this new task of learning to develop gnome applications. Here are some of the resources that influenced this tutorial:- Anjuta Tutorial - This tutorial is from Anjuta, however, it seems a little bit out of date. However, this was the basic guidline I followed.
- GTK+ Mailing List - This is the GTK+ mailing list in which I ask questions. We're going to be good friends.
- Tutorials by Ishan Chattopadhyaya - He has written several tutorials on GTK+/Glade programming.
- Below are 2 books I have and have been using as a reference. Both are a bit out-dated, so if you have some book reccomendations, please, by all means, post them in comments at the bottom of this page. I just got these 2 books mainly due to how cheap they are and knowing that they would still teach me the fundamentals of GTK and Gnome programming.
| This is a book by Havoc Pennington who plays a significant role in the development of gnome. I've been sort of casually reading through it to get an idea of what I'm up against. This book is from 1999 though, so you could imagine how many changes have occured since then. But, it gives me a good background on Gnome applications programming if nothing else. I find it quite valuable. | |
| Yet another book from 1999 and therefore highly likely to be a bit outdated, however, I've been using this as a reference for basic GTK+ programming concepts. |
The Tools - Anjuta and Glade
In order to go through this tutorial and begin developing Gnome applications, you should make sure you have the following installed for your distribution:- Glade - Glade Interface Designer is an application that allows you to easily create the GUI for your application. It then generates the GTK+ code for that interface. It also interfaces quite nicely with Anjuta. I'm using Glade 2.6.0 installed from RPM for my Fedora Core 3 installation. If you don't already have it installed and use RPMs (it comes with many distros), you can probably obtain the RPM using YUM or apt-get.
- Anjuta - Integrated Developement Environment (IDE). I'm using version 1.2.2 which I believe came from the Fedora Core 1 RPM downloaded from teh Anjuta website.
For me, this was resolved by installing the gettext-devel RPM by issuing the command:
yum install gettext-devel
Creating a New Project in Anjuta
According to the Anjuta tutorial, the sequences that the new project wizard takes you through are very important. However, we're just sort of playing around here so we can afford to make mistakes. That's how we learn. So open up Anjuta (it should be under 'Programming' in your Gnome applications menu). Select 'New Project' from the 'File' menu to begin the New Project wizard. Fill in each screen similar to these screenshots:Building the Interface with Glade
Now we should be in Anjuta. We will now create our basic GUI. You can either select 'Edit Application GUI' from the 'Project' file menu in Anjuta or press ALT+G to launch Glade. The main window of Glade looks like the one below. Take note of the 'window1' that's currently listed. That's going to become significant later in this tutorial. But for now, click to highlight 'window1' and press the delete key to delete window1.
In the 'Pallette' window, click the 'Gnome' button and then the Gnome Application Window button which is the upper left icon. With the newly created 'app1' window open, you can modify it's properties in the 'Properties' window. Change the 'Title:' attribute to "Hello World!" as shown below.
![]() |
![]() |
|
Editing the Code in Anjuta
Back in anjuta, click the callbacks.c file in the project explorer of Anjuta (left pane). We're going to add a call to gtk_main_quit() in the function named on_quit1_activate to terminate the program when a user selects 'Quit' from our program's 'File' menu.:void on_quit1_activate (GtkMenuItem *menuitem, gpointer user_data) { gtk_main_quit(); }And then one more, just for fun, still in the callbacks.c file, edit the function on_new1_activate as follows:
void on_new1_activate (GtkMenuItem *menuitem, gpointer user_data) { GtkWidget *msgbox = gnome_app_new("Hello World", "Hello World"); gnome_app_message (GNOME_APP(msgbox), "Hello World. You chose New!"); }Those 2 lines will generate a little message box when the user chooses 'New' from our program's 'File' menu. Now, you'd think we're ready to build and test our project-- but there's one little problem. I left this problem in on purpose as It's a good learning experience. Remember when we opened up Glade and deleted 'window1' and replaced it with our Gnome Application Window called 'app2'? Well, take a look at the file main.c and look around line 36 for:
window1 = create_window1 (); gtk_widget_show (window1);You see the problem? We no longer have a create_window1() function. It became create_app1() function (I found it in interface.c). However, it seems that once main.c is created, Glade will not modify it. Therefore, it didn't change this call. So we could either go back into Glade and rename our Gnome Application Window to 'window1', or, what I did was change that line as follows:
window1 = create_app1 (); gtk_widget_show (window1);Now we are ready to build our project. Select 'Build' from the 'Build' menu. Hopefull you don't get any errors. And now, press F3 or choose 'Execute' from the 'Build' Menu to view our little application in action. Cool eh?
From Here...
From here we move on to Gnome Programming Tutorial 2 - Using LibGlade with Anjuta/Glade in which we'll create another new Gnome application, only this time we'll be using Glade with the libglade library to build the interface at runtime.
Categories:
GTK+ Programming
Copyright © 2004 - 2010 Micah Carrick. All Rights Reserved.









11 Comments about "Gnome Programming: Getting Started with Anjuta/Glade"
RSS Feed
I can launch Glade3, but not from Anjuta. I tried to import a glade file from anjuta, but then I do not have the palette window.
Your tutorial looks great, I would like to be able to go further.
Best,
Alex
so, any solutions?
otherwise, I want to translate this tutorial to Chinese too, though my English is not good. Hope you can give me the permission.
My E-mail:go3go4@gmail.com, waiting for your E-mail, and thank you primarily.
Leave a Comment about "Gnome Programming: Getting Started with Anjuta/Glade"