| Previous | Next |
| Filling in the main application window | |
|---|---|
| As with any application, there are many ways to examine and present the
data in Gtemp. We could have a menu setting under edit->properties in which
we make the user select a C to F or F to C conversion. We could have an optionmenu
in the main window in which they select the proper conversion. This second
idea is probably the most useful of the two, as it requires less steps for the user
to get an actual result. It is also expandable, as we could add selections for miles
to kilometres, kilometres to miles and so on. However, we are only doing
temperature, so far, with this application. And the simplest way of data input
in this case is simply taking the data from a text entry field. A C to F conversion will be indicated
by the person entering the value to be converted in the C entry field. An
F to C conversion will have the value entered in the F entry field. In each case
the unused field will return the result.
We'll need two labels, one for each temperature scale, and two text entry fields, one for each entry/result pair. We need no buttons to start computation as computation will start as soon as the entry is activated by the enter or return key. This activation will send the signal we catch which begins computation. |
|
Each window element like a text entry or a label needs to be put into a container. The big hatched blank section currently in the gtemp application window is a container, but it can only hold one widget, so we need to put another container widget into it. We could use a combination of vertical and horizontal boxes, but a table container widget will work better. In the palette window click on gtk+ basic, if the palette page isn't there
yet. Click on the table container widget. It's in the 7th row from the top
and is second from the right. It looks like this: In the gtemp window, click in the empty hatched space. A popup window will appear, asking how many rows and columns you want for the table. Set rows and columns to 2, as we need two labels, and two entries. We can, if we desire, change this later in the properties window. The gtemp window should look like the screenshot to the right. |
![]() |
![]() |
Now we add the labels. Click on the label widget in the palette,
its under gtk+ basic, 2nd row from the top, 1st widget from the left and looks
like this In the properties window change the name of the label to fahr_label. Change the actual label itself to read 'Fahrenheit'. It looks sort of squished and lost up there, doesn't it? Let's give it some padding. On the main page in the properties menu for the label there are X Pad and Y Pad entries. Change them from 0 to 5. The label looks a bit more impressive now. Create another label, and put it in the top right corner of the table. Call it cel_label and make the actual label read 'Celsius'. Give it the same kind of padding as the fahr_label got. The gtemp application window should look like the screenshot to the left. |
We've to add entry widgets next. In the Palette window click on the
entry widget. This is in the 2nd row from the top, 2nd widget from the left. It
looks like this This widget will need renaming and some padding, at least. Call it 'fahr_entry'. Switch to the second page in the properties window (packing) and pad the entry by setting h padding and v padding to 5 each. On this page turn off the x expand attribute by clicking on the button which reads 'yes'. Add another entry widget to the lower right hand table area. Call it 'cel_entry' and give it padding as above. Remember to turn off the x expand attribute. Save your work by clicking the save button in the main glade window. You should have something that looks similar to the image to the right. |
![]() |
Play with the window some, expanding it and shrinking it by dragging at the corners. You might not like how it expands and contracts, or the way it looks. It's got a big area for those 4 little widgets, but they are all we need. You can play with the padding and expansion attributes of all the widgets, including the container widgets, in the properties window. The tutorial writer likes the look of the window when table1 is selected, the border of the table is set to 5, the homogenous attribute is set to on or 'yes', and row and column spacing are set to 5. You might like it differently. In this section you have learned, hopefully, how to set widgets into container widgets, how to play with expansion and padding properties, and how to set widget names. You'll be at least somewhat familiar with the properties window. Remember that you can right click on a widget while you are building to select any other widget in its parent tree, as well as copy, cut, paste or delete. | |
| Previous | Next |