Re: Toy menu program (GtkItemFactory) *gives no errors* but menu doesn't appear!? How debug?
- From: "Nils O." Selåsdal <noselasd frisurf no>
- To: Christian Seberino <seberino spawar navy mil>
- Cc: gtk-list gnome org
- Subject: Re: Toy menu program (GtkItemFactory) *gives no errors* but menu doesn't appear!? How debug?
- Date: 22 Jun 2002 00:04:44 +0200
On Fri, 2002-06-21 at 23:11, Christian Seberino wrote:
> This toy program give no errors when I compile.
> It should display a GtkItemFactory menu but
> it does not!!
>
> How can I debug this if no error messages???
>
> Chris
>
>
> #include <gtk/gtk.h>
>
> static void printHelloWorld(GtkWidget *w, gpointer data) {
> g_message("HelloWorld!\n");
> };
>
> static GtkItemFactoryEntry theMenu[] = {
> {"/_File", NULL, NULL, 0, "<Branch>"},
> {"/File/_New", NULL, printHelloWorld, 0, "<Item>"},
> {"/File/<Separator>", NULL, NULL, 0, "<Separator>"},
> {"/File/_Quit", NULL, gtk_main_quit, 0, "<Item>"},
> {"/_Help", NULL, NULL, 0, "<LastBranch>"},
> {"/Help/_See Docs", NULL, NULL, 0, "<Item>"},
> {"/Help/_About", NULL, NULL, 0, "<Item>"},
> };
>
> int main(int argc, char** argv) {
> GtkWidget* window;
> GtkItemFactory* item_factory;
> GtkAccelGroup* accel;
>
> gtk_init(&argc, &argv);
>
> /* Basic window creation stuff here. */
> window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> gtk_window_set_title(GTK_WINDOW(window), "Window Title Here");
> gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
>
> /* Here is menu stuff. */
> accel = gtk_accel_group_new();
> item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel);
> gtk_item_factory_create_items(item_factory, sizeof(theMenu) / sizeof(theMenu[0]), theMenu, NULL);
> gtk_accel_group_attach(accel, GTK_OBJECT(window));
> gtk_container_add(GTK_CONTAINER(window), gtk_item_factory_get_widget(item_factory, "<main>"));
>
> /* Basic ending stuff here. */
> gtk_widget_show(window);
> gtk_main();
> return 0;
> }
You forgot to show the menubar.
Either do gtk_widget_show_all(window);
or
GtkWidget *bar;
..
bar = gtk_item_factory_get_widget(item_factory, "<main>"));
gtk_container_add(GTK_CONTAINER(window),bar);
gtk_widget_show(bar);
>
--
Nils Olav Selåsdal <NOS Utel no>
System Developer, UtelSystems a/s
w w w . u t e l s y s t e m s . c o m
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]