Re: How do you develop you GTK code?
- From: "Dov Grobgeld" <dov grobgeld gmail com>
- To: "Diogo Ramos" <diogofsr gmail com>
- Cc: gtk-list gnome org
- Subject: Re: How do you develop you GTK code?
- Date: Sun, 15 Apr 2007 22:31:53 +0300
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]