(proposal for) source code generator
- From: "Amadeus W.M." <amadeus84 verizon net>
- To: gtkmm-list gnome org
- Subject: (proposal for) source code generator
- Date: Fri, 27 Jun 2008 02:37:13 +0000 (UTC)
I'm using gtkmm again after a break of about 1 1/2 years and I see some
things have changed. For one, I was building the gui with glade
(glade-2 to be precise), and then I would use glade-- to generate the
source code. I know, libglademm was the preferred method, but I preferred
glade-- because the code generated by glade-- already contained the
appropriate signal_connect() instructions. With libglademm I had to write
them myself. Anyway...
Now glade-- seems defunct, and despite my efforts to resuscitate it, I
can't repair it. So I have to byte the bullet and migrate to libglademm. I
tried some basic examples and it's not too bad, but it just crossed my
mind that one could write a code generator that uses libglademm.
To exemplify, suppose I have a trivial application with a top level window
with just a button in it that outputs "OK" to stdout when clicked. That's
the whole application. The gui part of the code for this would be as
follows:
class MainWindowGUI : public sigc::trackable
{
protected:
Glib::RefPtr<Gnome::Glade::Xml> refXml;
Gtk::Window * mainWindow;
Gtk::Button * okButton;
virtual bool on_mainWindow_key_press_event(GdkEventKey *ev) = 0;
virtual void on_okButton_clicked() = 0;
public:
MainWindowGUI(Glib::RefPtr<Gnome::Glade::Xml> refXml)
: mainWindow(0), okButton(0) {
// Get the main window.
refXml->get_widget("mainWindow", mainWindow);
if (!mainWindow)
throw std::runtime_error("Couldn't find okButton in
ok2.glade");
// Get the button.
refXml->get_widget("okButton", okButton);
if (!okButton)
throw std::runtime_error("Couldn't find okButton in
ok2.glade");
// Connect to signals.
mainWindow->signal_key_press_event().connect(sigc::mem_fun(*this,
&MainWindowGUI::on_mainWindow_key_press_event),false);
okButton->signal_clicked().connect(sigc::mem_fun(*this,
&MainWindowGUI::on_okButton_clicked));
}
Gtk::Window & getWindow() { return *mainWindow; }
};
In general, the MainWindowGUI class would contain a pointer to each widget
found in the .glade file and also pure virtual callbacks, again as
specified in the .glade file. The constructor would contain the
appropriate signal_connect() calls.
I don't know enough xml/xslt but I suspect this could be done by creating
an intelligent xslt file, say application.xsl, then generate the code with
an off-the-shelf xslt processor like so:
xsltproc application.xsl application.glade > MainWindowGUI.hh
Thus, one would not have to write massive amounts of code to parse the
xml .glade file and generate the C++ code from it. All that would need to
be written (not by me though) would be a one-time xslt file (transform).
Would this be feasible? Any xml experts willing to try this?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]