Glade Tutorial
Glade Tutorial
A Tutorial by
Paul Hogan October 2006
[email protected] - [email protected]
Table of Contents
i Introduction 1
ii A Note on Terminology 2
1 Glade The Starting Point 3
2 Gedit The Starting Point 9
3 Python Run #1 11
4 Glade Configure Window1 13
5 Gedit Connect The Window1 Destroy Signal 17
6 Python Run #2 18
7 Glade Add A Button 19
8 Python Run #3 22
9 Glade Configure The Button 23
10 Python Run #4 27
11 Glade Complete The GUI 28
12 Python Run #5 30
13 Gedit Complete The Python Code 31
14 Python Run #6 The Finished Application 32
15 Final Words 34
Introduction
Coming from Windows I found the way GUIs are created under
Linux totally alien, time consuming and very frustrating especially
being used to development environments such as MS Access etc.
Gedit
1
A Note on Terminology
2
Glade The Starting Point
1.2 You should see the forms as detailed below, if you don't
have the same layout then click the View menu on the
window titled 'Glade: <untitled>' and tick every option
except 'Show Clipboard'.
3
1.4 The Main window
4
1.6 The Widget Tree
5
1.8 Click New on the Main window to display the New
Project dialog.
1.10 Click the Save button on the Main window toolbar to display
the Project Options dialog.
1.11 Change the last entry in the Project Directory field from
project1 to glade-tut.
6
1.12 Notice that Project Name and Program Name change to
glade-tut too.
1.14 View the contents for the project directory you just
created. Two files have been created, glade-tut.glade
and glade-tut.gladep
The .glade file is the XML file that we will use with Python,
don't be concerned with this file as everything we do with
it will be done with Glade.
7
1.15 Go back to the Glade desktop and click the GTK+ Basic
button on the Palette.
1.16 Click the Window button on the Palette. If you hover your
mouse over the buttons you will see a tool tip which will aid
your locating the correct button.
8
Gedit The Starting Point
2.1 Select the Gedit desktop and select the Gedit window.
2.4 This is not a Python guide so I will only explain the bits to
do with Glade, there are plenty of Python tutorials out
there should you need further reading.
9
2.4.3 The if block checks to see if this code is being
called by Python or as part of an import
statement. If Python is calling it then an
instance of the GladeTut class is created and the
the GTK.Main() function is called to run our
application.
10
Python Run #1
3.1 Select the console desktop and click in the console window.
cd /home/pachjo/Projects/glade-tut
python glade-tut.py
11
3.7 And here we see our first problem, the window has closed
but we don't get our console prompt back! This is
because we have not told GTK to stop running so to get
our prompt back press ctrl-c
12
Glade Configure Window1
13
4.4 To save a little time we will modify a few settings in one
go and I will explain what they are and what they do.
First off click on the Widget tab.
4.6.1 Click the button with the label ... to open the
Select Signal dialog.
4.6.2 Scroll all the way to the bottom until you see the
heading GTKObject Signals and select the option
destroy then click the OK button.
14
4.7 Click on the Save button on the Glade Main window.
4.8 Your window1 Properties window should now look like this.
15
4.8.3 The Signals tab
16
Gedit Connect The Window1 Destroy Signal
5.1 Select the Gedit desktop and select the Gedit window.
17
Python Run #2
6.1 Select the console desktop and click in the console window.
python glade-tut.py
6.5 You will see the window title is now Glade-Tut, that the
window is the size we set and that it is now not resizeable.
6.6 Close the window and see that the prompt returns as we
setup the destroy signal to ensure our application closes
correctly.
6.7 Now lets get to adding some bells and whistles to our
application.
18
Glade Add A Button
7.3 Click on the Vertical Box button then click anywhere on the
window1 window to display the row setup dialog.
19
7.7 Click on the little triangle to the left of the window1
entry in the Widget Tree window to expand the entry.
7.8 Click on the vbox entry and see that its properties are
then displayed in the Properties window.
7.9 For the time being we won't change any of the properties
as it will make more sense once we place a widget in it.
20
7.11 Click on the Button button then click anywhere in the top
row of the vbox in window1.
7.12 Your Glade desktop should now look like this.
21
Python Run #3
8.1 Select the console desktop and click in the console window.
python glade-tut.py
8.5 Like when we first created and ran our application for the
first time, the button functions as expected in that it will
depress when clicked. However as we have not yet setup a
signal for the button nothing happens.
8.6 Lets now return to Glade to see how we can change the
properties of the vbox and the button and add a signal to
our button.
22
Glade Configure The Button
9.9 btnNumberOne now fills the entire first row of the vbox.
9.13 Click the Add button on the Signals tab to add the signal
to the list.
23
9.14 Click on the vbox entry in the Widget Tree window so that
its properties are displayed in the Properties window.
24
9.21 Your button Properties window should look like this.
25
9.21.3 The Signals tab.
26
Python Run #4
10.1 Select the console desktop and click in the console window.
python glade-tut.py
10.4 Not exactly what we wanted, but we can see that our single
button now has a neat border around it.
10.5 Lets get back to Glade and finish the GUI work.
27
Glade Complete The GUI
11.4 Click on the Button button then click on the second row of
the vbox in window1.
11.5 Click on the Label button then click on the third row of
the vbox in window1.
11.8 Click on the button you just added to ensure its properties
are displayed in the Properties window.
28
11.13 Change Expand to Yes.
11.17 Click the Add button on the Signals tab to add the signal
to the list.
29
Python Run #5
12.1 Select the console desktop and click in the console window.
python glade-tut.py
30
Gedit Complete The Python Code
13.1 Select the Gedit desktop and select the Gedit window.
31
Python Run #6 The Finished Application
14.1 Select the console desktop and click in the console window.
python glade-tut.py
14.3 Our window should now look like this after you click button
Number One.
32
14.4 And this is what it should like after clicking button Number
Two.
33
Final Words
Here are some useful links which might help you along the way:
http://heather.cs.ucdavis.edu/~matloff/python.html
http://python-forum.org/py/index.php
http://www.pygtk.org/pygtk2reference/
http://glade.gnome.org/
http://www.python.org/
34