Newbe Programming Question



I have recently started looking at programs in GTK and Gnome.
In light of this I purchased Gnome/GTK+ Programming Bible by Arthur
Griffith.
This is a book of short very useful caned programs that are very useful
as program starters. 
I have compiled and ran almost all the demo programs in this book.
Almost because there are several that I can not compile.
My next steep is to began combining these simple programs into more
useful to me basic programs. The two programs I have chosen to combine
are a gnome program - gnomebase - which creats a gnome window with an
exit and help menue and a GTK program - hpaned - which splits the window
in two vertically.

Both programs run before combining without error. After combining all
functions are located in the origional order and all statements from
both programs with duplicates being removed. Also all statments are
typed correctly. 

If the follow statement is included in the main file:
    window = gnome_app_new("gnomebase","Gnome Base");
The program compiles and the gonome base window is created with out
showing the split window and the words left and right. Also the command
line generates the following error message:
    GnomeUI-DRITICAL **: file gnome_app_helper.c line 1370
(gnome_app_create_menus): assertion `GNOME_IS_APP(app)' failed

If the follow statement is included in the main file:
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
The program compiles, the GTK window is shown which does not include thw
exit and help menue. Also the command line generates the following error
message:
    Gtk-CRITICAL **: file gtkbin.c line 217 (gtk_bin_add): assertion
`bin->child == NULL" failed.

Now I can understand that if you use window = gtk_window_new that you
would have problems with showing a gnome widget in a GTK window but I
can not understand why you can not show the GTK widget a gonome program.

I would appreciate any help some of the more enligjtened of you would
give with this problem.

The complete text of the program as currently being compiles and ran is
attached for your review.

Thanks
Frank Roberts







-- 
Frank Roberts
/** test-gnomebase00.c **/
#include <gnome.h>

static void shutdown();
static void helpContents();
static void helpAbout(GtkWidget *,gpointer);
gint eventDelete(GtkWidget *widget,
        GdkEvent *event,gpointer data);
gint eventDestroy(GtkWidget *widget,
        GdkEvent *event,gpointer data);

GnomeUIInfo fileMenu[] = {
    {   GNOME_APP_UI_ITEM,
        "Exit","Close all files and exit",
        shutdown,NULL,NULL,
        GNOME_APP_PIXMAP_NONE,NULL,
        0,0,NULL
    },
    GNOMEUIINFO_END
};

GnomeUIInfo helpMenu[] = {
    {   GNOME_APP_UI_ITEM,
        "Contents","Display help contents",
        helpContents,NULL,NULL,
        GNOME_APP_PIXMAP_NONE,NULL,
        0,0,NULL
    },
    GNOMEUIINFO_ITEM_STOCK("About...",NULL,
		helpAbout,GNOME_STOCK_MENU_ABOUT),
    GNOMEUIINFO_END
};

GnomeUIInfo mainMenu[] = {
    GNOMEUIINFO_SUBTREE("File",fileMenu),
    GNOMEUIINFO_SUBTREE("Help",helpMenu),
    GNOMEUIINFO_END
};

int main(int argc,char *argv[])
{
    GtkWidget *window;

    gnome_init("gnomebase","1.0",argc,argv);
    window = gnome_app_new("gnomebase","Gnome Base");
    gtk_widget_show(window);
    gnome_app_create_menus(GNOME_APP(window),mainMenu);

    gtk_signal_connect(GTK_OBJECT(window),
            "delete_event",
            GTK_SIGNAL_FUNC(eventDelete),
            NULL);
    gtk_signal_connect(GTK_OBJECT(window),
            "destroy",
            GTK_SIGNAL_FUNC(eventDestroy),
            NULL);

    gtk_main();
    exit(0);
}
static void helpAbout(GtkWidget *widget,gpointer data)
{
	GtkWidget *aboutBox;

	const gchar *writtenBy[] = {
		"Arthur Griffith",
		"Lance Peterson",
		NULL
	};

	aboutBox = gnome_about_new("Gnome Base","0.0",
			"(C) 1999 the Free Software Foundation",
			writtenBy,
			"This program serves no purpose other than "
			"its source code can be used as a starting "
			"point to create a Gnome application.",
			NULL);
	gtk_widget_show(aboutBox);
}
void helpContents() 
{
    g_print("Show the help contents window\n");
}

