Wize /
Tk
Search:  

Tk in Wize

Although Wize supports standard Tk, it also provides an enhanced, namespace-refactored version of Tk. Typically this looks something like this:

  Text new .t
  Text conf .t -bd 1

The purpose of this usage is to enable validation of Tk code, something that is not possible when using the old object calls, eg.

  text .t
  .t conf -bd 1

Wize internally defines extern definition for all widgets as well as a list of their options. These definitions are available when using wize -Wall.

(Note: at runtime, options are dynamically generated and cached in files in the directory ~/.tcl. See Tk Widget Externs.)

Examples

Here's a bigger example:

Frame new .f
set t [Text new .f.t]
Text configure $t -height 10 -width 10
Text insert $t 1.0 "Hello World"
Text mark set $t foo insert
Text xview set $t

This differs from standard Tk in that the widget path just becomes an argument to a sub-command. The sub-cmd new is added to handle creation. Another advantages of using this form is that it allows command completion in editors such as Ted.

NOTE: Several issues to be aware of with Wize Tk. Sub-command shortforms should not be used (except conf). Another is that the programmer must ensure the correct window type is passed to a command. A runtime check for this is made if env(TCL_CHECK)==1, checking that window arg matches [winfo class].

Sub-Command Extensions

The following subcommands have been added to some or all widgets in order to provide more consistent or enhanced functionality.

conf

The conf is short for configure which sets options for a widget. With conf errors are silently ignored. When env(TCL_CHECK) == 1, errors are reported as warnings. When env(TCL_CHECK) == 10, they become errors.

new

The new subcommand handles widget creation. If it is passed a window path with a trailing dot, it automatically generates and returns a new (unnamed) child path name. eg.

  set f [Toplevel new .t]
  set f1 [Frame new $f.]
  set t [Text new $f1.]

New also determines if a window is a named window and if so applies any applicable style (see below).

named

A named window path is defined as one whose tail part starts with an alphabetic and the rest containing only wordchars. Also, the window must have been created with the new sub-cmd. Toplevel provides the named sub-cmd to lookup these named windows, and a style sub-cmd apply attributes. For example all the following are named paths:

  Frame new $f.top
  Frame new $f.subwin
  Frame new $f.bot

and all the following are unnamed:

  Frame new $f._sub
  Frame new $f.9
  Frame new $f.

A list of all named windows associated with a toplevel can be returned by calling named with no argument.

© 2008 Peter MacDonald

Page last modified on June 09, 2009, at 01:03 PM