HOME            UP --^           NEXT-->>  Demo-2
side4linux, a simple integrated development environment!

GTKC Demo-1  Creating a GTK+ project and adding an 'About Box' using Glade-3. Also how to change the Version number of your Project.

Purpose:  To provide a basic introduction to adding an 'About Box' to a new GTK+ Project.
We will not be creating a new Product for this so we will place the new Project into the existing Product 'MC-1`'
Note this Demo is intended to be built using Glade-3 and not Glade-2 which is now deprecated.


Requirements:

Exercise-1: Create the basic program and add the 'About Box'.
  1. Open 'side4linux' and click on 'Project>New Project' in the Main Menue.
  2. Select 'GTKBUILDER 'C' GUI Program' as in figure-1 below and click on 'NEXT' in the Dialog Box.
  3. Select the 'PRODUCTS' Product Area in the Product Selection Dialog and click on 'OK' as in figure-2,
  4. Select 'MC-1' from the Product Area selection Combo Box ( figure-3 ) and click on the 'Next' button,
  5. In the New Project dialog enter the name of 'About' as in figure-4 and click on 'Build'.
  6. Once the Project is Built, close the project then re-open it to let things settle into place.
  7. 'Project>Close Project'
  8. 'Project>Open Project'
  9. Double click on the 'PRODUCTS' Product Area,
  10. Double click on the 'MC1' Product,
  11. In the file dialog double click the  'GTKC' folder, this takes you to where 'GTK' visual 'C' language projects are kept.
  12. Double click on 'About', this opens the 'About' project folder.
  13. Double click on 'about.prf', this opens the 'About' project file.
  14. Now open the Glade-3 GUI builder program, 'Edit Project>Edit Project Visuals with Glade-3'
  15. ( un-dock the windows and shrink the Main window to about one third screen size )
  16. Double click on the 'mainWindow' widget in the 'Inspector' window to make it appear if it is not already visible in the 'Main' window ( figure-5 ).
  17. Notice that the top of the Glade program's Main window says that we are editing 'about.glade'.
  18. Notice the 'Palette' window from where we 'pick' our visual widgets from ( figure-6 ).
  19. Notice in the 'Properties' window that the 'Name' of the main window widget is set to 'mainWindow' ( figure-7 ),
  20. Now let us add our 'About Box', click on 'Toplevels' in the 'Palette' window and then click on 'About Dialog' ( third from top left )
  21. This should enter the 'aboutdialog1' into our 'Project Box' below the 'Main Window' entry ( figure-8 ),
  22. Click on 'Save' in the Glade Main window to save the 'glade' GUI XML file ( about.glade ).
  23. Now close the Glade-3 GUI Builder program.
  24. Close the newly created project 'Project>Close Project'.
  25. Note that it will be stored in the 'GTKC' section of the 'MC-1' Product.
 

Fig-1

Fig-2

Fig-3

Fig-4

Fig-5

Fig-6


Fig-7


Fig-8

Exercise-2: Re-open the new project and connect the 'About Box'.
  1. Open the newly created 'About' project 'Project>Open Project'  in the IDE.
  2. Note that it will be stored in the 'GTKC' section of the 'MC-1' Product.
  3. Let us now add the callback to show the 'About Box',
  4. We will 'run' the Program 'about' in a terminal.
  5. Change workspaces and open a terminal program in the ' ~~ /SIDE/PRODUCTS/MC1/GTKC/About/src '  directory,
  6. and run the program ( ./about ) notice the full stop and forward slash to run a program in the current directory to get the following messages ( or similar ),
db@wks1:~/Data/Projects/SIDE/PRODUCTS/MC1/GTKC/About/src$ ./about
Trying local 'glade' file
Local 'glade' file found!

(about:8359): Gtk-WARNING **: Could not find signal handler 'on_programQuitToolbutton_clicked'
(about:8359): Gtk-WARNING **: Could not find signal handler 'on_fileSaveAsToolbutton_clicked'
(about:8359): Gtk-WARNING **: Could not find signal handler 'on_fileSaveToolbutton_clicked'
(about:8359): Gtk-WARNING **: Could not find signal handler 'on_fileOpenToolbutton_clicked'
(about:8359): Gtk-WARNING **: Could not find signal handler 'on_fileOpenToolbutton_clicked'
(about:8359): Gtk-WARNING **: Could not find signal handler 'on_aboutMenuitem_activate'
(about:8359): Gtk-WARNING **: Could not find signal handler 'on_programQuitMenuitem_activate'
(about:8359): Gtk-WARNING **: Could not find signal handler 'on_saveFileAsMenuitem_activate'
(about:8359): Gtk-WARNING **: Could not find signal handler 'on_openFileMenuitem_activate'
(about:8359): Gtk-WARNING **: Could not find signal handler 'on_newFileMenuitem_activate'


Notice that these are all 'callback signals' that the IDE has set up for you when it built your new project 'About'.
We will note that there needs to be 'signal handler functions' created ( often referred to as 'callback functions' ) to match the callback signals.

You will create two callback handler functions, one to 'show' the About Box and one to 'close'
the About Box.
Note you should follow the norm of placing the prototypes into your 'callbacks.h' file as follows ( you can just copy and paste the following! ),

void aboutdialog1_response_cb();
void on_aboutMenuitem_activate();

followed by the actual functions into 'callbacks.c' as follows,

GtkWidget *aboutPtr=NULL;

