| Previous | Up | Next |
| In the following I am going to build an interface for a small application which reads in latitude and longitude pairs from a file and computes the geographic center of the same, given a variable radius around a central point You can get the application here. If that sounds confusing it is. Think of it this way, I want to know where most of the people coming to a LUG meeting originate from. I only have latitude and longitude pairs for each person. That's what the program is all about. I'll use the interface I designed as an example, and highlight some important points in building Glade applications along the way. I apologize for using first person, present tense here, but it seemed most natural to me. As I wrote this while I was building the application, I thought it best to leave it natural. |
| The Main Window of Geocenter |
|---|
|
The application will need a main window, some menu functions, perhaps a simple button bar, an 'about' window, and even a splash window if I get ambitious. Most of these things are already built in a widget called the 'gnome application window', available on the 3rd menu (gnome widgets) of the Glade palette. Since this is going to be a gnome application, I'll use this widget as the base of my main window. This widget, or something like it, can also be built from the widgets on the first Palette menu (Gtk+ widgets), but with more work. The main window looks like this: |
|
I need to rename the window to something distinctive (right now it is called app1), I did that with the Glade properties window. Looking through the other 'widget' options in properties I leave them just as they are. The main window needs one callback added to it, the callback which will delete it (and close the application properly) when the X in the upper right-hand corner is clicked. In the signals tab of the properties window I added a handler for the 'delete_event' signal. The default name for the handler, which will be a function appearing in callbacks.c, is fine. The default Gnome application window, nice as it is, has too many elements for this simple program. Everything in the edit menu can be removed (as well as the edit selection itself). The view selection can be removed. I rename the buttons on the button bar. I'll need one for loading the data file, one for computing the geographic center, and one for a quick exit. The variable radius and centerpoint location will be set under the 'settings' menu, although I will set defaults in the code. I'll need a menu entry for this, called defaults. Still working with the main window (once called app1, now called geo_center_main), I do all this and set up handlers for the buttons in the toolbar. I leave a few things I'm not sure I'll need in the menus, notably the preferences entry, and the new file, save and save as entries. Maybe I'll get fancy and use them. Also, I need to change the tooltip helps for the buttons and menu items. They are still set at the defaults. I do this, so my application won't be more confusing than need be. Now, I need a container of some sort to enter into the main part of the application window. I think I'll helpfully show the radius and centerpoint location that the user picks in the settings->defaults menu in the main window. And I need a entry field for the output of the program. I could do this with labels, but I am going to use text entry widgets. This allows for future expansion if I wish to take data entry from the main window for the radius or centerpoint location some day. With these considerations in mind, I pick a table container and make it 3 rows and 2 columns big. All the left hand column are labels, the right hand contains text entries. Below is a screenshot of the window I'm buildiing when I'm almost done. label3 has not yet been changed, and the 3rd text entry field hasn't been added yet. |
![]() |
Looking at the window, I decide it's ugly. The labels need space around them, so do the entries. Using the properties window, I set the Xpad and Ypad values higher for each label. For the text entries I use horizontal and vertical padding, in the packing menu. I also set all the entry fields as not editable for the time being, as their values will be loaded by the code and not changeable by the user in the entry (yet). I can change them if and when I wish. |
| Popup Dialogs for Geocenter |
|
I need some sort of popup window to take the name of the data file. I could use the gtk file widget, but for the sake of simplicity, and time, I'm going to use a popup dialog that will take the file name from the user. It'll check for an appropriate entry, and throw up an error message window if there is not such an entry (ie the file doesn't exist, or nothing was entered). Since I'm writing a Gnome app, I'll use Gnome widgets for this. I could just as easily use Gtk+ widgets though, with a bit more work. The Gnome Dialog box comes with 3 buttons, ok, apply, and cancel. I don't think I need the apply button, so I right click on it and delete it. I set the name of the dialog box to load_file_dialog, and go about adding a vertical box container with 2 rows. The result, before I put anything into those rows looks like this: |
![]() |
I add a label to the top row, and an entry box to the lower one, and mess with the padding to make it look nice. I add handlers for the buttons, and a handler for the text entry field. I decide to use the changed rather than activate signal, that way the user doesn't have to hit return at the end of the entry. |
| Message Boxes/Windows for Geocenter |
|
Now I build the error message windows. All these need is a label and a handler for the ok button, if I use the Gnome Message Box widget. Once again each gets a distinctive name. Open seems to be the wrong word, and I won't be using the new file and save file options in the menubar under the file item. So I remove these, and change the word 'open' to 'load'. Picky as it seems, I think this gives the user a better idea of what the code will be doing. While I'm at it, I build the defaults dialog window. I use a table container again, 2 by 2 this time. The centerpoint variable is going to be an optionmenu, the radius will be a combobox. Finally I add an about box, because everyone deserves credit for their work! I also leave the preferences item in the settings menu, even though it will do nothing for now. Perhaps later I will use it. A screen shot of glade, with all the windows I made, is below. |
| The Final Product |
|
|
|
Here are the names of the widgets I created:
Next, we'll link the callbacks to the backend for this application. |
| Previous | Up | Next |