Re: Getting type/arg info without running a GUI?

On Wed, Sep 13, 2000 at 08:57:45AM -0700, John Margaglione wrote:
> Still no luck.  Here is the test program I am trying
> to run, if it helps:

You're not doing the _get_type which will init the type.  If you want to be
able to query arbitrary widgets which just may have been linked with the app,
you can use this function I use in pong.  It uses a gob style type name (so
"Gtk:Window") to be able to find the type.  It will use gmodule if it can't
get the typename from gtk itself.  If you only plan to query certain set of
types, this is UGLY, in fact this is the ugliest hack in pong.  (well I did
modify this to take out pong specific bits, and it maybe doesn't compile)

#include <gmodule.h>

static GModule *allsymbols = NULL;

static char *
replace_sep (const char *base, char r)
	char *p;
	char *s = g_strdup (base);
	while ((p = strchr (s, ':')) != NULL)
		*p = r;
	if (*s == r) {
		p = g_strdup (s+1);
		g_free (s);
		return p;
	return s;

static GtkType
type_from_string(const char *string)
	char *typestring;
	char *initfunc;
	guint (*get_type)(void);
	GtkType gtk_type;

	typestring = remove_sep(string);

	gtk_type = gtk_type_from_name(typestring);


	if(gtk_type == 0) {
		if( ! g_module_supported()) {
			g_warning(_("GModule is not supported and a widget "
				    "of type '%s' has not yet been "
			return 0;
		typestring = replace_sep(string, '_');
		initfunc = g_strconcat(typestring, "_get_type", NULL);

		if( ! allsymbols)
			allsymbols = g_module_open(NULL, 0);

		if( ! g_module_symbol(allsymbols, initfunc,
				      (gpointer *)&get_type)) {
			g_warning(_("Unknown widget %s found"), string);
			return 0;

		g_assert(get_type != NULL);

		gtk_type = get_type();

	if(gtk_type == 0) {
		g_warning(_("Unknown widget '%s' found"), string);
		return 0;

	return gtk_type;


George <jirka 5z com>
   There is nothing so useless as doing efficiently that
   which should not be done at all.
                       -- Peter Drucker

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]