Hello everyone!

I assume that you have already followed previous howto section. This is an informal tutotual page. I will show you some of the code I've written.

A Few Things You Better Keep in Mind

Don't use Glade's "build code" capability more than once.

When we build a BOND application, we use Glade to design its user interface, NOT to generate the code to draw GUI. Glade's "build code" is only useful to generate callbacks.c. Keep in mind that drawing GUI elements such as forms (generally windows), buttons, listbox, etc. are handled by BOND. The rest files such as main.c, interface.c, interface.h, support.c, support.h are not required at all. However, "build code" can be useful when you want to generate the template callbacks.c. This in the only time you may want to use "build code". After that, you should not try again because it may override your callbacks.c. So don't do that unless you haven't written any callbacks.

BOND application is data centric

It is very important to understand that the model of BOND application. I will discuss brief BOND application model later.

BOND Application Model

  (form)      
+-----------+                
|           |   (map to)    +---------+
|           |   -------->   |         |
|           |               +---------+
|           |               |         |
+-----------+

Writing Your First BOND Application

Run your favourite editor, and type the following code as fast as you can.
#ifdef HAVE_CONFIG_H
#  include config.h
#endif

#include bond/bond.h
#include bond/ui.h

#include "callbacks.h"

int
main (int argc, char *argv[])
{

        bond_init(argc, argv);
        bond_main();
        bond_cleanup();

        return 0;
}
Code 1.1

As you can see, the main.c is too simple and rather dull. Moreover, this code doesn't include any of your specific application feature, strange, huh?

In most cases, you main code will look like above. Writing a BOND application is actually writing the callback functions.


#ifdef HAVE_CONFIG_H
#  include config.h
#endif

#include gtk/gtk.h

#include "callbacks.h"

void
on_customer_tool_add_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
    int retval;

    retval = bond_formadd("customer");

    /* ASPECT: error */
    if (retval < 0) {
        puts("Ouch!!!\n");
    }

}


void
on_customer_tool_save_clicked          (GtkButton       *button,
                                        gpointer         user_data)
{
    int retval;

    retval = bond_formsave("customer");
    retval = bond_flushall();

    /* ASPECT: error */
    if (retval < 0) {
    }
}


Code 1.2

If you want quit, the whole BOND application, in a callback function call bond_mainquit(). This function post quit message to the message queue in GTK/wxWindows case, and the control of your application will go back to the main (Code 1.1) function and subsequentially, bond_cleanup() will be called.

If you need to flush cache right now, call bond_formsave("formname") first, then bond_flushall(). If you call only bond_flushall(), the immediate update will not be reflected on your form.

If you want to show

Naming Convention Revisited

As you keep work on the BOND application, you will encounter several situations,which needs more sophistcated graphical user interface interaction. Now we will touch on slightly more complicated cases with BOND naming convention.

Dealing with Dropdown box (i.e. GtkComboBox, wxComboBox)

As an simple example, say you have a database table product and product_type.
CREATE TABLE "product_type" (
    id INTEGER PRIMARY KEY,
    name CHARACTER(20)
);

CREATE TABLE "product" (
    id INTEGER PRIMARY KEY,
    name CHARACTER(20),
    description CHARACTER(200),
    producttypeid INTEGER REFERENCES product_type(id)
);


INSERT INTO product_type(id, name) VALUES(1, 'Heavy Weight');
INSERT INTO product_type(id, name) VALUES(2, 'Light Weight');

Code 1.3: tut.sql
francis@crackle:~/private/proj/tutbond/apptemplate/tut/src$ createdb -h nikita -U francis tut
CREATE DATABASE
francis@crackle:~/private/proj/tutbond/apptemplate/tut/src$ psql -f tut.sql -h nikita -U francis tut

Creating GUI with Glade

Using Notebook (i.e. PropertyPage)

Sometimes using Notebook (i.e. ) is extremly useful from escaping so many windows to reduce number of windows and grouping related things together.

So how do we map a database table to a notebook? Based on assumption that all Notebook GUI component has a label for each page, name the label of the page to database table name.

Using * in Seach Form

BOND provides a set of APIs to search a row in database. When you name a field name of search input form, use can specify '*' to at end of the field name. For example, name to name* means typing "a" in the name field will return "andru" "andrew", etc. However, it will not return "bart" because it does not start with 'a' although it contains 'a'.