Re: Toy menu program (GtkItemFactory) *gives no errors* but menu doesn't appear!? How debug?



Nils

Thanks! I'm so glad you sent this reply!
I changed gtk_widget_show to gtk_widget_show_all
like you said and now my menus appear!!!

Do you know why the menubar would take over
the whole window? The 2 menu items "File" and "Help"
are huge.  It looks like one must specify size
of menu bar somewhere. :(

(I saw one example program that defined a vbox
and one that avoided that..... perhaps one needs
a vbox or something like that?! errrr. :)

Thanks again,

Chris

P.S. Here is code with your suggested change...

#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_all(window);
  gtk_main();
  return 0;
};


On Sat, Jun 22, 2002 at 12:04:44AM +0200, Nils O. Sel?sdal wrote:
> 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
> 
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list

-- 
_______________________________________

Dr. Christian Seberino
SPAWAR Systems Center San Diego
Code 2363
53560 Hull Street
San Diego, CA 92152-5001
U.S.A.

Phone: (619) 553-7940
Fax:   (619) 553-2836
Email: seberino spawar navy mil
_______________________________________



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