The tabbar Widget

by

Trevor Williams

phase1geo@gmail.com

Reference

NAME
tabbar::tabbar - Create and manipulate tabbar widgets

SYNOPSIS
tabbar::tabbar pathName ?options?
STANDARD OPTIONS
-activebackground
-anchor
-background or -bg
-borderwidth or -bd
-disabledforeground
-font
-foreground or -fg
-height
-padx
-pady
-relief
-state
-takefocus
-width
-xscrollincrement
WIDGET-SPECIFIC OPTIONS
-bordercolor color
-close left|right
-closecommand command
-closeimage image
-closeshow enter|current|all
-command command
-history boolean
-inactivebackground color
-margin pixels
-maxtabwidth pixels
-mintabwidth pixels
TAB-SPECIFIC OPTIONS
-compound left|right
-emboss boolean
-image image
-padx pixels
-pady pixels
-state normal|disabled|hidden
-text text
-movable boolean
DESCRIPTION

INDICES

WIDGET COMMANDS

pathName btag
pathName cget option
pathName configure ?option? ?value option value ...?
pathName delete first ?last?
pathName index tab_index
pathName insert tab_index page_pathName ?tab_option value ...?
pathName select ?tab_index?
pathName tab tab_index ?tab_option value ...?
pathName tabs
pathName xview args
pathName xview
pathName xview scroll number what
pathName xview shown
EXAMPLE

DEFAULT BINDINGS

KEYWORDS

Detailed Reference

NAME
tabbar::tabbar - Create and manipulate tabbar widgets

SYNOPSIS
          tabbar::tabbar pathName ?options?
        
STANDARD_OPTIONS
-activebackground
-anchor
-background or -bg
-borderwidth or -bd
-disabledforeground
-font
-foreground or -fg
-height
-padx
-pady
-relief
-state
-takefocus
-width
-xscrollincrement
See the options manual entry for details on the standard options.

WIDGET-SPECIFIC OPTIONS

Command-Line Name:  -bordercolor
Database Name:  borderColor
Database Class:  Color

Specifies the color that is used in the border of each tab.

