[gtkmm] libglademm



Hello everyone!

First of all, as a total newcomer to gtkmm, I'd like to introduce myself. I have earlier experience from GTK+ programming, and I'm a rather experienced C++ programmer, but it's not until now that I've actually taken the time to get all the bits and pieces together needed to get a gtkmm development environment up and running.

As my email address suggests, I don't do GUI programming professionally (actually I don't do much programming professionally at all nowadays) but rather I am tinkering around with open source stuff and personal toys.

Anyway, right now I'm playing around with a rather complex user interface and I thought I'd use gtmm together with libglademm for the job.

As always, there are some problems, so here we go;


1. Mapping the glade-generated widget hiearcy to my C++ code.

An old favorite I assume from searching through the archives of this and related lists (I can hear you all crying out in pain about going through this again).

I've taken the route of creating my own Gtk::Window objects with a constructor that looks up the guts of the corresponding window in the Glade::Xml and reparents it to itself. I also copy the basic attributes (such as title, etc) from the corresponding Glade::Xml window into my own window.

Now, is there a better way of doing this? Specifically;

This works fine with a flat bunch of Windows, but what if I need a more complex hiearchy? Can/should I reparent at several points in the hiearchy?

Currently, I copy the attributes from the Glade::Xml into my own object "manually" (i.e. attribute-by-attribute). Is there a way to make this simpler (i.e. like this->clone(xmlWindow);)?

I'm a bit worried about reloading (i.e. calling Glade::Xml::create()) the XML everytime I create a window. The XML file is rather large. Is there some magic that avoids this internally, or should/can I re-use the Glade::Xml?

Unfortunately, the provided examples seems to more or less avoid these issues... :-(


2. Connecting signals

To connect a signal, I need about 5 lines of code for each signal (given that I want to avoid a segfault if the widget can't be located in the Glade::Xml). This is not _too_ bad, but mapping hundreds of signals still means a lot of code. I tried to cook up some shortcuts using templates which would allow me to do something like:

   connectActivate("my_widget", &MyWindow::onMyWidgetActivate);

but I wasn't able to come up with a completely elegant solution.
Any tips?


3. Mapping variables

Having tinkered with the signals, I moved along to look at how I would manage the widget values and found Glade::VariablesMap which provides exactly what I was looking for. Additionally, I would be able to use a similar mechanism for my signal connection shortcuts.

At least, so I though...

I got quite disappointed to find out that Glade::VariablesMap, by design, only works with entry boxes and checkbuttons (which is not mentioned anywhere, of course :-)). I suppose that there must have been plans on how to extend this to work in a generic way when this interface was added to libglademm. I can't figure out how it would work though...
Any ideas?

--
Christer Palm




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