By Ishan Chattopadhyaya
Introduction
This example of the building of a program using wGLADE will show you in easy steps how to:
In this tutorial, you will see how to create an interface and how to link some common widgets with one another.
Creating the interface
The wGLADE Environment (Click for a larger view) |
Open wGLADE. You will see a number of component windows of wGLADE. They are wGLADE (Main), Palette, Properties, etc. (See figure above for an example environment ) Proceed as follows:
[Note for other programmers: Using a fixed position container is easier for beginners rather than using vertical and horizontal boxes etc. Besides, all who have previous experience with Microsoft Visual Basic/C++ or Power Builder will find it more comfortable to adjust. Using vertical and horizontal box containers can be left for a later stage in the course for a beginner learning wGLADE.]
[Tip: You can move your mouse over the icons in the palette and wait for a second for the ‘tool tips’ to popup. Take a while exploring these tool tips so you are comfortable with the development environment.]
Adding the Signals (After Clicking "..." button) |
Adding the Signals (After Clicking Add button) |
Editing the code
Now that we have successfully created the interface and built the source for it, the time has come to edit the code. Since wGLADE is not an Integrated Development Environment (IDE) like Visual Basic, Visual C++ etc., you will need to edit the code using an external text editor. Many programmers use notepad as their text editor for coding, but I prefer using a specialist programmer's editor which has a multiple document interface (MDI), e.g. Crimson Editor from http://geocities.com/crimsonware . The choice of editor is up to you!
Whichever text editor it might be, fire it up. Assuming
that during building your source you gave /home/ [username] /Projects/Project1
as the directory of your project, open the file
C:\Projects\First/src/callbacks.c
in your editor. This is the file where all the callback functions are
written. What I mean is that you can assign any functions to the widgets
that you connected during adding the signals. So, this file is mainly
responsible for the interactivity between the widgets, e.g. buttons, etc.
Begin by inserting #include <string.h> at
the top of the file.
Scroll down the file until you come across the function on_BT_EXIT_clicked. In the space that is provided within the function, add a function: gtk_main_quit(); Your function should now look like this:
{ gtk_main_quit(); } |
[Note: The gtk_main_quit() function causes the program to end. Another alternate function exit(0); can also be used for the same purpose. As you wil have seen in the previous example, the gtk_main_quit function can be included automatically from within wGLADE. This method simply represents an alternative.]
Do the same for the on_window1_destroy function. That is add gtk_main_quit() function there also. This ensures that when the window is closed using the 'X' button on the upper right, the program ends.
Similarly, add the following code to the on_BT_OK_clicked function:
{ /* INITIALIZATIONS START HERE */
/* COPYING THE TEXT ENTERED IN ENTRY1 TO THE LIST WIDGET */
/* COPYING THE TEXT ENTERED IN entry1 TO entry2 */
/* SHOWING A DIALOG BOX WITH THE TEXT OF entry1 IN IT */
} |
Now add the following code to the two radiobutton functions, like this:
{
}
{
} |
This piece of code is quite simple to understand. What the on_BT_OK_clicked function does is as follows:
Now that the coding part is done, now you have to proceed compiling your project. This is carried out in exactly the same way as mentioned in the Getting Started page.
All the examples in these exercises are available in one file ( Projects.zip ) which you can download.Overview of this tutorial
Simply follow the same steps that you used to compile your first project. This method is the one to be used for every project that you will build with wGLADE.