| Previous | Next |
The lecturer hated having to figure out the conversion between Celsus and Fahrenheit whenever she needed it. So she wrote an application to do it for her. This application can also be a nice frontend for the units program that ships with many Linux distros. (Note that the units program only does straight multiplicative (ie linear) transfers, not ones like the C to F or F to C conversion.)
This application will take a value in C or F and convert it to the other scale. It will do so without any other user input, but a carriage return.
If the user enters anything rather than a number an error message will be sent to the status bar of the application. This is the only foreseeable user created error.
| Creating the GUI | |
|---|---|
| Open glade2 by selecting Glade from the programming subsection of the main menu (this is under Redhat). | |
| Click on the 'new' button. A window will open asking if this is to be a gtk or gnome project. Select Gnome. Doing this provides access to the gnome widgets, which are convenient to use and easy ways to keep inside at least the first part of the gnome guidelines. | |
Click the 'options' button on the main glade window. This will open a window which looks like the screenshot to the right. There are several tabs to consider, the default is the 'general' tab. Backspace over the project1 section of the project directory entry and add gtemp. This will set the other name variables to gtemp as well. Set the subdirectories for source and pixmaps if you wish to change them from the default, and select the preferred language. Glade comes with C and C++ native to it, other languages are available as add-ons. Then move to the C options tab. On the C options page turn off gettext support for now. Gettext supplies support for internationalization, but in my experience is the number one source of autogen and configure problems with Glade. For this tutorial we won't deal with it. Leave the other options as they are. If you were to create an application which used several different glade files, you'd want to change these options as needed. Examine the libglade tab. This option allows you to save strings for translators. This is important if you are creating an international application. For this tutorial application, we'll leave the settings at default for this. |
|
| Setting up the First Window | ||
|---|---|---|
![]() |
Go to the Palette window of Glade. Click on Gnome to change to the gnome widget palette, then click on the first widget in the upper left. This is the gnome application window widget. It'll set up an empty window with all the standard gnome menubar and toolbar, with the standard gnome entries on each. The widget you created should look like the picture to the left. In the properties window, with the application window widget selected, rename it to something like 'gtemp_app'. The rest of the properties entries for this window can be left as they are, for now. You can explore the default entries already set into the menus on the menubar and see the buttons on the toolbar. The Gtemp application is so simple it doesn't need most of these options. In fact, the only ones it'll use under present design concerns are the exit open under the file menu, the help menu, and it'll need an exit button on the button bar. There is nothing to save, as the results the program gives are loaded to the window immediately. There is no file to open, as input to the program is taken directly from the window. There is nothing to edit, and nothing to view.. yet. So we'll take out the commands which will always be unused, and set those that are not used yet to be insensitive (inactive/greyed out). Later on, we can set them to active if we decide to use them. |
|
First highlight (click in) the toolbar. This is the rectangular section in which the stock buttons (New, Open, and Save) are residing. You'll see toolbar1 appear under 'name' in the properties window. Notice that it specifies the toolbar size as 3. We only want one button, a quit button. So set this size to 1. This should leave you with only the 'new' button on the toolbar. Now highlight (click on) that 'new' button. It should be called 'button1' in the properties window. Change the name to 'quit_button'. Go down to the stock button selection and hit the down arrow. This will bring up a stock button selection menu. Select the quit icon. Give the button a border width, 5 or 3 looks nice. Click the save button in the main glade window to save what you've done so far. |
||
|
Now, back in the gtemp application window, click on the 'file' menu selection. The menubar should be highlighted, and the properties window should show 'menubar1'. Click the edit menus button in the properties window. You should see a new window appear, one which looks like that to the right. It will be labeled, 'menu editor'. You should notice that the layout on the menubar is replicated by the layout and indentations in the window of the menu editor. File is a header on the menubar. Clicking on it opens a submenu which lists 'new', 'open', 'save', 'save as', a menu separator (line) and 'quit'. We'll just need quit. Select each option that we don't need in the menu editor and delete it by hitting the delete button to the right. Under the Edit menu header there is little we need. But we might possibly want to add preferences and properties later on, so we'll keep those in the menu. Delete everything ele under 'edit'. You can click 'apply' and go back to the gtemp application window to see the results of what you are doing. We won't need the view header at all, so delete it. We'll keep help, and its menu item 'about' because we'll put in an about popup window. Everyone deserves credit for what they create, after all. |
![]() |
|
| There's one other change we'll make to the gtemp application window. We've no need for a progress bar, but the status bar will be useful for conveying messages. Select the status bar in the gtemp application window. It'll be called 'appbar1'. Rename it if you wish, although this is not necessary as there is only one appbar in the application, and it's unlikely the stock names will become confusing in this case. In the properties window, set 'progress' to 'no' by clicking on the button to the right labeled 'yes'. | ||
| When you've finished you should have a gtemp application window that looks like the screenshot to the left. We still haven't done anything about data or setting up what the application does, but hopefully you've learned how to call up the menu editor, how to set a few parameters using the property window, and that it's ok to click and explore at random with glade. If you really hate what you do, you can always go back to the backup *.glade file which glade writes each time you save, or just reload the application, or go ahead and undo all you did in glade. | ![]() | |
| Previous | Next |