[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [gtk-list] Widget factory
- From: Y2K <y2k y2ker com>
- To: gtk-app-devel-list redhat com
- Subject: Re: [gtk-list] Widget factory
- Date: Thu, 3 Feb 2000 13:55:33 -0800 (PST)
On Thu, 3 Feb 2000, Jeroen Benckhuijsen wrote:
> I don't know if were talking about the same thing here, but i was
> looking through the Gtk tutorials, the section about creating your own
> widgets. I saw that a great deal of the code needed there is always the
> same. So i thought maybe it would be nice to create a program which
> could generate the code for me. This would save me a great deal of
> writing. Stuff like autogenerating code when adding signals ,etc.
A very rough perl script --
Some things like hbox's and vbox's need tweaking afterwords
Feel Free to use as desired...
#! /usr/bin/perl -w
#
# subwidgetize.pl
#
# Author: SJP <y2k@y2ker.com>
#
#
# Description: this script creates custome widgets for gui framework
#
sub smakker
{
my ($oword,$nword) = @_;
$oword =~ /([a-z]+)_(\w+)/;
return ucfirst($1) . ucfirst($2);
}
if ( $#ARGV != 1) {
print "Usage: subwidgetize gtk_foo cw_bar\n";
print "Usage: $0 gtk_foo cw_bar\n";
exit();
}
$parent = $ARGV[0];
$child = $ARGV[1];
$PARENT = $ARGV[0];
$CHILD = $ARGV[1];
$PARENT =~ tr/a-z/A-Z/;
$CHILD =~ tr/a-z/A-Z/;
$par = smakker($parent);
$parf = $parent;
$parf =~ s/([a-z]+)_(\w+)/$1$2/;
$chdf = $child;
$chdf =~ s/([a-z]+)_(\w+)/$1$2/;
$chd = smakker($child);
print "Making $child from $parent\n";
-d "autogen" || mkdir( "autogen", 0775);
chdir "autogen";
open(H, ">$child.h");
print H <<HERE ;
/*
-= ${child}.h =-
Authors:
Website: http://
DESCRIPTION: custom widget ${child} header file
*/
#ifndef _H_${CHILD}_H_
#define _H_${CHILD}_H_
#include <gtk/gtk.h>
#include <gtk/${parf}.h>
#ifdef __cplusplus
extern "c" {
#endif
#define GTK_TYPE_${CHILD} ( ${child}_get_type() )
#define ${CHILD}(obj) (GTK_CHECK_CAST ((obj),GTK_TYPE_$CHILD, ${chd}))
#define ${CHILD}_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), \\
GTK_TYPE_${CHILD}, \\
${chd}Class))
#define GTK_IS_${CHILD}(obj) GTK_CHECK_TYPE ((obj),GTK_TYPE_${CHILD})
#define GTK_IS_${CHILD}_CLASS(klass) GTK_CHECK_CLASS_TYPE ((klass),GTK_TYPE_${CHILD} )
typedef struct _${chd} ${chd};
typedef struct _${chd}Class ${chd}Class ;
struct _${chd}
{
${par} _par;
};
struct _${chd}Class
{
${par}Class parent_class;
};
GtkType ${child}_get_type(void);
GtkWidget* ${child}_new(void);
#ifdef __cplusplus
}
#endif
#endif
HERE
close(H);
open(C, ">$child.c");
print C <<HERE ;
/*
-= ${child}.c =-
Authors:
Website: http://
DESCRIPTION: ${child} is a custom widget for
*/
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gtk/${parf}.h>
#include <config.h>
#include "${child}.h"
static void
${chd}_init(${chd} *me)
{
}
GtkType
${child}_get_type(void)
{
static GtkType p_t = 0;
if (!p_t)
{
GtkTypeInfo p_i = {
"${chd}" ,
sizeof(${chd}),
sizeof(${chd}Class),
/* (GtkClassInitFunc)${chd}_class_init, */
(GtkClassInitFunc) NULL,
(GtkObjectInitFunc)${chd}_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL,
};
p_t = gtk_type_unique(${parent}_get_type(),&p_i);
}
return p_t;
}
GtkWidget*
${child}_new(void)
{
return GTK_WIDGET(gtk_type_new(${child}_get_type()));
}
HERE
close(C);
exit();
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]