gint eventDelete(GtkWidget *widget,GdkEvent *event,gpointer data) 
{
    return(FALSE);
}

gint eventDestroy(GtkWidget *widget,GdkEvent *event,gpointer data) 
{
    shutdown();
    return(0);
}

void shutdown() {
    gtk_main_quit();
}
/** test-hpaned00.c - I / test-gonomebase00.c - II **/ 
/* The comments I-x refer to the original program test-hpaned00.c.*/
/* The comments II-x refer to the original program test-gonomebase00.c.*/
/*Both of thse programs compile and run with out generating errors.*/

#include <gnome.h>

/* II-1 */
static void shutdown();
static void helpContents();
static void helpAbout(GtkWidget *,gpointer);

/* I-1 *//* II-2 */
GtkWidget *makeHorizontalPane();
gint eventDelete(GtkWidget *widget,
        GdkEvent *event,gpointer data);
gint eventDestroy(GtkWidget *widget,
        GdkEvent *event,gpointer data);

/* II-3 */
GnomeUIInfo fileMenu[] = {
    {   GNOME_APP_UI_ITEM,
        "Exit","Close all files and exit",
        shutdown,NULL,NULL,
        GNOME_APP_PIXMAP_NONE,NULL,
        0,0,NULL
    },
    GNOMEUIINFO_END
};

GnomeUIInfo helpMenu[] = {
    {   GNOME_APP_UI_ITEM,
        "Contents","Display help contents",
        helpContents,NULL,NULL,
        GNOME_APP_PIXMAP_NONE,NULL,
        0,0,NULL
    },
    GNOMEUIINFO_ITEM_STOCK("About...",NULL,
		helpAbout,GNOME_STOCK_MENU_ABOUT),
    GNOMEUIINFO_END
};

GnomeUIInfo mainMenu[] = {
    GNOMEUIINFO_SUBTREE("File",fileMenu),
    GNOMEUIINFO_SUBTREE("Help",helpMenu),
    GNOMEUIINFO_END
};

/* I-2 *//* II-4 */
int main(int argc,char *argv[])
{
    GtkWidget *window;
    GtkWidget *pane;

    gnome_init("gonomebase","1.0",argc,argv);

//
/* I-2 */
/*    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);*/
/*  If the above line is included the follow line is not included */
/*  the above line is included the following error message is generated:*/
/*  Gnome UI_CRITICAL **: file gonome-app-helper.c: line 1370*/
/*  (gnome-app-create-menus): assertion `GNOME_IS_APP (app)' failed */

/* II-4 */
/*    window = gnome_app_new("gnomebase","Gnome Base");*/
/*  If the above line is included the previous line is not included */
/*  the above line is included the following error message is generated:*/
/*  Gtk_CRITICAL **: file gtkbin.c line 217 */
/*  (gtk-bin-add): assertion `bin->child == NULL" failed */
//

    window = gnome_app_new("gnomebase","Gnome Base");

/* II-4 */
/*    gtk_widget_show(window);*/
/* II-4 */
    gnome_app_create_menus(GNOME_APP(window),mainMenu);

    gtk_signal_connect(GTK_OBJECT(window),
            "delete_event",
            GTK_SIGNAL_FUNC(eventDelete),
            NULL);
    gtk_signal_connect(GTK_OBJECT(window),
            "destroy",
            GTK_SIGNAL_FUNC(eventDestroy),
            NULL);

    pane = makeHorizontalPane();

    gtk_container_add(GTK_CONTAINER(window),pane);
/* I-2 */
    gtk_widget_show(window);
    gtk_main();
    exit(0);
}

