hwtk::menu - Create and manipulate menu widgets
The menu command creates a new top-level window (given by the pathName argument) and makes it into a menu widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the menu such as its colors and font. The menu command returns its pathName argument. At the time this command is invoked, there must not exist a window named pathName, but pathName’s parent must exist.
A menu is a widget that displays a collection of one-line entries arranged in one or more columns. There exist several different types of entries, each with different properties. Entries of different types may be combined in a single menu. Menu entries are not the same as entry widgets. In fact, menu entries are not even distinct widgets; the entire menu is one widget.
hwtk::menu - pathName ?option value? ...
-clientdata, clientData, ClientData
Command-Line Name: -configcommand
Database Name: configCommand
Database Class: ConfigCommand
Callback script will be executed just before populating the menu. menuitem properties can be configured here such as -state, -visible
Command-Line Name: -gridlayout
Database Name: gridlayout
Database Class: Layout
Specifies whether or not the menu should be displayed as a grid, containing images only. Acceptable values are 1 (menu will be displayed as a grid) and 0 (menu will be displayed as a list). The default value is 0.
Command-Line Name: -tearoff
Database Name: tearOff
Database Class: TearOff
This option must have a proper boolean value, which specifies whether or not the menu should include a tear-off entry at the top. If so, it will exist as entry 0 of the menu and the other entries will number starting at 1. The default menu bindings arrange for the menu to be torn off when the tear-off entry is invoked.
Command-Line Name: -type
Database Name: type
Database Class: Type
Specifies the type of menu item. Acceptable values are command, radiobutton, and checkbutton.
In addition to the standard configure, cget, identify, instate, and state commands, menu support the following additional widget commands:
pathName activate index
Change the state of the entry indicated by index to active and redisplay it using its active colors. Any previously-active entry is deactivated. If index is specified as none, or if the specified entry is disabled, then the menu ends up with no active entry. Returns an empty string.
pathName clear
Clears the menu.
pathName entrycget index option
Note: This is internal command. instead use itemcget command.
pathName index index
Returns the numerical index corresponding to index, or none if index was specified as none.
pathName invoke index
Invoke the action of the menu entry. See the sections on the individual entries above for details on what happens. If the menu entry is disabled then nothing happens. If the entry has a command associated with it then the result of that command is returned as the result of the invoke widget command. Otherwise the result is an empty string. Note: invoking a menu entry does not automatically unpost the menu; the default bindings normally take care of this before invoking the invoke widget command.
pathName item name ?arg arg ...?
Creates a menu item
pathName itemconfigure tag ?arg arg ...?
Same as configure command. Items can be configured. Supports only -state option of an item.
pathName itemcget tag option
Returns the current value of a configuration option for the entry given by index. Option may have any of the values accepted by the item widget command.
pathName itemdelete ?arg arg ...?
Deletes one or more items from the menu.
pathName itemexists tag
Returns a value specifying whether or not the given item exists in the menu; returns 1 if the item exists, or 0 if it does not.
pathName itemlist
Returns a list of the items contained in the menu.
pathName items ?arg arg ...?
Returns the list of all item tag names
pathName post X Y
Arrange for the menu to be displayed on the screen at the root-window coordinates given by x and y. These coordinates are adjusted if necessary to guarantee that the entire menu is visible on the screen. This command normally returns an empty string. If the postCommand option has been specified, then its value is executed as a Tcl script before posting the menu and the result of that script is returned as the result of the post widget command. If an error returns while executing the command, then the error is returned without posting the menu.
pathName postcascade index
Note: This is internal command.
pathName unpost
Unmap the window so that it is no longer displayed. If a lower-level cascaded menu is posted, unpost that menu. Returns an empty string. This subcommand does not work on Windows and Mac OS X, as those platforms have their own way of unposting menus.
Note: -configcommand callback script will be executed just before populating the menu. menuitems properties can be configured here such as -state
# hwtk::menu
hwtk::dialog .dlg
set w [.dlg recess]
pack [hwtk::entry $w.ent]
proc ConfigMenu {W} {
foreach item [$W items] {
switch -- $item {
abaqus {
$W itemconfigure abaqus -state disabled
}
}
}
}
hwtk::menu .menu -configcommand "ConfigMenu %W"
.menu item new -caption "New" -command "puts New" -accelerator "Ctrl + N"
.menu item open -caption "Open" -command "puts Open" -accelerator "Ctrl + O"
.menu item save -caption "Save" -command "puts Save" -accelerator "Ctrl + S" -image fileSaveModel-16.png
.menu item saveas -caption "Save As" -command "puts SaveAs" -accelerator "Ctrl + A"
.menu item separator
.menu item import -caption "Import"
.menu item model -caption "Model" -command "puts Model" -parent import -accelerator "Alt + I"
.menu item solver -caption "Solver Deck" -parent import -command "puts /"Solver Deck/""
.menu item abaqus -caption "Abaqus Deck" -parent solver -command "puts /"Abaqus Deck/""
.menu item permas -caption "Permas Deck" -parent solver -command "puts /"Permas Deck/""
.menu item separator -parent solver
.menu item radioss -caption "Radioss Deck" -parent solver -command "puts /"Radioss Deck/""
.menu item connectors -parent import -caption "Connectors" -command "puts /"Connectors/"" -image fileImportModel-16.png
.menu item exit -caption "Exit" -command "puts Exit" -accelerator "Alt + F4" -image closeReverse-16.png
bind $w.ent <ButtonRelease-3> [list .menu post %X %Y]
.dlg post