Hi,

Indeed, this way things seems to work. Only I do not use the ItemFactory, since I have an action-like implementation in Python (changing sensitivity and stuff).

The odd thing is that default stock icons (such as 'gtk-new') have an accelerator, but stock items created by me do not. Although they have a key binding associated with them when added with gtk.stock_add.

The key binding shows up when doing a gtk.stock_lookup(), but they do not appear when a menu item is created with gtk.ImageMenuItem with the statement

item = gtk.ImageMenuItem(action.stock_id, accel_group)

where action.stock_id is a stock item id such as 'gaphor-class' and the accel_group is an gtk.AccelGroup, which has been added to a gtk.Window.

What am I missing?

Thanks in advance,

Arjan

Nickolay V. Shmyrev wrote:
All works fine for me. Here is the example.

#include <gtk/gtk.h>

static void
register_stock_icons (void)
{
static gboolean registered = FALSE;
if (!registered)
{
GdkPixbuf *pixbuf;
GtkIconFactory *factory;
GtkIconSet *icon_set;



static GtkStockItem items[] = {
{ "demo-gtk-logo",
"GTK!",
GDK_CONTROL_MASK, 'g', NULL }
};
registered = TRUE;


gtk_stock_add (items, G_N_ELEMENTS (items));
factory = gtk_icon_factory_new ();


      gtk_icon_factory_add_default (factory);

      pixbuf = gdk_pixbuf_new_from_file ("gtk-logo-rgb.gif", NULL);

      icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);

      gtk_icon_factory_add (factory, "demo-gtk-logo", icon_set);

      gtk_icon_set_unref (icon_set);
      g_object_unref (pixbuf);
      g_object_unref (factory);
    }
}

void clicked_cb (GtkWidget *widget, gpointer data)
{
  g_message ("Activated");
}


static GtkItemFactoryEntry menu_items[] = { { "/_File", NULL, NULL, 0, "<Branch>" }, { "/File/_Gtk", NULL, clicked_cb, 0, "<StockItem>", "demo- gtk-logo"}, };

/* Returns a menubar widget made from the above menu */
GtkWidget *get_menubar_menu( GtkWidget  *window)
{
  GtkItemFactory *item_factory;
  GtkAccelGroup *accel_group;

  accel_group = gtk_accel_group_new ();

  item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
                                       accel_group);

  gtk_item_factory_create_items (item_factory, 2, menu_items, NULL);

  gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);

  return gtk_item_factory_get_widget (item_factory, "<main>");
}


main (int argc, char ** argv) {
GtkWidget *window;
GtkWidget *menu;
GtkStockItem stock_item;
gtk_init(&argc, &argv);
register_stock_icons();
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
menu = get_menubar_menu (window);
gtk_container_add (GTK_CONTAINER(window), menu);
gtk_widget_show_all (window);
gtk_main();
}


_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to