typesafe

Archive for the ‘GNOME dev.’ Category

Using custom widgets in Glade3

without comments

While playing around GNOME and Gtk development, it became interesting to me how to add custom widgets that are not in Gtk+ base library, GtkSourceView, for instance.  I discovered that Glade’s Custom Widget is obsolete.

Custom Widget is obsolete in Glade3

Naturally, for new development, one does not use obsolete features. I searched Google to find out what’s offered in place of Custom Widget but could not find any sane answer… well, until I found this mailing list message.

You just don’t add any custom widgets in design-time in Glade. Instead, you just instantiate your widget and add it to some placeholder, like GtkPaned, for example.

In C#/Mono it looks like that:

using GtkSourceView;
public class Foo
{
  [Glade.Widget]
  private Gtk.Paned paned;
  public Foo()
  {
     //Initialization, Autoconnect, etc
     //....
     SourceLanguagesManager manager = new SourceLanguagesManager();
     SourceLanguage language = manager.GetLanguageFromMimeType("application/x-perl");
     buffer = new SourceBuffer(language);
     buffer.Highlight = true;
     paned.Add1(new SourceView(buffer));
  }
}

Of course, you only need private member if you’re going to reference your container (Gtk.Paned in this case) instance from somewhere else in your code. Otherwise, just use Glade.XML’s GetWidget().

Glade3 has been around for a while, so I’m wandering why there’s so little information on this. Who knows, maybe it’s just too obvious.

Written by martinsb

March 16th, 2009 at 3:14 pm

Posted in GNOME dev.

Tagged with , ,