Re: Gnome::Glade::Xml::create_from_buffer question
- From: Bob Caryl <bob fis-cal com>
- To: Ed Leaver <eleaver sterlingseismic com>
- Cc: gtkmm-list gnome org
- Subject: Re: Gnome::Glade::Xml::create_from_buffer question
- Date: Thu, 19 Jan 2006 08:31:26 -0600
Ed Leaver wrote:
I use Glade with the same intent of not having to load UI Xml files at
startup. I'm currently using glade-2.6.8 and glademm-2.6.0. Glade has
a mode to do this directly, i.e., it writes C++ header files and
parent class files containing the parent constructor and destructor.
This apparently (from what I can see) has nothing to do with the
/Gnome::Glade::Xml /namespace, nor (again from what I can see) does it
even use libglademm. No patch scripts are needed. Is there some reason
you wish to have it both ways? I admit to never having used the
/Gnome::Glade::Xml /namespace, and thus am totally ignorant of its
advantages and features - ymmv.
Hey Ed,
I am using *only* the XML file generated by Glade hence, I use none of
the Glade generated C/C++ source code. I have written an application
that converts this output to an includable C/C++ .h file containing the
XML as a const char buffer. Gnome::Glade::Xml::create_from_buffer
takes that XML and instantiates all the widgets I placed on my window in
the Glade designer.
Prior to using Glade, I derived my classes from Gtk::Window or
Gtk::Dialog, but now, I just create a non-derived class and insert into
it all the widget pointers (including one to Gtk::Window) I will need in
order to connect necessary signals and get data from control widgets.
In the class constructor I make the call to
Gnome::Glade::Xml::create_from_buffer, and then I use
Gnome::Glade::Xml::get_widget to make my defined pointers in my class
point to the widgets that were instantiated by the create call. It
makes life very simple from a UI design standpoint for me, since I had
been hand coding all the widgets prior to this.
Here is a snippet of the XML buffer (with the middle excised out, since
its include file is somewhere in the neighborhood of 14K in size):
const char *fiscryptxml = "<?xml version='1.0' standalone='no'?> <!--*-
mode: xml -*--><!DOCTYPE glade-interface SYSTEM
'http://glade.gnome.org/glade-2.0.dtd'><glade-interface>
. . .snip. . .
</glade-interface>";
Here is the class definition for Fiscrypt:
class Fiscrypt
{
public:
Fiscrypt(void);
~Fiscrypt(void){}; // note that nothing is done in the destructor
// since Gnome::Glade::Xml takes
// care of all the memory management
// for me.
Gtk::Window *window;
protected:
Glib::RefPtr<Gnome::Glade::Xml> xml;
Gtk::RadioButton *rbs[2];
Gtk::Entry *keys[2];
Gtk::Entry *filename;
Gtk::Button *default_button;
Gtk::Button *browse;
Glib::ustring file_name;
void doit(void);
void on_button_clicked(int i);
void setup_commandline(void);
void setup_ops_group(void);
void setup_key_group(void);
void setup_file_selection(void);
void get_file(void);
};
and here is a snippet from the constructor of the class Fiscrypt:
Fiscrypt::Fiscrypt(void)
{
xml =
Gnome::Glade::Xml::create_from_buffer(fiscryptxml,strlen(fiscryptxml));
xml->get_widget("main window",window);
setup_commandline(); // initialize
the commandline buttons and container
setup_ops_group();
setup_key_group();
setup_file_selection();
}
here is code getting widget pointers in Fiscryp::setup_ops_group:
void Fiscrypt::setup_ops_group(void)
{
xml->get_widget("encrypt",rbs[0]);
xml->get_widget("decrypt",rbs[1]);
rbs[0]->set_active(TRUE);
}
Lastly, my main function:
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
// Fiscrypt window;
Fiscrypt fc;
Gtk::Main::run(*fc.window);
return 0;
}
Before using Glade, the setup_ops_group function was over 50 lines and
involved hand coding all the containers for the radio buttons and so
forth. Now, as can be seen, it's three lines.
I may still be doing this in a kludged sort of way, but it sure works
well for me.
Bob
begin:vcard
fn:Robert Caryl
n:Caryl;Robert
org:Fiscal Systems, Inc.
adr:;;102 Commerce Circle;Madison;AL;35758;USA
email;internet:bob fis-cal com
title:Senior Software Design Engineer
tel;work:356-772-8920 X108
x-mozilla-html:TRUE
url:http://www.fis-cal.com
version:2.1
end:vcard
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]