/* I-3 */
GtkWidget *makeHorizontalPane() {
  
    GtkWidget *leftText;
    GtkWidget *rightText;
    GtkWidget *paned;

    leftText = gtk_text_new(NULL,NULL);
    gtk_widget_show(leftText);
    rightText = gtk_text_new(NULL,NULL);
    gtk_widget_show(rightText);
  
        gtk_text_insert(GTK_TEXT(leftText),NULL,NULL,NULL,
          "   Left    ",
          -1);
        gtk_text_insert(GTK_TEXT(rightText),NULL,NULL,NULL,
          "   Right   ",
          -1);
  

    paned = gtk_hpaned_new();
    gtk_widget_show(paned);
    gtk_paned_add1(GTK_PANED(paned),leftText);
    gtk_paned_add2(GTK_PANED(paned),rightText);

    return(paned);
}

/* II-5 */
static void helpAbout(GtkWidget *widget,gpointer data)
{
	GtkWidget *aboutBox;

	const gchar *writtenBy[] = {
		"Arthur Griffith",
		"Lance Peterson",
		NULL
	};

	aboutBox = gnome_about_new("Gnome Base","0.0",
			"(C) 1999 the Free Software Foundation",
			writtenBy,
			"This program serves no purpose other than "
			"its source code can be used as a starting "
			"point to create a Gnome application.",
			NULL);
	gtk_widget_show(aboutBox);
}

/* II-6 */
void helpContents() 
{
    g_print("Show the help contents window\n");
}

/* II-7 */
gint eventDelete(GtkWidget *widget,GdkEvent *event,gpointer data) 
{
    return(FALSE);
}

/* II-8 */
gint eventDestroy(GtkWidget *widget,GdkEvent *event,gpointer data) 
{
    shutdown();
    return(0);
}

/* II-9 */
void shutdown() {
    gtk_main_quit();
}



/** test-hpaned01.c **/ 

#include <gnome.h>

GtkWidget *makeHorizontalPane();
gint eventDelete(GtkWidget *widget,
        GdkEvent *event,gpointer data);
gint eventDestroy(GtkWidget *widget,
        GdkEvent *event,gpointer data);

int main(int argc,char *argv[])
{
    GtkWidget *window;
    GtkWidget *pane;

    gnome_init("gonomebase","1.0",argc,argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);


    gtk_signal_connect(GTK_OBJECT(window),
            "delete_event",
            GTK_SIGNAL_FUNC(eventDelete),
            NULL);
    gtk_signal_connect(GTK_OBJECT(window),
            "destroy",
            GTK_SIGNAL_FUNC(eventDestroy),
            NULL);

    pane = makeHorizontalPane();

    gtk_container_add(GTK_CONTAINER(window),pane);
    gtk_widget_show(window);
    gtk_main();
    exit(0);
}
GtkWidget *makeHorizontalPane() {
  
    GtkWidget *leftText;
    GtkWidget *rightText;
    GtkWidget *paned;

    leftText = gtk_text_new(NULL,NULL);
    gtk_widget_show(leftText);
    rightText = gtk_text_new(NULL,NULL);
    gtk_widget_show(rightText);
  
        gtk_text_insert(GTK_TEXT(leftText),NULL,NULL,NULL,
          "   Left    ",
          -1);
        gtk_text_insert(GTK_TEXT(rightText),NULL,NULL,NULL,
          "   Right   ",
          -1);
  

    paned = gtk_hpaned_new();
    gtk_widget_show(paned);
    gtk_paned_add1(GTK_PANED(paned),leftText);
    gtk_paned_add2(GTK_PANED(paned),rightText);

    return(paned);
}
gint eventDelete(GtkWidget *widget,
        GdkEvent *event,gpointer data) {
    return(FALSE);
}
gint eventDestroy(GtkWidget *widget,
        GdkEvent *event,gpointer data) {
    gtk_main_quit();
    return(0);
}


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