Tycho provides a set of classes that are added to top-level windows to perform certain well-defined functions. There are currently three of these "decorator" classes.
("Decorator" is perhaps a poor name for this set of classes since the meaning is very different from the Decorator object-oriented design pattern.)
The MenuBar class is a complete application menu bar. (MenuBar
is a subclass of the abstract class MenuSupport, which implements
most of the menu functionality.) The Displayer
top-level window contains a MenuBar object for each View
packed into it. Views are responsible for maintaining their own
menu bars: they each have a method called menubar
which
directs commands to its menu bar; each view subclass adds
appropriate entries to the menubar.
To illustrate the workings of the menu bar, we will just create a
menu bar and pack it into a top-level window. To understand the
Displayer-View machinery, see the documentation for the Displayer and View classes. Create a top-level
window and and an empty menubar:
set f [::tycho::autoName .dechtml]
::tycho::TopLevel $f
::tycho::MenuBar $f.mb
pack $f.mb -fill x -expand on
$f centerOnScreen
$f.mb addMenu file -label File
$f.mb addMenu help -label Help -side right -underline 0
Help
menu is packed to the right of the menu bar.
The -underline
option places an underline under the
indicated letter of the label and enables keyboard navigation through
menus.
The menu bar accesses all menus and menu entries by tag -- that
is, by the first argument you gave when you created the menu.
To add
entries to a menu, call add
with the entry label, the
name of the menu to place the entry into, and additional options. For
example, we'll add a Close
menu choice to the File
menu and a Tycho Home Page entry to the Help
menu:
$f.mb add command close file -label Close -command {delete object $f}
$f.mb add command home help -label {Tycho Home Page} \
-command {::tycho::File::openContext \
$TYCHO/doc/index.html} \
-underline 0 -accelerator "C-x h"
File
and Help
menu buttons to
bring down the menus.) Note that labels containing spaces must be
bracketed as a list, or the menu bar will get confused -- as in
{Tycho Home Page}
.
The add
command takes any options acceptable to the
entries of the Tk menu
widget. Three commonly-used
ones are illustrated above:
-command
is a script which is executed in the
global scope when the menu entry is invoked.
-underline
indicates the letter of the label to
underline and enables keyboard selection of that entry.
-accelerator
displays a string next to the menu,
which represents a key accelerator for the menu command. The menu
bar only displays this string: it does not actually bind the command
to the indicated key sequence. (This is an artifact of the way
that Tk works -- we are considering making the menu bar perform the
key bindings as well as displaying the accelerator string.)
You can add a separator to a menu:
$f.mb add separator sep1 help
$f.mb add command foo help -label Foo -command {::tycho::inform Foo!}
Individual menu entries can be disabled and enabled:
$f.mb disable home
Help
menu: the Tycho Home Page
entry is greyed out and cannot be invoked.) Whole menus can be
disabled in exactly the same way:
$f.mb disable file
enable
:
$f.mb enable home
$f.mb enable file
class
documentation.
The StatusBar is a bar designed to be placed along the bottom
of top-level windows. It contains a button to close the window,
an optional field indicating file status (writable, read-only, or
modified), and an area in which short but informative status messages
can be displayed. Usually, the status bar is accessed from a View
class, which has the method statusbar
to
direct commands to its status bar.
To illustrate the operation of the status bar, we will create one
and pack it into a top-level window with a empty frame to give the
window some size:
set fr [::tycho::autoName .dechtml]
::tycho::TopLevel $fr
frame $fr.f -width 300
pack $fr.f -fill x -expand on
::tycho::StatusBar $fr.sb -closecommand {delete object $fr}
pack $fr.sb -fill x -expand on
$fr centerOnScreen
-closecommand
option, which deletes the object
when the close button is pressed.
The status bar has a number of other options that control its appearance.
To add a file status display, set the -filestatus
to
readonly
, writable
, or modified
:
$fr.sb configure -filestatus readonly
$fr.sb configure -filestatus modified
$fr.sb configure -closetext Quit
$fr.sb configure -scrollbarpad 1
puts
prints a string to the status region:
$fr.sb puts "A brief but informative message"
$fr.sb puts ""
<Enter>
and <Leave>
events -- that way the status bar can be used
as a simple help mechanism.
For example, the toolbar can be set up so that
information about a button is printed in the status bar
when the mouse is moved over that button.
The ToolBar is a bar designed to be placed along the top of top-level windows. It contains a row of buttons that make commonly-used functions highly visible to the inexperienced user. It can also display entry widgets below the buttons -- these are typically used when the temporary nature of the StatusBar display is not sufficient, or when direct user input is desired without popping up a dialog box (or both!).
We will place the toolbar in an empty top-level window
to illustrate its operation. Usually, the toolbar will be
accessed through the toolbar
method of the View class.
We will use the same window as for the status bar -- if you have
closed it, go back and create another. Then:
::tycho::ToolBar $fr.tb -statusbar $fr.sb
pack $fr.tb -fill x -expand on -before $fr.f
$fr.tb button foo -description "The first button" \
-text "Push Me" \
-command {::tycho::post Thanks!}
$fr.tb button bar -description "The second button" \
-text "Push Me Too" \
-command {::tycho::post {Thanks again!}}
$fr.tb disable foo
$fr.tb enable foo
$fr.tb entry thing "Enter something here" "Start with" {::tycho::post}
get
:
$fr.tb get
$fr.tb disable thing
$fr.tb enable thing
MenuBar class documentation
MenuSupport class documentation
ToolBar class documentation
StatusBar class documentation
Tycho Home Page