Using Glade for UI development on Gnome

On my post about network traffic monitor project, I said that I will share some details on it here. Well here it is. My application works on a GNOME desktop environment which is the default Ubuntu desktop. Now there are two ways to go about creating GUI application on GNOME. The hard way would be to hardcode the UI from scratch using the GTK libraries or the easier way would be using a tool like Glade that helps to generate the codes for you. Glade is an open source RAD tool.

I used Glade for my project as it is so much easier to use than hardcoding each widget like windows and text boxes. It also saves a lot of time since it is much faster too. With glade you can add any widgets that the GTK library provides into a container. You can then configure the properties of that widget for example the title name, the width and length etc. When saving the project, Glade will create an glade file which is in fact a XML file that describes all the widget and its properties so that you can use it on your application.

The Glade file can be loaded by applications dynamically by using GtkBuilder GTK object. GtkBuilder adds connection between widgets and the application source code. By using GtkBuilder, Glade XML files can be used in numerous programming languages including C, C++, C#, Vala, Java, Perl, Python,and others. Below is the code snippet to add the Glade file using python.

builder = gtk.Builder()

builder will be used as a reference to the Glade file that is added as To interact with a widget on the Glade file you need to reference it first for example:

window = builder.get_object(“main_window”)
combo = builder.get_object(“combobox_interface”)

window is now referencing the widget named “main_window” that is defined in Glade. combo is referencing “combobox_interface” widget. Once you successfully reference the widget, you can interact with them for example connecting signals to it. A signal is used to tell the application that an event has occurred. Examples of events are user clicking a button or resizing the window. Since my application is GUI based, it needs to be event-driven so that it will react whenever a user interacts with it. The codes below is an example of how to connect signals.

window.connect(“delete-event”, destroy_window)
window.connect(“response”, destroy_window)

In the codes above, I’ve connected the “delete-event” and “response” signal to the window widget. The “delete-event” signal will be emitted when the window is closed for example the user clicked to the ‘X’ button on the window. destroy_window is a callback function which is called when the signals are emitted. Callback functions are used to execute codes in response to the events.

Glade can be a pretty neat tool if you ask me especially for developers that uses RAD methodology. You can change the interface easily without changing much of the codes. You can also see the changes nearly instantly after editing the design.

I will post other information of my project soon.


Author: Darren

A 26 year old geek who was brought up in Kota-Kinabalu, Sabah. I graduated with a Degree in Computer Science majoring in Systems and Networking from Universiti Tenaga Nasional, Selangor. I am a CISCO Certified person with CCNA qualification where I am able to install, configure and maintain Cisco and network devices. With my programming skills, I also develop systems and websites for small companies as a freelancer. Things that interest me are computers and its technologies which had been a thing for me for many years now. I am also an open-source enthusiast. I have worked on an open-source project for my FYP that involves Ubuntu, GTK, and Python. I’ve made it through my Degree and I hope that one day I will be able to contribute in some way to the open source community. Other than that, I am a big fan of TV series and movies. I also like reading especially interesting tech blogs on the web.

1 thought on “Using Glade for UI development on Gnome”

  1. I am looking for people working with glade and connection between glade and gcc programmes. I can’t find some people. I would for a beginning make a litle aditions programme in gcc and then make a frame where my programme is. Only because it looks more professionel.
    Ole Hasselbalch

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s