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 choice 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
$f.mb addMenu Help -side right -underline 0
set bogus ""
-underline
option places an underline under the
indicated letter of the label and enables keyboard navigation through
menus. (Sorry, this is currently broken...)
The menu bar accesses all menus and menu entries by label -- that is,
by the string displayed in the menu bar or in 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 entry to the File menu and a Tycho Home
Page entry to the Help menu:
$f.mb add Close File -command {delete object $f}
$f.mb add {Tycho Home Page} Help \
-command {::tycho::File::openContext \
$TYCHO/doc/index.html} \
-underline 0 -accelerator "C-x h"
{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 addSeparator Help
$f.mb add Foo Help -command {::tycho::inform Foo!}
Individual menu entries can be disabled and enabled:
$f.mb disable {Tycho Home Page}
$f.mb disable File
enable
:
$f.mb enable {Tycho Home Page}
$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," "writeable," 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 ""
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 mature 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 bak 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 "The first button" -text "Push Me" \
-command {::tycho::post Thanks!}
$fr.tb button bar "The second button" -text "Push Me Too" \
-command {::tycho::post {Thanks again!}}
set bogus ""
$fr.tb disable foo
$fr.tb enable foo
$fr.tb entry thing "Enter something here" "Start with" {::tycho::post}
set bogus ""
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