next up previous contents index
Next: Customizing the Hot Keys Up: Customizing the Popup Menu Previous: Customizing the Popup Menu

Customizing the popup menu

   

The popup menu in VMD has a number of default menu items and submenus, which cannot be changed. These are described in an earlier section. But you can add new submenus and items to this menu, and assign text commands to those items. When the items are selected by the user, the assigned text command will be executed as if it had been typed in at the console. In fact, with Tcl you can assign arbitrarily complex commands (such as scripts) to a single menu selection.

  To add a menu to the main pop-up menu, use:

where name is the name of the menu entry as it will appear in the Popup menu.

For example, lets suppose we want to make a menu of our most often used structures. Then the command to accomplish this is:

        user add menu Favorites

Since there isn't anything in the menu, it doesn't appear in the popup menu yet. To add items to the menu, use:

where command can either be a list of Tcl commands to execute or the name of a script that is to be processed when the menu item is chosen. For instance, we often load the structures ``alanin.pdb'' and ``brH.pdb'' and remotely download the 9pti structure from the PDB FTP site, so we'll add:
        user add subitem Favorites BPTI {mol pdbload 9pti}
        user add subitem Favorites alanin {mol load pdb alanin.pdb}
        user add subitem Favorites bR {mol load pdb brH.pdb}

Enter these three lines and then bring up the popup menu. You should see the new menu item just above the ``Help'' lines. Unless you also happen to have these molecules available, the last two items probably won't work, but the first one should. Try it out.

You can also add a separator in the menu, using:

So if you wanted a separation between the first three molecules and a fourth, say the poliovirus 2PLV structure, then you would type:
        user add subseparator Favorites
        user add subitem Favorites Polio {mol pdbload 2plv}

      As a second complete example, the code below will produce a cascading menu which allows you to quickly adjust the degree of transparency for transparenent objets (i.e. the default is .3, where 1.0 is opaque and 0.0 is invisible).

        # Set the alpha value of the "transparent" materials
        proc set_transparency_value {alpha} {
                display update off
                # change the opaquicity of the transparent colors
                for {set color 17} {$color < 34} {incr color} {
                        color change alpha $color $alpha
                }
                # and the transparent color scale (66 to 97)
                for {set color 66} {$color < 98} {incr color} {
                        color change alpha $color $alpha
                }
                display update on
        }
        user add menu Transparency
        for {set i 1.0} {$i >= 0.0} {set i [expr $i - 0.1]} {
                eval "user add subitem Transparency $i {
                        set_transparency_value $i}"
        }

Unfortunately, the user modifiable popup menus are not hierarchical. There is no way to add a submenu to one of your own menus. They can only be added to the main popup menu. However, there is another place to add new menu items, the `User Commands' submenu of the main menu. ``Where is it?'' you ask? It doesn't contain anything, so it isn't displayed. You can add items to it just as you can to the main menu, but the commands are slightly different. Admittedly this is not an optimal solution. Future versions of VMD will use Tk menus to alleviate this problem. Until then though, here is a specification of the syntax.

To add an item to the `User Commands' menu:

To add a separator to the 'User Commands' menu:

The usage is the same as their related commands, so we won't give a detailed example, but to see how it works, try this:

        # Turn off the axis
        user add item {Axes Off} axes location off
        user add item {Axes On} axes location LowerLeft 
        # a break
        user add separator
        # delete all the loaded molecule
        user add item {Zap Everything} {
                foreach molecule [molinfo list] {
                        mol delete $molecule
                }
        }

Finally, if you wish to see the current definitions of the user-customized menu items, use the command

This will print out to the console the names and associated text commands for all menu items added by the user.


next up previous contents index
Next: Customizing the Hot Keys Up: Customizing the Popup Menu Previous: Customizing the Popup Menu

Justin Gullingsrud
Tue Apr 6 09:22:39 CDT 1999