Version 64 of menubar - A command that creates menubar objects

Updated 2010-01-06 16:40:28 by tomk

The tklib library contains a menubar package that implements a menubar class. This class can be used to create an manage menubars in toplevel windows. The class doesn't depend on a widget framework and therefore can be used with or without a framework (e.g. Bwidget, IWidget, Snit, etc.). Some of the features of this package are:

  • A tagging system that simplifies access to menu entries in the menu tree.
  • Support for user defined tags that depend on the toplevel window context.
  • A simplified and uniform interface for all callback commands.
  • Namespace support for all callback commands so callback commands can be easily grouped into namespaces.
  • Support for hiding and exposing menus on the menubar.
  • A simplified method for creating radiobutton groups.
  • Automatic management of state variables for checkbuttons and radiobuttons.
  • Scope control for the state variables of checkbuttons and radiobuttons.
  • Tearoff menu management that ensures only one tearoff menu is created.
  • Support for dynamic menu extension to simplify the creation of recent document menus.
  • Support for saving and restoring dynamic menu extensions.

The package is written in pure Tcl/Tk but it uses TclOO so 8.6 or greater is suggested.

-- tjk


The screen shots in the following examples were created using the demo code that is part of the menubar package. You can use this code as a starting point for implementing any special feature you my need for your application.


SCOPE CONTROL

The following screen shots illustrate what is meant by scope control in the menubar class. In the screen shots below the same instance of the menubar class has been installed in each of the two toplevel windows. Below the windows are two menus that have been torn off from the same location in the menubar of each of the toplevel windows.

Global Scope Example

In this first screen shot illustrates what is meant by global scope. Each of these menus was created using the global (i.e. default) scope. As a result the value of the items are the same for both menus and changing one menu will cause the other menu to also be changed.

menubar_image1.jpg

Local Scope Example

This second screen shot is similar to the first but the menus have been created using the local scope modifier. Notice that even though the menus have identical items the value of the items on the left are different from the items on the right. These menus have values that are scoped local to their associated toplevel window.

menubar_image2.jpg

Notebook Tab Scope Example

The following two screen shots illustrate how tab selection can be used to control the value settings of check and radio buttons. Notice that in the first screen shot tab "One" is selected in both toplevel windows and in the second screen shot tab "Two" is selected.

menubar_image3.jpg

menubar ScreenShot1


DYNAMIC MENU EXTENSION

This screen shot illustrates dynamic menu extension. This menu has a dynamic extension that starts at the horizontal separator. All of the "Item"s and the "Mark" were added by clicking on the appropriate command buttons. The "Mark" was also moved up from its initial location at the end of the menu. This demo code is designed to test and illustrate the use of the group.xxx commands but these commands can of course also be used without any visible menu items.

menubar ScreenShot2