This program is a code generator for Glade that produces C# code. It will make it nearly as easy for you to develop a cross-platform GUI with Gtk as it is with Windows Forms. The generator has been tested on both Windows and Linux with Mono.
To be able to run Gtk# GUIs on Windows, you need the Gtk# runtime. You can get it here; it is 23.3 Mb. The GUI designer Glade can be downloaded here. Alternatively, if you have Mono for Windows installed, it is under Start-> Mono 1.2.4 for Windows -> Applications -> Glade. If you are using Linux and are interested in this article, I presume that you already have Mono installed and that you are more familiar with this topic. Thus, I will explain in more detail for Windows users.
Cross-platform GUIs: left Linux and right Windows
How does it function? The tool is pretty simple. It watches the *.glade file that you selected in the upper file chooser for changes. A change in this case means that you saved it in Glade. So, when it detects the change it parses the Glade file for widgets and signals. Then it puts them into your code as specified in the *.cs file in the second file chooser. I will later go into more detail.
I am now going to explain the procedure for VS 2005. After you have downloaded and installed the Gtk# runtime, download GladeSharperTemplate and put the ZIP file like it is (unzipped!) in the directory: My files\Visual Studio 2005\Templates\Project Templates. Start VS and begin a new GladSharperProject from the templates. The main file looks like this:
staticvoid Main(string args)
standardNamespace + "." + "gui.glade", null, null);
Now download and start GladeSharper. As a Glade file, you select gui.glade in your Project folder and as a C# file you select GladeAppDummy.cs -- i.e. the file from above -- in the same folder. Click "Start watcher." Now you can start Glade and open gui.glade in your Project folder again. Design your GUI and save it. Then the widgets and signals are made available in your Editor. You just have to reload the code when VS asks you. Don't forget to uncomment
window1.Show() after you've created the first window.
To make the application react on the Close button, you create the signal destroy for your window. Save the Glade file. The signal will be added to your code. Then put in
Application.Quit(), as shown below:
voidon_window1_destroy(object sender, EventArgse)
The widgets are placed in
#region GtkWidgetDeclarations. Don't write any code within this section, as it will be deleted. However, you can move the whole region and it will stay there when the code is updated. You can move the signal handlers freely in your code wherever you like; they will not be moved again or deleted. They also won't get deleted when you deactivate the signal in Glade! So, if a signal is no longer responding, have a look at Glade's properties!
To find out which
EventArgs a signal uses, I had to use Reflection. In the Glade file is the name of the widget and the signal. With Reflection, I look up the signal and find out which
EventArgs it uses. You will have something like this:
voidon_window1_client_event(object sender, Gtk.ClientEventArgse)
voidon_togglebutton1_toggled(object sender, System.EventArgse)
As you can see, the
EventArgs have full qualifiers like
System.EventArgs. Sometimes the name of the signal cannot be found in the Gtk# API. In this case, the signal will also be put in the code and it will be functional. It could be, however, that it has special
EventArgs. You will recognize this through seeing that
EventArgs is not qualified, i.e. there is no preceeding
voidon_button1_activate(object sender, EventArgse)
That is the one example I spoke of. The Event here is called
Activate, but in the Gtk# API it is called
Activated. Either way, the
System.EventArgs so it makes no diference. When you see a signal handler with unqualified
EventArgs, you know that GladeSharper was not able to find it in the API. If you look by hand, it may be that the signal has more special
A last hint: If you are unsure about whether you saved your code, when the Editor tells you that the code has changed and asks if you want to reload it, just click No. Save your code and click Save in Glade again. I hope you like the generator! If you are missing functions, post in detail in the comments section!
- 18 July, 2007 -- Original version posted