Tcl 8.4 provided significant performance improvements, many new commands and options, and three new Tk widgets.
Speed was a primary objective of Tcl/Tk 8.4. Version 8.0 provided major performance improvements to Tcl with the introduction of the bytecode compiler. But new features added in version 8.1 (in particular, multi-threaded support and internationalization support with Unicode strings) slowed down Tcl significantly. The goal for 8.4 was for scripts to run as fast as — or faster than — they did under 8.0, and the goal was achieved in almost all areas of the language.
Tcl/Tk 8.4 is perhaps the most significant release since 8.1 in terms of new features. Virtually all aspects of the language gained new functionality, and new widgets were added to the core for the first time since version 8.0.
Version 8.4 also marked the transition from Tcl being under the sole control of John Ousterhout to its management by the Tcl Core Team (TCT), which is composed of a group people who have been instrumental to Tcl's development over the years. The TCT is responsible for determining changes and new features for upcoming versions of Tcl. They also work with maintainers, who have responsibility over specific aspects of Tcl/Tk, and other community volunteers to actually implement the changes. Anyone can suggest a new feature or change to Tcl by submitting a Tcl Improvement Proposal (TIP). A description of the TIP process and a list of all submitted TIPs are available at http://www.purl.org/tcl/tip. Development of the 8.4 release was already in progress before the TIP process was in place, so not all new 8.4 features were controlled by TIPs; however, in this chapter, any new feature that was proposed by a TIP has that TIP number indicated.
Changes to several commands provide better support for 64-bit values, even on 32-bit platforms. (TIP #72) The changes implemented were designed to maximize backward compatibility.
The expr
command now supports 64-bit (wide integer) arithmetic. Integer constants unable to fit in a signed 32-bit value are treated as wide integers, unless they exceed the capacity of 64 bits, in which case they are treated as double-precision floating point values. The result of an arithmetic operation is a double if at least one of the operands is a double, a wide integer if at least one of the operands is a wide integer, and a normal integer otherwise.
The int()
function always returns a non-wide integer (converting by dropping the high bits), and the new wide()
function always returns a wide integer (converting by sign-extending).
The incr
command can increment variables containing 64-bit values correctly, but can accept only 32-bit values as amounts to increment by.
The format
and scan
commands now support the l
modifier for use with integer-handling conversion specifiers (d
, u
, i
, o
, and x
), which tells them to work with 64-bit values. The binary
command gained new w
and W
specifiers for its format
and scan
subcommands, which operate on 64-bit wide values in a fashion analogous to the existing i
and I
specifiers (that is, smallest byte to largest, and largest byte to smallest, respectively).
All Tcl commands interacting with the filesystem (file
, glob
, seek
, and tell
) work correctly for files larger than 2 GB.
Tcl is now “virtual filesystem (VFS) aware,” which allows filesystem interaction and input/output to take place on something other than the system's native filesystem. (TIP #17) This means that, given appropriate extensions, any ordinary Tcl code can use the standard file commands: cd
, pwd
, glob
, file
, open
, etc. and operate on “virtual files” without realizing it. Such virtual files can be remote files (on FTP sites or over an HTTP connection) or inside archives (for example, Zip or tar files).
The basic Tcl distribution doesn't expose the capability of manipulating virtual filesystems at the Tcl script level. However, the new C APIs enables several interesting extensions and applications. TclVFS is the extension that allows standard Tcl scripts to “mount” and use virtual filesystems. TclVFS includes support for virtual filesystem types including: FTP, HTTP, WebDAV, Zip archives, tar archives, MetaKit databases, and Tcl namespaces. TclKit, which provides a method of distributing single-file, standalone executables written in Tcl/Tk, is also based on Tcl's VFS capabilities. TclKit is described in Chapter 22.
The file
command gained several new subcommands, primarily to support the new virtual filesystem capabilities described above (TIP #17): file normalize
, file separator
, and file system
. TIP #17 added the glob -tail
option. TIP #99 added the file link
command for creating hard and symbolic links. See “The file Command” on page 108 for more information on the file
subcommands, and “Matching File Names with glob” on page 122 for more information on glob
.
Tcl 8.4 added several new commands and options that increase performance when manipulating lists:
The new lset
command allows you to directly change the value of an individual list element. This is much faster than using lreplace
to replace the element with a new value. See “The lset Command” on page 66.
The lindex
command now accepts multiple indices to allow retrieval of values in nested lists. See “Getting List Elements: llength, lindex, and lrange” on 68.
Many new options were added to lsearch
for faster and more flexible list searching. You can use the -sorted
, -ascii
, -decreasing
, -dictionary
, -increasing
, -integer
, and -real
options indicate that the list is already sorted in various ways, which allows lsearch
to use a more efficient searching algorithm. TIP #80 added the -all
, -inline
, -not
, and -start
options, giving you the ability to do things such as retrieve multiple elements with a search. See “Searching Lists: lsearch” on page 69.
New -exact
, -glob
, and -regexp
options to the array names
command allow you to specify the type of pattern matching to use when searching for array element names. The new array statistics
command returns statistics about the array internals, used primarily for debugging and profiling purposes.
The fconfigure
-handshake
, -queue
, -sysbuffer
, -timeout
, -ttycontrol
, -ttystatus
, and -xchar
options provide much finer control over serial port communications than was available under previous versions of Tcl. See “The fconfigure Command” on page 231 for a description of these options.
Two new string comparison operators, eq
and ne
, can be used to force a string equality or inequality comparison everywhere that you can evaluate an expression (for example, expr
, for
, if
, and while
).
Tcl now has the ability to trace commands as well as variables. (TIP #62) Options include triggering actions: before or after executing any specified command; before or after entering any command within a specified procedure; when a command is renamed; or when a command is deleted. A new command syntax for creating and using variable traces was also added, to match the features of command tracing. The old syntax for variable traces will be retained for now for backwards compatibility, but its use is deprecated. For more information on using traces, see “Tracing Variables and Commands” on page 193.
Several new commands support more introspection and control of the Tcl interpreter:
info functions
returns a list of all the math functions currently defined. (TIP #15)
info script
now accepts an optional pathname argument. If provided, it becomes the return value for all future invocation of info script
for the duration of the session. This can be useful in virtual file system applications.
interp recursionlimit
sets and returns the maximum depth for nested Tcl procedure calls and other operations that create Tcl stack frames. (TIP #87)
namespace exists
reports whether or not a specified namespace exists.
With the -nocomplain
option, unset
suppresses any possible errors. A new --
option also allows you to delete variables that might have the same name as any unset
options.
The final regsub
argument (the name of the variable in which to store the substituted string) is now optional. If omitted, regsub
simply returns the substituted string (or the original string, of no substitutions were made). (TIP #76)
Tk 8.4 features three new widgets:
A spinbox
is an extended entry widget that allows the user to move, or “spin,” through a fixed set of values, such as times or dates, in addition to editing the value as in an entry.
A labelframe
is very similar to the standard frame, but also has the ability to display a label. (TIP #18)
A panedwindow
contains any number of panes, arranged horizontally or vertically. Each pane contains one widget, and each pair of panes is separated by a moveable sash, which causes the widgets on either side of the sash to be resized. (TIP #41)
The text widget gained several new features in Tk 8.4:
A mechanism for unlimited undoing and redoing of changes was added. (TIP #26) When the new -undo
option is set to a Boolean true value, the widget records every insert and delete action on a stack. Default key bindings allow the user to undo and redo changes, and a programmatic interface gives the application full control over the undo and redo stacks. (See “The Undo Mechanism” on page 548.)
The text widget generates a <<Modified>>
virtual event whenever the contents of the widget changes. (TIP #26)
The text widget generates a <<Selection>>
virtual event whenever the text selection of the widget changes. (TIP #26)
The text widget's delete
and get
operations now accept multiple ranges, instead of only a single character or range of characters. (TIP #93)
Both the pack
and grid
commands now support asymmetric padding. If you provide a single screen distance value to either -padx
or -pady
, then that value is used for both the left and right (or top and bottom) padding around the widget, just as it has been in previous versions of Tk. But now if you provide a 2-element list of screen distance values, then the first value determines the padding on the left (top), and the second value determines the padding on the right (bottom).
In previous versions of Tk, labels, menu entries, and the various button widgets could not display text and a bitmap or image at the same time. Tk 8.4 introduced the compound
attribute, which specifies whether the widgets should display both an image (or bitmap) and text, and if so, where the image should be placed relative to the text. (TIP #11)
Buttons, checkbuttons, and radiobuttons all gained an -overrelief
option, which specifies a relief style to use when the mouse cursor is over the widget. Checkbutton and radiobutton widgets also gained an -offrelief
option, which specifies the relief style to use for the widget when the widget is in an “off” state and the indicator is not drawn. These new relief options make it much easier to create “toolbars” from a collection of button widgets. (TIP #82)
The entry and listbox widgets gained new options for controlling their state:
The entry widget state
attribute now supports a readonly
value. When an entry is in the readonly
state, the value displayed cannot be changed by either the application or the user, and the insertion cursor is never displayed. However, the user can still select the contents of the widget. The entry widget also supports new disabledForeground
, disabledBackground
, and readonlyBackground
attributes to control its appearance in the different states.
The listbox widget now supports a state
attribute, with normal
and disabled
states, and a disabledForeground
attribute to control its appearance in the disabled state. Additionally, a new activeStyle
attribute controls the style in which the active element is drawn. (TIP #94)
Several wm
subcommands were added to provide additional interaction with the window manager and control over toplevel windows:
wm attributes
returns or sets platform-specific attributes associated with a window. (TIP #95)
wm stackorder
returns information about the stacking order of an application's toplevel windows. (TIP #74)
wm iconbitmap
accepts a new -default
option on Windows platforms for designating a default icon bitmap for all of an application's toplevel windows. (TIP #8)
tk windowingsystem
returns the current Tk windowing system, one of x11
(X11-based), win32
(MS Windows), classic
(Mac OS Classic), or aqua
(Mac OS X Aqua). (TIP #108)
You can now configure how buttons, scales, scrollbars, and spinboxes respond when the user holds down a mouse button or key for that widget. The repeatDelay
attribute specifies the number of milliseconds a button or key must be held down before it begins to auto-repeat, and the repeatInterval
attribute determines the number of milliseconds between auto-repeats.
Tk 8.4 provides greater access to transparency information for photo images. Photo image object commands now support a transparency
subcommand with get
and set
operations, which respectively get and set the transparency setting of individual pixels in the image. (TIP #14) Additionally, a new -compositingrule
option to the copy
subcommand allows you to specify how transparent pixels in the source image are combined with the destination image. (TIP #98)
The tk_getOpenFile
-multiple
option allows a user to select multiple files to open, returning the files selected as a list.
On Windows systems, the button width
attribute now accepts a negative value to specify a minimum width, enabling better compliance with native Windows look-and-feel.
A new clipboard get
subcommand returns the contents of the clipboard — equivalent to selection get -selection CLIPBOARD
.
The image inuse
command returns whether or not a specified image is in use by any widget.
To enable writing Tk-based window managers, Tk 8.4 added support for five new event types: <CirculateRequest>
, <Create>
, <MapRequest>
, <ResizeRequest>
, and <ConfigureRequest>
. The %i
and %P
event substitutions were also added. (TIP #47)
A new tk caret
command sets and queries the caret location for the display of the specified Tk window. The caret is the per-display cursor location used for indicating global focus (for example, to comply with Microsoft Accessibility guidelines), as well as for location of the over-the-spot XIM (X Input Methods) or Windows IME windows. (TIP #96)
The bell
command has the side effect of resetting the screen saver for the screen, which usually makes the screen visible again. The new -nice
option prevents the bell
command from resetting the screen saver.
The Tk 8.4.1 patch release added the ability on Windows for the canvas to generate Postscript for embedded widgets currently displayed on the screen (that is, displayed within the canvas's viewport and not obscured by other windows). This capability was added concurrently with the 8.3.5 patch release.
3.17.167.114