Author: Jan Nijtmans <[email protected]> State: Draft Type: Project Created: 8-June-2020 Post-History: Keywords: Tcl index Tcl-Version: 8.7 Tk-Branch: strict-index
Various commands handle errors in "index" values differently. This TIP attempts to treat the different uses of index values in Tk to a more uniform way, align them better with index usage in Tcl.
The main feature of this TIP is to let Tk indices handle all forms of Tcl indices.
So "4+5" and "end-1" will now be accepted, just as any other form accepted by
Tcl_GetIntFormIndex() (See also TIP #544).
In addition, the empty string is accepted in Tk as valid index. It means the same
-1 so not available. In Tk this is more natural, since the default of many
options is already the empty string. The default value of the
so because the empty string, and setting
-underline to the empty string means
no underlining. This default value change will be only done when Tk is compiled
with Tk 9.0 headers, in order to give applications more time to adapt to this
usage (see Compatibility section below).
Some examples (Tk):
$ wish8.6 % listbox .l % menu .m % .l index 0 0 % .l index none bad listbox index "none": must be active, anchor, end, @x,y, or a number % .m index none none % .m index 0 none % .m index foo bad menu entry index "foo"
We see that menu's have a different way to indicate 'not found' compared to other widgets.
A request is done already a long time ago, to make index handling in Tk more flexible.
widgets indices enhancement
This TIP implements part of this request (only the
active-int form is not implemented.
- Tk indices (e.g. the value of the
-underlineoption) will accept all forms accepted by
Tcl_GetIntFromIndex(), and also the empty string meaning not available. So
-underline end-1means underline one character before the last one of the string.
- Indices in menu's, which currently use
noneas default, will be changed to use the empty string as default. The use of
nonein menu's is now considered deprecated, but still supported as long as Tk is compiled with Tcl 8.x headers.
- Start accepting the empty string as index for entries, listboxes, menus .....
just as for button and menu-related
-underlineoptions. A new
TK_OPTION_INDEXoption is implemented, which is almost the same as
TK_OPTION_INT, but in stead of only integers, accepts all those index forms as well.
- When Tk is compiled with Tcl 9 headers, the default
-underlinevalue becomes the empty string in stead of -1. When compiled with Tcl 8 headers,
-1is still the default.
- When Tk is compiled with Tcl 9 headers, all commands which currently report
not available as
-1, will start returning the empty string in stead.
When compiled with Tcl 8.x headers, this is almost 100% compatible. Except for
menu commands which currently use the inconsistent
none keyword (see above example)
they will start returning the empty string.
Code can easily be made compatible in any environment. Just don't check against
-1 any more, but use the
< 0 check: Since comparing the empty
0 in Tcl uses string compare, it gives the same result as
0. All Tk utilities and demo's are already modified to
do this check consistently.
This document has been placed in the public domain.