void aboutdialog1_response_cb()
{
  gtk_widget_hide(aboutPtr);
  g_print("About box close button pressed\n");
}

void on_aboutMenuitem_activate()
{
  char versionString[256];

  sprintf(versionString," %s",VERSION);
  g_print("fetching About Box\n");
  if(aboutPtr == NULL)
     aboutPtr = GTK_WIDGET(gtk_builder_get_object(builder,"aboutdialog1"));
  gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutPtr),versionString);
  g_signal_connect(GTK_OBJECT(aboutPtr),"response",G_CALLBACK(aboutdialog1_response_cb),NULL);
  gtk_widget_show(aboutPtr);
}

Open the files in the Notebook of the IDE  ( click on 'Open-Txt' Toolbar button ) and cut/paste from above.
Make sure there is at least one blank line below your code so that your 'C' compiler does not complain!
Then click on 'Build'.

Now change to the other workspace and in a terminal run the file as above,
you should see your visual Program ( figure-9 ) and the warning messages should no longer refer to
'on_aboutMenuitem_activate'.


Fig-9

Fig-10


Exercise-3: Connect up the remaining callback ( 'File>Quit' ).
  1. Open the newly created 'About' project 'Project>Open Project'.
  2. Note that it will be stored in the 'GTKC' section of the 'MC-1' Product.
  3. Open the Glade-3 GUI Builder program, 'Edit Project>Edit Project Visuals with Glade-3'
  4. Now double click on the 'mainWindow' widget so that we can connect the 'File>Quit' signal.
  5. Double clicking should make the 'mainWindow' active in the Glade-3 Main Window so click on  'mainWindow' widget 'File' then 'File>Quit'.
  6. Look at the 'Properties' window for 'Quit1' in the 'General' tab, click on the 'Signals' tab and notice the signal 'activate <on_programQuitMenuitem_activate>'.
  7. As we already have a quit function in callbacks.c ( void gtkQuit(void); ) we need to add just an 'on_programQuitMenuitem_activate()' function that calls it as follows,
add to callbacks.c

void on_programQuitMenuitem_activate()
{
  g_print("Main Menue quit button pressed\n");
  gtkQuit();
}

also add to callbacks.h

void on_programQuitMenuitem_activate();

Quit the Glade-3 program to return to the IDE editor notebook.
Add the above text to the respective files.
Click on the 'Build' toolbar button in the IDE to re-build the 'About' Project.
Now change to the other workspace and in a terminal re-run the 'about' file as above,

Fig-12

Fig-13

Fig-14

 
To end the Practical we cannot have Users clicking the 'X' in the top right corner of the About Box widget ( figure-10 ) as it will destroy it such that it will not show later. So in the Glade-3 program click on the 'aboutdialog1' widget entry in the 'Inspector' window and in the 'Properties' window, in the 'General' tag, change the 'Deletable' property of the widget to 'No' . Also in the Glade3 program, erase the 'Program name' property which currently says 'Glade' so that the line is empty of all characters and spaces.
Now try running the program again after you have clicked on 'Save' in Glade-3 and clicked on the 'Build' button in the IDE, to see if the little cross has gone away! ( figure-12 )

Finally we can alter the Project Version String to show that we have updated the Project, 'Project>Edit Project>Edit Project Properties'.
Set the Project to Version '0.0.2' in the Dialog Box and click on 'Apply' ( figure-13 ).

Now try running the program again after you have clicked on the 'Build' button to get the revised 'About Box'. ( figure-14 )


Summary: Creating a new Visual Project using side4linux and Glade-3
Note: Should you not succeed at this point in the Demo then look in SIDE/DEMOS/SIDEdemos/GTKC/About for a working copy of the 'About' project.


Further Excercises: Add your own 'About Box' callback signal using the Glade3 program.

In the example given above we generated callback signals either manually using a callback handler in the code ( callbacks.c ) such as,

g_signal_connect(GTK_OBJECT(aboutPtr),"response",G_CALLBACK(aboutdialog1_response_cb),NULL);

which generated the 'response' callback which is linked to the 'About Box' 'Close' button.

Or, we made use of callback signals generated by the IDE during the 'Build' process such as the signal emitted when one clicks on the Main Menu's 'Help>About' button in the 'about' program which generated the 'on_aboutMenuitem_activate' callback signal.

So, now we will create a new additional 'About Box' callback signal using Glade3 to create the callback signal, we will attach this signal to the 'Edit>Cut' Main Menu Button.....
(about:10843): Gtk-WARNING **: Could not find signal handler 'on_cutMenuitem_activate'

add to callbacks.c

void on_cutMenuitem_activate()
{
  g_print("Main Menue Edit>Cut button pressed\n");
  on_aboutMenuitem_activate(); // calling existing 'About Box'
}





Fig-15
Fig-16

Note: Check in SIDE/DEMOS/SIDEdemos/GTKC/About for a working copy of the 'About' project.



Further reading: Check out the following book for some GTK+ programming references..


http://www.gtkbook.com/home.php



Foundations of GTK+ Development
by Andrew Krause

Publisher: Apress
Pub Date: April 2007
Print ISBN: 978-1-59059-793-4
Web ISBN: 1-59059-793-1
Pages: 630








We will provide other demos as 'side4linux' develops to cover GTK+ visual programming and integration into a real world machine controller.

GUI interface made with Gtk and Glade GUI demo built with Glade