Command-Line Name:  -close
Database Name:  close
Database Class:  Close
If this option is set to a value of left or right, a close button will be drawn on each tab at the specified location on the tab. When the user left-clicks on this button, the -closecommand will be executed and the tab will be removed from the tabbar. If this option is set to the empty string, a close button will not be drawn and there will not be a widget-provided way to close a tab. The default value of this option is right.
Command-Line Name:  -closecommand
Database Name:  closeCommand
Database Class:  Command
If the -close option is set to a non-empty string value, a close button will be displayed on each tab. When the user clicks on the close button, the command specified by this option is executed, allowing the code to remove the page associated with the tab from view and do any other cleanup necessary. If this option is set to the empty string, no command will be executed when a tab is closed (but the tab will still be removed from the tabbar widget). If this optin is set to a non-empty value, the associated command will be executed in global namespace and the pathname of the tabbar widget and the pathname of the associated page widget will be appended to the -closecommand string.
Command-Line Name:  -closeimage
Database Name:  closeImage
Database Class:  Image
Specifies an alternative image to use for the close button. This option is only used when the -close option is a non-empty value. By default, the tabbar widget comes with a close button image which is basically just an "x" image. The default image is a bitmap image which is has a foreground color that matches the foreground color of the tab and a transparent background (performed by specifying the same bitmap file to the -maskfile option of the bitmap image creation script.
Command-Line Name:  -closeshow
Database Name:  closeShow
Database Class:  CloseShow
The value can be set to a value of either enter, current or all. Its value specifies when the close button will be displayed and hidden. If a value of enter is specified, the close button will be hidden until the mouse cursor enters the associated tab. At this time the close button will be displayed. When the mouse cursor leaves the tab, the close button will be hidden from view. If a value of current is specified, the close button will be continually displayed in the tab that has a tab_index value that matches current. If a value of all is specified, the close button will be displayed in all tabs at all times. The default value of this option is enter.
Command-Line Name:  -command
Database Name:  command
Database Class:  Command

When a tab is left-clicked, the command that is associated with this option will be executed in global namespace, appending the pathname of the tabbar as well as the pathname associated with the clicked tab when the tab was added to the tabbar. If the value of this option is the empty string, no command will be executed when a tab is clicked.

Command-Line Name:  -history
Database Name:  history
Database Class:  History

If this option is set to a boolean true value, the historical order of tab selections will be recorded for the tabbar such that when a tab is removed from the tabbar, the previously selected tab will be set to current tab. The highest number of stored tabs is the total number of tabs in the tabbar (i.e., tabs are not stored twice in the history list). If this option is set to a boolean value of false, the tab to the left of the removed tab is set to current (if no tabs to the left of the removed tab exist, the first tab to the right of the removed tab is made the current tab). The default value of this option is true.

Command-Line Name:  -inactivebackground
Database Name:  inactiveBackground
Database Class:  Background

The associated color associated with this option is used to colorize the background of any tab that is not the current tab.

Command-Line Name:  -margin
Database Name:  margin
Database Class:  Margin

Specifies the number of horizontal pixels to separate each tab from its neighboring tab. Default is to draw tabs with no margin.

Command-Line Name:  -maxtabwidth
Database Name:  maxTabWidth
Database Class:  TabWidth

Specifies the maximum width that a tab can be drawn in number of pixels. If this value is set to a value of 0, the maximum width of the tab will be the total width of the tabbar divided by the number of tabs to display.

Command-Line Name:  -mintabwidth
Database Name:  minTabWidth
Database Class:  TabWidth

Specifies the minimum width that a tab can be drawn in number of pixels. If the number of tabs to draw multiplied by their minimum width exceeds the width of the tabbar widget, left and right tab shift buttons will be displayed on the left and right side of the tabbar to allow the user to view buttons that are not currently displayed. Additionally, a dropdown button will be drawn on the right-most side of the tabbar to allow the user to quickly select a tab. If this value is set 0, the right, left and dropdown buttons will never be displayed. If the text in the tab cannot be displayed in full, the text will be elided, displaying the first portion of the tab string, followed by the string "...".


TAB-SPECIFIC OPTIONS

The options specified in the section can only be specified when retrieving or setting options on a tab.

-compound

If this option is set to a value of left or right an image specified by the -image tab option will be displayed on the specified side of the tab text. If this option is set to the empty string (default), the tab will only be able to display an image or text, but not both.

-emboss

If set to a boolean value of true, draws the text with an emboss effect; otherwise, draws normal text.

-image

Specifies an image to display in the tab as returned from an image create command call. If the -compound option is set, specifies the location of the image in relation to the text.

-padx

Specifies, in pixels, the amount of horizontal padding to provide between the tab border and the tab content (text/image/close).

-pady

Specifies, in pixels, the amount of vertical padding to provide between the tab border and the tab content (text/image/close).

-state

Specifies the current state of the tab. The legal values are: normal, disabled, or hidden. A button with a normal state will be shown, can be moved, and may be selected. A button with a disabled state will be shown, may not be moved and may not be selected. The text in disabled tabs will be colored with the -disabledforeground color. A button with a hidden state will not be shown, but is still managed by the widget and can be displayed again at any time by setting the state to a value of normal or disabled.

-text

Determines the text string to display in the tab. This value will be ignored if the -image option is set and the -compound option is set to the empty string. If the width of the tab is not wide enough to display the full text stored in the tab, the text will be automatically elided, displaying the left-most characters of the text followed by the string "...".

-movable

If set to a boolean value of true, the tab will be allowed to move within the tabbar and its order number will be allowed to change. If set to a boolean value of false, the tab will not be allowed to be moved within the tabbar and its position may not be modified by moving other tabs to the opposite side of the unmovable tab.


DESCRIPTION

The tabbar::tabbar command creates a new window named pathName and of the class Tabbar, and makes it into a tabbar widget.  Additional options, described above, may be specified on the command-line or in the option database to configure aspects of the tab bar such as its colors, font, sizing, etc. The tabbar::tabbar 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.

The tabbar widget is a specialized version of a ttk::notebook. Instead of displaying both the tab bar and the associated frame, the tabbar widget only displays the tab bar portion, allowing the user to place a tabbar in the same horizontal space in the application as other widgets (including other tabbar widgets), leaving the display of the tab frame up to the application writer. This mechanism allows the application writer to design some powerful interfaces that make more efficient use of screen real estate.

In addition to this capability, the tabbar widget provides some powerful, modern tab bar behaviors that most users come to expect from a tab bar, including a built-in close button per tab, the ability to re-order/move tabs by dragging them within the tabbar, dynamically resizing tabs based on number and size of the tabbar (maintaining even tab sizes), properly handling tabs when all tabs cannot be shown in the widget, and even the ability to hide tabs, just to name a few.

INDICES

Each tab position is identified with an index in the tabbar command set. The value of the index can be specified as any of the following:
number

Represents the numerical index of the tab where the left-most tab has an index value of 0 and each tab to the right of it increments its index by a value of 1. It is important to note that tabs can have different indexes if the user reorders the tabs by moving them around in the tabbar.

end

In any command that uses an index to set or get values to an existing tab, this index value refers to the right-most tab in the tabbar. For the insert command, this index refers to the position to the right of the right-most tab (i.e., the position of the inserted tab will be in the right-most position).

current

Refers to the currently selected tab in the tabbar. If the tabbar does not contain any tabs, using this index will result in an error.

last

If the -history option is set to a value of 1, refers to the last selected tab prior to the selection of the current tab. If the -history option is set to a value of 0 or there is no selection history, using this index will result in an error.

pathName

Where pathName refers to the pathname of the widget associated with the tab that is displayed when the tab is selected.

@x,y

Specifies an X and Y coordinate within the tabbar window. The tab that comes closest to the these coordinates will be indexed.

WIDGET COMMANDS

The tabbar::tabbar command creates a new Tcl command whose name is pathName.  This command may be used to invoke various operations on the widget.  It has the following general form:
pathName option ?arg arg ...?
option and the arg determine the exact behavior of the command.  The following commands are possible for tabbar widgets:

pathName btag
Returns the name of a binding tag whose name depends on the path name of the tabbar widget and which is associated with the tabbar's line canvas widget component. This binding tag precedes the tag TabbarTabBar in the list of binding tags of the tabbar descendants mentioned above and is designed to be used when defining individual binding scripts for canvas widgets.

pathName cget option
Returns the current value of the configuration option given by option. option may have any of the values specified in the STANDARD OPTIONS or WIDGET-SPECIFIC OPTIONS.

pathName configure ?option? ?value option value ...?
Query or modify the configuration options of the widget. If no option is specified, returns a list describing all of the available options for pathName (see Tk_ConfigureInfo for information on the format of this list). If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. option may have any of the values specified in the STANDARD OPTIONS or WIDGET-SPECIFIC OPTIONS.

pathName delete index ?index?
Deletes one or more tabs from the tabbar. If only a single index is specified, the tab at the given index will be removed from the tabbar. If two indices are specified, all tabs between the first index and the last index, inclusive, will be removed from the tabbar. The deleted tab(s) will be removed from the history list if the -history option is set to true.

pathName index index
Returns the numerical index of the tab associated with the index value of index within the tabbar.

pathName insert index pathname ?option value ...?
Inserts a new tab to the left of the tab identified by index (if index is a value of end, the inserted tab will be placed in the right-most position). The value of pathname is the path to the widget that will be displayed when the tab is selected. The optional option value pairs can be specified to configure the behavior of the inserted tab. Legal values are described in the TAB-SPECIFIC OPTIONS section.

pathName select ?index?
If index is specified, causes the tab at the given index to be selected (i.e, the index value current will be set to this new index position and the corresponding widget will be eligible to be displayed). If index is not specified to the command, the widget path associated with the currently selected tab will be returned. If no index is currently selected, the empty string will be returned.

pathName tab index option ?value? ?option value ...?
Retrieves the value of a tab option or sets one ore more tab options for the tab at the position specified by index. If only a single option is specified, the current value for the tab option is returned; otherwise, the arguments after the tab index must be an even number of option/pair items. The options to set or retrieve must be in the list of options as specified in TAB-SPECIFIC OPTIONS.

pathName tabs
Returns a list of the pathnames all of the associated widgets with all tabs in the tabbar (includes disabled and hidden tabs).

pathName xview ?args?
This command is used to query and change the horizontal position of the tabs within the tabbar. It can take any of the following forms:
pathName xview
Returns a list containing two elements. Each element is a real fraction between 0 and 1; together they describe the horizontal span that is visible in the window. For example, if the first element is .2 and the second element is .6, 20% of the tabbar is off-screen to the left, the middle 40% is visible, and 40% of the canvas is off-screen to the right.

pathName xview scroll number
This command adjusts the tabbar view to the left or right by the number of tabs specified by number. If the value of number is less than 0, the view is moved number of tabs to the left; otherwise, the view is moved number of tabs to the right.

pathName xview shown
Returns a list containing two numbers. The first number is the index of the left-most visible tab. The second number if the index of the right-most visible tab.
EXAMPLE

The following example shows how to make the tabbar widget (along with a frame widget to display notebook content) to make the tabbar behave as a notebook widget.

        # Require the tabbar package
        package require tabbar
        
        # This procedure displays the associated widget in the notebook frame.
        proc show_frame {tb win} {
        }
        
        ########################
        # Create the interface #
        ########################
        
        # Create the tabbar frame (contains an add button and the tabbar frame)
        ttk::frame     .tf 
        ttk::button    .tf.add -text "+" -command "add_tab"
        tabbar::tabbar .tf.tb  -command "show_frame"
      
DEFAULT BINDINGS

  1. Clicking mouse button 1 positions the insertion cursor just before the character underneath the mouse cursor, sets the input focus to this widget, and clears any selection in the widget. Dragging with mouse button 1 strokes out a selection between the insertion cursor and the character under the mouse.

  2. Double-clicking with mouse button 1 selects the word under the mouse and positions the insertion cursor at the end of the word. Dragging after a double click will stroke out a selection consisting of whole words.

  3. Triple-clicking with mouse button 1 selects all of the text in the entry and positions the insertion cursor at the end of the line.

  4. The ends of the selection can be adjusted by dragging with mouse button 1 while the Shift key is down; this will adjust the end of the selection that was nearest to the mouse cursor when button 1 was pressed. If the button is double-clicked before dragging then the selection will be adjusted in units of whole words.

  5. Clicking mouse button 1 with the Control key down will position the insertion cursor in the entry without affecting the selection.

  6. If any normal printing characters are typed in an entry, they are inserted at the point of the insertion cursor.

  7. The view in the entry can be adjusted by dragging with mouse button 2. If mouse button 2 is clicked without moving the mouse, the selection is copied into the entry at the position of the mouse cursor.

  8. If the mouse is dragged out of the entry on the left or right sides while button 1 is pressed, the entry will automatically scroll to make more text visible (if there is more text off-screen on the side where the mouse left the window).

  9. The Left and Right keys move the insertion cursor one character to the left or right; they also clear any selection in the entry and set the selection anchor. If Left or Right is typed with the Shift key down, then the insertion cursor moves and the selection is extended to include the new character. Control-Left and Control-Right move the insertion cursor by words, and Control-Shift-Left and Control-Shift-Right move the insertion cursor by words and also extend the selection. Control-b and Control-f behave the same as Left and Right, respectively. Meta-b and Meta-f behave the same as Control-Left and Control-Right, respectively.

  10. The Home key, or Control-a, will move the insertion cursor to the beginning of the entry and clear any selection in the entry. Shift-Home moves the insertion cursor to the beginning of the entry and also extends the selection to that point.

  11. The End key, or Control-e, will move the insertion cursor to the end of the entry and clear any selection in the entry. Shift-End moves the cursor to the end and extends the selection to that point.

  12. The Select key and Control-Space set the selection anchor to the position of the insertion cursor. They do not affect the current selection. Shift-Select and Control-Shift-Space adjust the selection to the current position of the insertion cursor, selecting from the anchor to the insertion cursor if there was not any selection previously.

  13. Control-/ selects all the text in the entry.

  14. Control-\ clears any selection in the entry.

  15. The F16 key (labelled Copy on many Sun workstations) or Meta-w copies the selection in the widget to the clipboard, if there is a selection.

  16. The F20 key (labelled Cut on many Sun workstations) or Control-w copies the selection in the widget to the clipboard and deletes the selection. If there is no selection in the widget then these keys have no effect.

  17. The F18 key (labelled Paste on many Sun workstations) or Control-y inserts the contents of the clipboard at the position of the insertion cursor.

  18. The Delete key deletes the selection, if there is one in the entry. If there is no selection, it deletes the character to the right of the insertion cursor.

  19. The BackSpace key and Control-h delete the selection, if there is one in the entry. If there is no selection, it deletes the character to the left of the insertion cursor.

  20. Control-d deletes the character to the right of the insertion cursor.

  21. Meta-d deletes the word to the right of the insertion cursor.

  22. Control-k deletes all the characters to the right of the insertion cursor.

  23. Control-t reverses the order of the two characters to the right of the insertion cursor.
If the entry is empty and only the watermark is displayed, the bindings will work as if the entry is empty.

If the entry is disabled using the -state option, then the entry's view can still be adjusted and text in the entry can still be selected, but no insertion cursor will be displayed and no text modifications will take place except if the entry is linked to a variable using the -textvariable option, in which case any changes to the variable are reflected by the entry whatever the value of its -state option.

The behavior of entries can be changed by defining new bindings for individual widgets or by redefining the class bindings.

KEYWORDS
notebook, widget