next up previous contents
Next: 6.12.2 Workspaces Up: 6.12.1 Tools and toolkits Previous: 6.12.1.1 Static menu items   Contents

6.12.1.2 Dynamic menu items

Dynamic menus give you much more control over the way menus are drawn and make it easy to reuse menus. A dynamic menu item is a class instance that is a sub-class of Menuitem. It needs to have three members: label, the text that should appear in the menu (with an underscore character to indicate the mnenonic); tooltip, a short hint that appears as a tooltip or in the toolkit browser; icon, an optional image file to be displayed in the menu next to the text; and action, the function that is called when the menu item is activated. label and tooltip are constructor arguments for Menu.

So for example:

                                                      
  Wombat_find_item = class Menuitem
    "_Find Wombat"
    "analyse image and locate wombat" {
    icon = "nip-slider-16.png";
    action x = im_wombat_locate x;
  }

will appear as shown in Figure 6.2.

Figure 6.2: How Wombat_find_item will look
\includegraphics[width=2.5in]{figs/toolkit2.PS}

A dynamic pullright menu is a subclass of Menupullright. It's just like Menuitem, but without the need for an action member. Any members which are subclasses of Menu are displayed as items in the submenu. So again:

                                                      
  Wombat_item = class Menupullright
    "_Wombat"
    "wombat-related operations" {
    icon = "nip-slider-16.png";
    item1 = Wombat_find_item;
    boink = Wombat_find_item;
  }

will appear as shown in Figure 6.3.

Figure 6.3: How Wombat_item will look
\includegraphics[width=2.5in]{figs/toolkit3.PS}


next up previous contents
Next: 6.12.2 Workspaces Up: 6.12.1 Tools and toolkits Previous: 6.12.1.1 Static menu items   Contents
John Cupitt 2004-12-20