| Previous | Up | Next |
You've built your application's interface, and it looks pretty with Glade. You've set a bunch of signal handlers to respond to user action in your application's interface. You've used Glade to build the code. You have a directory with several files in it and a src subdirectory. Now what?
Now it's time to start writing code. Most people, I think, find it easier to build with Glade and write code in the same process. It's extremely difficult to build an interface when you don't know exactly what your code will entail. This is another reason for writing the 'user's guide' before you even touch the code editor or Glade. If you are using something with a lot of structures, which will relate to data input from the interface, it almost becomes essential to have a guide, you'll refer to it when you want to remember what you originally wanted the code to do.
Glade uses the standard Gnu automake tools. When you first build your code with Glade, you will need to cd to the directory which contains the project and type ./autogen.sh. This will set up the Makefile.am and Makefiles needed, tailored for your system. You will not be able to compile code without doing this. If you get any major errors with the autogen system, well, you are on your own. This isn't an automake tutorial :).
Glade also uses the glib libraries. It's a good idea to use them in whatever files or code you add to your application, as they include several nifty improvements on standard C functions. For example, with g_free() you don't have to worry about freeing a NULL. It won't kill your app if you do. If you are coding for gnome, an #include <gnome.h> will take care of all that for you. A link to the library help files for glib is included at the end of this tutorial, for your convenience.
Now cd to the src directory and type make. This will compile your interface's basic code. Run it by typing ./projectname. See it start up, notice that all the windows you created are loaded. This is probably not what you want, but leave it for now. It doesn't do anything, but go ahead and browse around the interface. When you exit it, you will find it doesn't exit cleanly. So Ctrl-C the application and get your prompt back.
Start up your favorite code editor. I myself use Gvim, but whatever suits you, use it. Load up main.c and we'll take care of the problem with all the windows loading. Remove the GtkWidget *whatever variables and the whatever = create_whatever_widget() functions calls, leaving only the main window call and variable. Now load up callbacks.c and add in the code to close the main window cleanly, so it exits the application properly. If you didn't add the handler for this in Glade when you made the main window, go back and do it, and rebuild the code with Glade.
gboolean on_projectname_main_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
gtk_exit(0);
return FALSE;
}
Save the file, exit your editor and compile the code again. Start up your program. The spurious windows should be gone, and you should be able to exit with a click to the upper righthand corner of the main window.
From now on, you'll continue to add the guts of the handler/callback functions in callbacks.c. If you need to add other files, for instance, data input/output and manipulation (ie the 'backend' of your application), don't forget to add entries for them in projectname/src/Makefile.am.
When your application is finished, or ready for its first release, you'll want to give it a version number. Do this in /projectname/configure.in. Change the versionnumber in AM_INIT_AUTOMAKE(projectname, versionnumber) to what you desire. You can, at this point, use make install to install your application to your whole system (you'll need to be root for this). To make a distribution you can use make dist to make a tarball of your application.
And that's it, you're done with the application!
For an example of how callbacks and handlers are actually linked to code, and how gtk functions are linked into an application, see the example on the next page.
| Previous | Up | Next |