gtkmm widgets in glade




I have bodged together an horrific hack that enables gtkmm widgets (even user-subclassed ones) to be used in glade-3. (I'm using 3.6.7)

I present this with two aims:

1) To show that it can be done (if it has been done elsewhere, and I've
   missed it, my apologies)

2) In the hope that someone knows a better/nicer/simpler way of doing it.

Basic Methodology:

Glade requires a chunk of xml (a "catalog") and a .so file to display custom widgets. The xml defines (vicariously) the name of the entry point that is called by glade in the .so. This entry point should register a new GType and return its id. Glade then uses this GType to create/display (etc) instances the widget.

I couldn't find a way of automatically generating a correct GTypeInfo structure from a subclass of a gtkmm widget so go through the following moderate hassle: create a GTypeInfo that describes a subclass of a GtkAlignment (the simplest, non-abstract, single child container I could find), then, during initialisation, create an instance of the required gtkmm widget and attach it to the GtkAlignment. Viola, a widget in glade that looks and behaves almost exactly as the wrapped gtkmm widget.

List of badness:
- Non of the properties of the gtkmm widget are exposed.
- Some properties that it doesn't have *are* exposed (the properties of
  the GtkAlignment)
- glade (obviously) does not use Gtk::Main, so I call
  Gtk::Main::init_gtkmm_internals() in the type creation function.
- The way glade calculates the entry point name from the typename is
  non-trivial. At the moment it has to be manually entered, usually after
  running glade once and noting which function it complains about when
  loading the plugin.
- The name of the entry point is defined by the name of the type -
  different type = different entry point

This last point means that one can't write a single gtkmm wrapper that will expose multiple widgets - you need a new bit of code for each widget. Hence, I generate code by having a "template" .cc.in file that is run through sed to change a few of the more important words. Equally, I have a .xml.in file that is the basis of the glade catalog.

Now, apart from exposing the properties properly, all I need to do is work out how to get Gtk::Builder to create the right gtkmm widget when it sees one of these bodge-widgets in the .glade file.

Source Code:

I have some source code demonstrating all of this, but don't want to upset anyone by attaching it to this email (it is 7 files that tar-gzip down to 1883 bytes). If anyone knows a somewhere free where I can upload it, please tell me.

-------------------------------------------------------------------
Charlie - Saxon Cambridge






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]