[Haskell-cafe] Help with Menu item handlers in gtk2hs with glade

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Sun Feb 15 08:02:32 EST 2009

On Sun, 2009-02-15 at 16:48 +0530, Lakshmi Narasimhan wrote:
> I designed a basic GUI with Menu bar and menu items in glade. I use the 
> glade bindings in haskell to get the menu item using xmlGetWidget and 
> castToMenuItem function. I set a *onActivateItem* handler for this 
> menuitem. However this is not working.

You're not the only one confused, I've never really understood the
profusion of actions on Gtk+ menu items, but onActivateLeaf seems to be
the one to use.

> I saw the glade file and it has a signal function in the xml. I tried
> to use the same function name, but it doesn't work either.

Ignore that, it only works for C code.

> Any suggestions on what I might be doing wrong here and how to get
> menu item handlers working.

There are three places to look at for help, the demos, the API
documentation and the gtk2hs-users mailing list.

The demos:

Take a look at the menu demo that comes with gtk2hs (in the gtk2hs
tarball under demo/menu/MenuDemo.hs). You'll notice it uses
onActivateLeaf rather than onActivateItem.

The API docs:


(linked from http://haskell.org/gtk2hs/documentation/)


        onActivateItem :: MenuItemClass self => self -> IO () -> IO (ConnectId self)
        Emitted when the user chooses a menu item that has a submenu.
        This signal is not emitted if the menu item does not have a

        onActivateLeaf :: MenuItemClass self => self -> IO () -> IO (ConnectId self)
        The user has chosen the menu item.
        This is the only function applications normally connect to. It
        is not emitted if the item has a submenu.

The mailing list:



More information about the Haskell-Cafe mailing list