I have recently started to make heavy use of gob2 (
http://www.5z.com/jirka/gob.html) for my gtk programming, and I'm finding it
so much cleaner than any other approach that I have tried till now. I hope
to put to together a tutorial about it in the near future.
Here are a list of advantages of using gob2:
* Everything is turned into GtkWidget's. The overhead of extending an
existing widget is so small so there is no reason not to do it. gob2 is
doing all the dirty work for you!
* Creating a new signal is almost as simple as writing "signal" in front
of a the method name.
* Clean separation of public and private data through the _priv pointer.
* You develop classes in a single .gob file and there is no need to
manually handle the c-file, the public h-file, and the private-h file. gob2
creates these for you.
Here is e.g. how you would create your own dialog. See the gob2
documentation for more explanations.
%headertop{
#include <stdlib.h>
#include <gtk/gtk.h>
%}
class My:Button:Editor from Gtk:Dialog
{
private GtkWidget *button;
private GtkWidget *entry;
/* Here's the constructor */
public GtkWidget *
new (GtkWidget *button) {
MyButtonEditor *self = MY_BUTTON_EDITOR(GET_NEW);
selfp->button = button;
selfp->entry = gtk_entry_new();
// Create and pack some widgets
gtk_box_pack_start(GTK_DIALOG(self)->vbox, selfp->entry, TRUE, TRUE,
0);
// Add dialog buttons
gtk_dialog_add_buttons(GTK_DIALOG(self),
GTK_STOCK_CLOSE,
GTK_RESPONSE_CLOSE,
GTK_STOCK_EDIT,
RESPONSE_EDIT,
NULL
);
return GTK_WIDGET(self);
}
/* Handle the response signal */
override (Gtk:Dialog)
void
response (Gtk:Dialog *dialog (check null type),
gint response_id)
{
MyButtonEditor *self = MY_BUTTON_EDITOR(dialog);
gchar *user_text = gtk_entry_get_text(GTK_ENTRY(selfp->entry));
// Do something with the text
}
}
Regards,
Dov
_______________________________________________
gtk-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-list