.NET on Linux: C# Development with Mono and Glade, Part I

Glade is a GUI development environment for creating applications using the same type of visual development tools as one would use in Delphi, JBuilder, Visual Basic or many of the .NET languages hosted in Visual Studio. You can read about Glade at the following URLs:

  • http://glade.gnome.org/index.html
  • http://www.gotmono.com/docs/gnome/bindings/glade/glade.html

Installing Glade

There are at least two versions of Glade available at the time of this writing:

  • The original Glade for Gnome 1.4, distributed as Glade 0.6.4 at the time of this writing.
  • And the fancier Glade 2 for Gnome 2.4 and 2.6, distributed as Glade 2.5 or 2.6 at the time of this writing. In particular, Glade 2.5 comes in this package: glade2-2.5.0-1.i386.rpm.

Be sure to install Glade 2, as the original Glade does not have support for the Gnome interfaces needed to build this kind of application. At the time of this writing, the most current version of Glade is 2.6, which is what I get on Fedora Core 3. But when I was on Fedora Core 2, yum retrieved Glade 2.5, which I was able to use without mishap. As mentioned earlier, I am not currently developing Mono applications on Fedora Core 3 while I wait for the Mono packages to be updated.

You can download Glade as a tarball or as a Debian package from http://glade.gnome.org/download.html. But on Fedora Core 2 and Fedora Core 3 I installed Glade 2 by issuing this command:

yum install glade2

Note: You can read more about yum by reading my introduction to that subject.

Yum had to resolve numerous fairly complex dependencies in order to install the Glade package. It is the resolution of these dependencies that leads me to recommend yum. Trying to resolve all those dependencies by hand can be a frustrating process, and it is nice to just sit back and watch yum pull down seven or eight dependencies and install them all for you automatically.

NOTE: If you are currently running the Gnome desktop, you can discover the version by right clicking on the panel and selecting About. You can subscribe to the user’s list for Glade at http://lists.ximian.com/mailman/listinfo/glade-users..

Installing Mono with Yum

The most difficult step in using Mono on Linux is the install. Unless you are a very experienced Linux user, you don’t want to try to take this step by hand. The Mono libraries have a number of complex and very specific dependencies, and trying to resolve them all manually can be a painful experience. Instead, you want to use an automatic install system of one kind or another.

There are two primary ways to install Mono on Linux. For quite some time, the Ximian RedCarpet, which I believe is now called Novell Zenworks, was the preferred method, and it is still a reliable system to use. However, you can also use yum to perform the install. I prefer using yum because it comes with Fedora Core and is supported by the Mono project as specified on their download page.

As described in my article, yum installs applications by first pulling down packages from a repository on the Internet. You need to tell yum where these repositories are located by modifying your yum.conf file. If you are using Fedora Core 2, here are the lines to add to your /etc/yum.conf file:

[mono]
name=mono
baseurl=http://www.go-mono.com/archive/1.0.2/fedora-2-i386/
#http://www.go-mono.com/archive/yum-repository/fedora-2-i386/

Then issue this command:

yum install mono-complete

All of the many files needed to support Mono will then be pulled down and correctly installed. Typically, this can save hours or even days of work.

After installing Mono, you want to make sure that GTK# is also installed on your system. GTK# is the API you will use to connect Mono to the code generated by the Glade development environment. Installing GTK# involves working with two packages called gtk-sharp-gapi and gtk-sharp:

yum update gtk-sharp-gapi
yum update gtk-sharp

After you are done, you should be able to type mono or mcs at the command line and get back some sensible output other than “command not found.” You should also find that the “Glade Interface Designer” is part of the Programming node of your menu. If it is not on the menu, try typing glade-2 at the command line to launch Glade from the default /usr/bin directory.

A Glade Primer

Now that you have everything installed, the next step is to bring up Glade and get to work. When you first bring up Glade 2, you see the main window.

Choose Project | New, and select New Gnome project, from the New Project dialog. In particular, selecting Project | New causes the New Project dialog to appear. In that dialog, select New Gnome Project.

In the View menu of the main Glade window, be sure that both View Palette and Show Property Editor are checked.  You can use the palette to create new windows, and then to decorate your windows with various controls such as buttons and labels. You can drop these controls on to a window in order to create a user interface, much as you would in Delphi, or Visual Studio.NET. All of this will be described in depth in this article, and in the next installment of this article.

In the upper left hand corner of the Palette, on the GTK+ Basic page, you can see an icon for creating a new window. Select this icon. The result is a new window. In the upper left hand corner, you can see that the new window is listed as window1 in the main Glade window.
The three main windows of Glade are shown to the southwest (the palette), northwest (the main window) and northeast (the properties window). The window in the southeast is the design surface created when you clicked the icon in the upper left hand corner of the palette.

The editable features of window1 are shown in the properties window, found in the upper right hand corner. You can, for instance, change the name or title of the window you created by editing the fields in the properties window. More generally, the properties window lets you set the properties of the currently selected control. You can see that window1 is selected. The name of the window, as you can see, is window1, and its title is window1. You can use the properties window to set the name of the window to myWindow, and the title to My Window.

The window has changed from window1 to myWindow and the title has changed from window1 to My Window. You can see the new title in the window shown in the southeast of this screen shot.

No comments yet

Leave a Reply

You must be logged in to post a comment.