Glade# Code Generator

I wrote a very basic application to generate Glade# code from a glade xml file using CodeDOM. Its a good way for new users to get an idea of how to use Glade#, as well as a way for everyone else to save time.

This tool generates stub classes (one class per top-level widget) that use the Glade.XML object to load and interact with your glade xml file. It does not build the whole gui using code. Specifically, the following is generated:

  • Constructor that loads the XML and Autoconnect()s members in the class
  • A public Show() method for GtkWindows
  • A public Run() method for GtkDialogs
  • A public Popup() method for GtkMenus
  • Private fields with the [Glade.Widget] attribute reperesenting your widgets
  • Empty methods to handle signals (events) you have defined using Glade.

It’s extremely unfinished, but I decided to post it now because, well, I was tired of working on it :)

Some things that I would love somebody to implement are:

  • Support for other languaes (VB.net, Boo, etc.) - should be only a few lines of code to change
  • Completed message dialog should show the number of files/classes/methods/fields generated (the GenerateCode method needs to return an object containing this information rather than just void)
  • Ability to update existing source files. This is obviously quite a bit more complex, but also very vital. Perhaps putting all the widget fields into a #region and just overwriting that entire region every time is one way to go about. Google finds a few things that may be of use for this, although I haven’t actually looked at them myself: http://sourceforge.net/projects/cscodedomparser/, http://www.codeproject.com/csharp/CodeDOMparser.asp.

If all of these were to be implemented, there is a very good chance this would be integrated into monodevelop, so there’s perhaps some extra incentive for you =).

Please let me know if you have any questions, comments, or bugs!

To Download:
$ svn co https://svn.extremeboredom.net/GladeSharpCodeGenerator/

10 Comments

  1. Erik Dasque
    Posted June 9, 2005 at 6:47 am | Permalink

    Very nice little app. Very easy to use and looks good too.

  2. Posted June 9, 2005 at 9:22 am | Permalink

    Very cool little app. I love the UI.

  3. khad
    Posted June 9, 2005 at 9:34 pm | Permalink

    Good looking UI!

  4. James Chaldecott
    Posted June 10, 2005 at 1:51 am | Permalink

    About the ability to update existing source files:

    I would suggest using partial classes (MCS supports them , I think). They are intended for use with code generation.

    VS2005 now uses partial classes for all the code generated by the various designers (e.g. WinForms editor, typed Resources, XAML). Their convention is to have (up to) two files per class: “Foo.cs” for the edited code and “Foo.g.cs” for the generated code. The “Foo.g.cs” is fair game to be discarded & regenerated at any time.

  5. Posted June 13, 2005 at 5:32 am | Permalink

    Just the app I could of done with 6 hours ago when I was coding up my Glade UI on the train to work ;-)

    Worked a treat on my project anyway. Hopefully someone can add those extra features, cos they’re a little above my coding abilities.

  6. Posted June 13, 2005 at 7:52 am | Permalink

    Me again, hope you don’t think I’m spamming your comments!

    Is there a particular reason the EXE needs to be run from its own directory (ie, cd to that dir before running) ? If I run it from my homedir, and give it a full path to the exe to run, instead of cd’ing there, I get a NullReferenceException.

    I think its because its either trying to load an external resource (glade xml) or a referenced assembly (judging by a 30 sec glance at your code) and is unable to find it in the path releative to the main exe

    Only discovered this by trying to add it to the Programming menu on the GNOME panel and wondering why it didn’t do much….

  7. Martin Sieradzki
    Posted July 7, 2005 at 12:12 pm | Permalink

    Hi, well done. Really nice tool.

    Would be fine is someone could could add the vbnet support.

    Greetings from Germany

    Martin

  8. Posted November 25, 2005 at 9:08 am | Permalink

    Hi! How to me to adjust a background of page?

  9. Posted September 25, 2006 at 11:32 pm | Permalink

    Thanks for this. And nice UI!

  10. Posted August 20, 2007 at 8:05 am | Permalink

    Hi, everyone. The project on this site is interesting to me because I am a developer for a program called Gladex (http://www.openphysics.org/~gladex/). Using a Glade file it produces code using libglade for any supported language. As of 2007-09-19 it supports Python, Perl, and Ruby. We’re interested in making a C# plugin and would love to take a look at the code you have. However, the svn repository does not appear to be operational. Did your program get merged into monodevelop? Does anyone have a copy of the code? Can anyone help me out?

2 Trackbacks

  1. By jB: no - that's definitely not good enough on November 18, 2005 at 1:50 am

    Miguel de Icaza: Mono Status 2005

    After releasing Mono 1.1.10 recently, Miguel de Icaza has put up a long entry dubed “Mono Status ‘05″ on his blog concerning the current status and the upcoming changes and additions to the open-source .NET implementation. The following points are c…

  2. [...] Speaking of gaming worlds. I was reading a copy of the latest MSDN Magazine - we get them at work - and I found 1 article that was actually interesting. It covered System.CodeDOM and how to use it to dynamically generate code, compile it, and then call it from the same app. While this is nothing new - I believe Eric actually wrote an app that generates form code for you with CodeDOM - it’s something I haven’t looked into. Two applications that come to mind: genetic programming and learning machines and secondly it would be perfect for my passion of having a game world you could edit/create from inside the game. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*