treectrl - Create and manipulate hierarchical multicolumn widgets
The treectrl command creates a new window (given by the pathName argument) and makes it into a treectrl widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the treectrl such as its background color and relief. The treectrl command returns the path name of the new window. At the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist.
A treectrl is a listbox widget which displays items in a one- or two-dimensional arrangement. Items have a parent-child relationship with other items. Items may be arranged from top-to-bottom or from left-to-right. Items may be spread about one or more columns. Each item-column may be configured to span one or more adjacent item-columns. The visibility of items can be set individually.
Items have a set of states, which are boolean properties. For each column of an item there is a style associated, which determines how to display the item's column taking into account the item's current state set. New states may be defined to further control the appearance of items; these custom states may be turned on or off in individual columns of items.
Multiple rows of column headers are supported. Column headers have platform-native appearance on Windows, Mac OS X, and Gtk+. The appearance of column headers may be customized using styles.
Columns may be rearranged by the user using drag-and-drop. One column can be specified to display the data in a hierarchical structure. The visibility of columns can be set individually.
A treectrl can display a user-resizable selection rectangle called the marquee. Another feature, the drag image, may be used to provide feedback during drag-and-drop operations. Both of these are features commonly found in file browsers.
A treectrl can generate events when various things happen, such as changes to the selection, or a parent item being toggled open or closed. Scripts may be bound to these events. New events can be defined.
A treectrl can display a background image. The background image can be configured to be scrolled and tiled on each axis individually.
See the option manual entry for details on the standard options.
Throughout this manual page the term canvas is sometimes used. The canvas can be thought of as the virtual sheet of paper upon which all visible items are drawn. The treectrl window displays different areas of the canvas within its borders as the list is scrolled.
Columns and items may have any number of tags associated with them. A tag is just a string of characters, and it may take any form, including that of an integer, although the characters '(', ')', '&', '|', '^' and '!' should be avoided.
The same tag may be associated with many columns or items. This is commonly done to group items in various interesting ways; for example, in a file browser all directories might be given the tag "directory".
Tag expressions are used in column descriptions and item descriptions to specify which columns and items to operate on. A tag expression can be a single tag name or a logical expression of tags using operators '&&', '||', '^' and '!', and parenthesized subexpressions. For example:
.t item id "tag {(a && !b) || (!a && b)}"
or equivalently:
.t item id "tag {a ^ b}"
will return the unique ids of any items with either "a" or "b" tags, but not both.
Within a tag expression a tag name may be enclosed in double quotes to avoid special processing of the operator characters. For example:
.t item id {tag {"a&&b"||c}}
will return the unique ids of any items with either "a&&b" or "c" tags; in this example the && is not treated as an operator. A double-quote may be escaped within a quoted tag name using a backslash '\'.
Tag operators may be bypassed completely by setting the -columntagexpr and -itemtagexpr options. This can be useful if your application has column or item tags containing arbitrary text.
.t configure -itemtagexpr false .t item delete "tag a&&b"
The treectrl command creates a new Tcl command whose name is the same as the path name of the treectrl's window. This command may be used to invoke various operations on the widget. It has the following general form:
pathName option ?arg arg ...?
PathName is the name of the command, which is the same as the treectrl widget's path name. Option and the args determine the exact behavior of the command. The following commands are possible for treectrl widgets:
Sets the active item to the one described by itemDesc, and switches on the state active for that item. The active item can be referred to by the item description active. If this command changes which item is active an <ActiveItem> event is generated. If the active item is deleted the root item becomes the new active item.
Returns a list with four elements giving the bounding box (left, top, right and bottom) of an area of the window. If area is not specified, then the result is the bounding box of the entire window. If area is content, then the result is the part of the window not including borders, headers, or locked columns. If area is header, then the result is the part of the window not including borders where column titles are displayed. If area is left, then the result is the part of the window not including borders or headers where left-locked columns are displayed. If area is right, then the result is the part of the window not including borders or headers where right-locked columns are displayed.
If area is one of header.left, header.none or header.right then the area of the column headers occupied by columns with -lock=left, -lock=none or -lock=right is returned.
An empty string is returned if the display area has no height or width, which can be true for various reasons such as the window is too small, or the header is not displayed, or there aren't any locked columns.
Translates the given window x-coordinate windowx in the treectrl to canvas coordinate space. The marquee command expects canvas coordinates.
Translates the given window y-coordinate windowy in the treectrl to canvas coordinate space. The marquee command expects canvas coordinates.
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the tree command.
Deprecated. Use item collapse instead.
This command is used to manipulate the columns of the treectrl widget (see section COLUMNS below). The exact behavior of the command depends on the option argument that follows the column argument. The following forms of the command are supported:
Returns a list with four elements giving the bounding box of the header of the column specified by the column description columnDesc. The returned coordinates are relative to the top-left corner of the widget. If the column option -visible=false or if the widget option -showheader=false, then an empty list is returned.
This command returns the current value of the option named option for the column specified by the column description columnDesc, ColumnDesc may also be the string tail to specify the tail column. Option may have any of the values accepted by the column configure widget command.
This command is similar to the configure widget command except that it modifies options associated with the columns specified by the column description columnDesc instead of modifying options for the overall treectrl widget. ColumnDesc may be the string tail to specify the tail column. If columnDesc refers to more than one column, then at least one option-value pair must be given. If no option is specified, the command returns a list describing all of the available options for columnDesc (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 option(s) to have the given value(s) for columnDesc; in this case the command returns an empty string.
See COLUMNS below for details on the options available for columns.
For compatibility with older versions of treectrl (which did not support more than one row of column headers) any of the configuration options mentioned in the HEADERS section, such as -arrow, -text, etc, may be passed to the top header-row through this command.
For both column descriptions column1 and column2 the index is retrieved (as returned from the column order widget command). Then these indexes are compared using the operator op, which must be either <, <=, ==, >=, >, or !=. The return value of this command is 1 if the comparison evaluated to true, 0 otherwise.
If no additional arguments are given, the result is a decimal string giving the number of columns created by the column create widget command which haven't been deleted by the column delete widget command; in this case the tail column is not counted. If columnDesc is given, then the result is the number of columns that match that column description.
This command creates a new column in the treectrl widget. The new column is placed to the right of all other columns (except the tail column). Any option-value arguments configure the new column according to the column configure command. The return value is the unique identifier of the new column.
Deletes the specified column(s). First and last must be valid column descriptions. If both first and last are specified, then they may refer to a single column only. The tail column cannot be deleted and it is an error to specify it. The order of first and last doesn't matter, and first may be equal to last.
Deprecated. Use header dragcget instead.
Deprecated. Use header dragconfigure instead.
Deprecated. Use column id instead.
This command resolves the column description columnDesc into a list of unique column identifiers. If the column(s) described by columnDesc don't exist, this command returns an empty list.
This command returns a list of identifiers for every column (except the tail) from left to right. If -visible is given, only columns whose -visible option is true are returned.
Moves the column specified by columnDesc to the left of the column specified by beforeDesc. Both columnDesc and beforeDesc must be valid column descriptions. If beforeDesc is the string tail, the column columnDesc will become the last column.
This command returns a decimal string giving the needed width of the column specified by the column description columnDesc. The needed width is the maximum of the width of the column header and the width of the widest style in any visible item.
When an item style or column header spans multiple columns, the needed width of a column is affected by the widths of other columns in the span, in which case the result of this command isn't particularly useful.
This command returns a decimal string giving the position of the column specified by the column description columnDesc in the list of columns starting from zero for the leftmost column. If -visible is given, only columns whose -visible option is true are considered, and -1 is returned if columnDesc's -visible option is false.
This command is used to manipulate tags on columns. The exact behavior of the command depends on the option argument that follows the column tag argument. The following forms of the command are supported:
Adds each tag in tagList to the columns specified by the column description columnDesc. Duplicate tags are ignored. The list of tags for a column can also be changed via a column's -tags option.
Evaluates the tag expression tagExpr against every column specified by the column description columnDesc. The result is 1 if the tag expression evaluates to true for every column, 0 otherwise.
Returns a list of tag names assigned to the columns specified by the column description columnDesc. The result is the union of any tags assigned to the columns.
Removes each tag in tagList from the columns specified by the column description columnDesc. It is not an error if any of the columns do not use any of the tags. The list of tags for a column can also be changed via a column's -tags option.
This command returns a decimal string giving the width in pixels of the column specified by the column description columnDesc, even if the treectrl is configured to not display the column headers by means of the -showheader option.
Deprecated. Use the item compare command instead.
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 accepted by the treectrl command.
Returns a list with four elements giving the bounding box of the screen area used to display items. This is the area of the window not including borders, column headers, or locked columns. An empty string is returned if the display area has no height or width, which can happen if the window is too small. The result of this command is the same as that of bbox content.
This command is used to facilitate debugging of the treectrl widget. The exact behavior of the command depends on the option argument that follows the debug argument. The following forms of the command are supported:
Returns a string giving partial statistics on memory allocations, if the package was built with TREECTRL_DEBUG defined.
This command returns the current value of the debugging option named option. Option may have any of the values accepted by the debug configure widget command.
This command is similar to the configure widget command except that it modifies debugging options instead of modifying options for the overall treectrl widget. If no option is specified, the command returns a list describing all of the available debugging options (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 debugging option(s) to have the given value(s); in this case the command returns an empty string.
The following debugging options are supported:
Returns a string describing display-related stuff. Option must be one of alloc, ditem, onscreen or range.
Causes the area of the window bounded by the given window-coords to be marked as invalid. This simulates uncovering part of the window.
If the additional argument itemDesc is given, then the result is a decimal string giving the depth of the item described by itemDesc. If no itemDesc is specified, then the maximum depth of all items in the treectrl widget is returned instead. Depth is defined as the number of ancestors an item has.
This command is used to manipulate the drag image, which is used to provide feedback when items are drag-and-dropped within the window. The drag image is displayed as the dotted outlines of one or more items, columns and/or elements. The exact behavior of the command depends on the option argument that follows the dragimage argument. The following forms of the command are supported:
Adds the shapes of the item described by itemDesc to the shapes of the dragimage. Specifying additional arguments reduces the number of rectangles that are added to the dragimage. If no additional arguments is specified, for every element of the item in every column a dotted rectangles is added. If column is specified, all elements in other columns are ignored. If also element is specified, only a rectangle for this one element of the specified item in the given column is added.
This command returns the current value of the dragimage option named option. Option may have any of the values accepted by the dragimage configure widget command.
Removes all shapes (if there are any) from the dragimage. This command does not modify the dragimage offset.
This command is similar to the configure widget command except that it modifies the dragimage options instead of modifying options for the overall treectrl widget. If no option is specified, the command returns a list describing all of the available dragimage options (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 dragimage 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 dragimage option(s) to have the given value(s); in this case the command returns an empty string.
The following dragimage options are supported:
Returns a list containing the x and y offsets of the dragimage, if no additional arguments are specified. The dragimage offset is the screen distance the image is displayed at relative to the item(s) its shape is derived from. If two coordinates are specified, sets the dragimage offset to the given coordinates x and y.
This command is used to manipulate elements (see ELEMENTS AND STYLES below). The exact behavior of the command depends on the option argument that follows the element argument. The following forms of the command are supported:
This command returns the current value of the option named option associated with the element given by element. Option may have any of the values accepted by the element configure widget command.
This command also accepts the -statedomain option.
This command is similar to the configure widget command except that it modifies options associated with the element given by element instead of modifying options for the overall treectrl widget. If no option is specified, the command returns a list describing all of the available options for element (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 option(s) to have the given value(s) in element; in this case the command returns an empty string. See ELEMENTS AND STYLES below for details on the options available for elements.
Creates a new master element of type type with the unique user-defined name name and configures it with zero or more option/value pairs. See the subsections on individual element types in ELEMENTS AND STYLES for the options that are valid for each type of element. This command returns the name of the new element (the same as the name argument).
This command also accepts the -statedomain option with a value of either header or item to specify where this element will be displayed.
Deletes each of the named elements and returns an empty string. If an element is deleted while it is still configured as an element of one or more styles by means of the style elements widget command, it is also removed from the element lists of these styles.
Returns a list containing the names of all existing elements.
This command returns the value of the per-state option named option for element for a certain state. StateList is a list of state names (static and dynamic, see STATES) which specifies the state to use.
Returns the type of the element given by element, such as rect or text.
Deprecated. Use item expand instead.
This command is used to manipulate color gradients. See GRADIENTS for more information about using gradients. The exact behavior of the command depends on the option argument that follows the gradient argument. The following forms of the command are supported:
Returns the current value of the configuration option for the gradient specified by gradient whose name is option. Option may have any of the values accepted by the gradient configure command.
If no option is specified, the command returns a list describing all of the available gradient options (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 gradient 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 gradient option(s) to have the given value(s); in this case the command returns an empty string.
The following options are supported (see gradient create for the meaning of each option):
Creates a new gradient with the name name, which must be a unique name not used by another gradient created by this treectrl widget.
The following options are supported:
Deletes each gradient specified by name. If the gradient is still being used then it is not actually deleted until all elements etc using the gradient have stopped using it. A deleted-but-in-use gradient is not recognized by the various gradient commands. Creating a new gradient with the same name as a deleted-but-in-use gradient resurrects the deleted gradient.
Returns a list of names of all the gradients that have been created by this treectrl widget.
Without any arguments, this command returns a boolean indicating whether or not the platform supports native transparent gradients. The preference argument is a boolean that indicates whether native gradients should be used; this can be used to test the appearance of the application.
This command is used to manipulate column headers. The exact behavior of the command depends on the option argument that follows the header argument. The following forms of the command are supported:
See the item bbox command.
See the item compare command.
There are two forms of this command distinguished by whether or not a column description appears after the headerDesc argument. If the first argument after headerDesc begins with a '-' character it is assumed to be an option name, not a column description, in which case the command applies to the header-row. If the first argument after headerDesc does not being with a '-' it is assumed to be a column description, in which case the command applies to a header-column.
If no option is specified, returns a list describing all of the available options for the header given by headerDesc (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 option(s) to have the given value(s); in this case the command returns an empty string. This is the only case where headerDesc may refer to multiple header-rows.
The following options are supported by this command (see header create for the meaning of each option):
If no option is specified, returns a list describing all of the available options for the single column column of the header-row given by headerDesc (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 option(s) to have the given value(s); in this case the command returns an empty string. This is the only case where both headerDesc may refer to multiple header-rows and column may refer to multiple header-columns.
The following options are supported by this command (see HEADERS) for the meaning of each option):
If no additional arguments are given, the result is a decimal string giving the number of header-rows created by the header create widget command which haven't been deleted by the header delete widget command, plus 1 for the ever-present top header-row created along with the widget. If the optional argument headerDesc is given, then the result is the number of header-rows that match that header description.
Creates a new header-row and returns its unique identifier. The following configuration options are supported:
Deletes the header-rows given by the header description headerDesc. Attempts to delete the ever-present top header-row are ignored without raising an error.
There are two forms of this command distinguished by whether or not a header description appears as the first argument. If the first argument begins with a '-' character it is assumed to be an option name, not a header description, in which case the command applies to the header-drag-and-drop options for the widget. If the first argument does not being with a '-' it is assumed to be a header description, in which case the command applies to a header-row.
This command returns the current value of the header-drag-and-drop option named option for the widget. The following configuration options are supported (see header dragconfigure for the meaning of each option):
This command returns the current value of the header-drag-and-drop option named option for a header-row. The following configuration options are supported (see header dragconfigure for the meaning of each option):
There are two forms of this command distinguished by whether or not a header description appears as the first argument. If the first argument begins with a '-' character it is assumed to be an option name, not a header description, in which case the command applies to the header-drag-and-drop options for the widget. If the first argument does not being with a '-' it is assumed to be a header description, in which case the command applies to a header-row.
This command queries and sets header-drag-and-drop options for the widget, not for individual header-rows. The following configuration options are supported:
This command queries and sets header-drag-and-drop options for header-rows, not for the widget as a whole. The following configuration options are supported:
See the item element command.
This command resolves the header description headerDesc into a list of unique header-row identifiers. If headerDesc doesn't refer to any existing header-rows, then this command returns an empty list.
The behavior of this command depends on whether or not a column header was assigned a style containing an image element. If a column header has no style or no style with an image element then this command operates on the same -image option as header configure. Otherwise this command operates on the -image option of the first image element in a column header's style. See the item image command.
See the item span command.
See the item state command.
See the item style command.
The behavior of this command depends on whether or not a column header was assigned a style containing a text element. If a column header has no style or no style with a text element then this command operates on the same -text option as header configure. Otherwise this command operates on the -text option of the first text element in a column header's style. See item text.
See the item tag command.
This command returns information about the what is displayed at the given window coordinates x and y. When the -array option is used to specify the name of an array variable, elements of the array variable are set as follows:
If the coordinates are outside the window, over the borders, or over any whitespace in the window, then:
$varName(where) is ""
If the coordinates are over a column header, then:
$varName(where) is header
$varName(header) is the unique id of the header-row
$varName(column) is the unique id of the column
$varName(element) is the name of an element, or ""
$varName(side) is left or right if the coordinates are close to the edge of the column header, otherwise ""
If the coordinates are over an item, then:
$varName(where) is item
$varName(item) is the unique id of the item
$varName(column) is the unique id of the column
$varName(element) is the name of an element, or ""
$varName(button) is a boolean indicating whether or not the coordinates are over the item's expand/collapse button
$varName(line) is the unique id of an ancestor of the item (but not the parent of the item) if the coordinates are over a line descending from that ancestor. If the coordinates are not over such a line then $varName(line) is "". This is used to collapse the ancestor when the line is clicked on.
When the -array option is not used, this command returns a list describing what is displayed at the given window coordinates. The format of this list can be like one of the following:
{}
An empty list is returned if the coordinates are outside the window, over the borders, or over any whitespace in the window.
header C ?left|right?
header C elem E ?left|right?
header H column C ?left|right?
header H column C elem E ?left|right?
Only when there is more than one header-row is there a unique id of a header-row H followed by the keyword column. This is for compatibility with older versions when there was only one row of column headers allowed.
item I column C
item I column C elem E
item I button
This is the result when the coordinates are over the expand/collapse button next to an item.
item I line I2
This is the result when the coordinates are over a line descending from an ancestor I2 of the item I (but not the parent of that item). This is used to collapse the ancestor when the line is clicked on.
Deprecated. Use item id instead.
This command is used to manipulate items. The exact behavior of the command depends on the option argument that follows the item argument. The following forms of the command are supported:
Returns a list containing the item ids of the ancestors of the item specified by itemDesc. The first list value is the parent, the second is the parent's parent, an so on. The last list value will be the root item if itemDesc is a descendant of the root item.
Returns a list with four elements giving the bounding box of the item described by itemDesc. If no further argument is specified, the bbox spans the area of the item over all non-locked columns. If a column is specified, only the area of the item in this column is considered. If an additional element is specified, the area of this element in column of the specified item is returned. The returned coordinates are relative to the top-left corner of the widget. If the item is not visible for any reason, the result in an empty string.
If state is specified, this command sets the state of the expand/collapse button for the single item specified by itemDesc. The state argument may be one of active, normal or pressed. The current (or newly-set) state of the button is returned. The button state is used by the system theme, if any, to change the appearance of the button.
Returns the current value of the configuration option for the item specified by itemDesc whose name is option. Option may have any of the values accepted by the item configure command.
Returns a list containing the item ids of all children of the item specified by itemDesc in the correct order from the first child to the last child.
Switches off the open state of the item(s) described by itemDesc. If an item has descendants, then they are no longer displayed. If an item is already closed, then this command has no effect on that item. If -animate is specified, then the item's button will animate as it transitions between states if the theme supports it; in this case only one item may be specified. If -recurse is specified, then all descendants of the items described by itemDesc will also be collapsed. For every item that actually will be collapsed, two events are generated: a <Collapse-before> event before the item state is changed, and a <Collapse-after> event after the item state was changed.
From both items described by the itemDescs the index is retrieved (as returned from the item order widget command). Then these indexes are compared using the operator op, which must be either <, <=, ==, >=, >, or !=. The return value of this command is 1 if the comparison evaluated to true, 0 otherwise.
This horrible command is now deprecated. Use item element configure instead. For every column of the treectrl there may be specified one list. Each list should look like this:
{ {element option value ...} {element option value ...} ...}
Every option must be known by the element's type (see ELEMENTS AND STYLES below). Each option will be set to value for the element in this one column in this item.
If no option is specified, returns a list describing all of the available options for the item given by itemDesc (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 item option(s) to have the given value(s); in this case the command returns an empty string. This is the only case where itemDesc may refer to multiple items.
The following options are supported by this command (see item create for the meaning of each option):
If no additional arguments are given, the result is a decimal string giving the number of items created by the item create widget command which haven't been deleted by the item delete widget command, plus 1 for the ever-present root item. If the optional argument itemDesc is given, then the result is the number of items that match that item description.
Creates some new items and optionally returns a list of unique identifiers for those items. The new items have the states open and enabled set by default. If the treectrl widget currently has the focus, the state focus is also set.
The following options are supported by this command:
Deletes the specified item(s). First and last must be valid item descriptions. If last isn't specified, then first may specify multiple items. If both first and last are specified, they must each decribe a single item with a common ancestor; then the range of items between first and last is deleted. The order of first and last doesn't matter.
Deleting an item deletes any child items of the deleted item recursively. If the current active item is deleted, the root item becomes the new active item. If the current selection anchor item is deleted, the root item becomes the new anchor item. There is no way to delete the root item of the treectrl widget; in all cases the specification of the root item is ignored.
For each call to this command, two events may be generated. If any of the deleted items are selected, then they are removed from the selection and a <Selection> event is generated just before the items are deleted. If any items are going to be deleted, then an <ItemDelete> event is generated just before the items are deleted.
Returns a list containing the item ids of the descendants of the item specified by itemDesc, i.e. the children, grandchildren, great-grandchildren etc, of the item.
Debug command. Returns a list with 4 words in the form index index indexVis indexVis.
This command is used to manipulate elements of the item. The exact behavior of the command depends on the command argument that follows the element argument. The following forms of the command are supported:
Deprecated. Use item element perstate instead.
This command returns the value of the option named option associated with element inside column of the item described by itemDesc, if it was already configured for the actual item. Option may have any of the values accepted by the type of the specified element (see ELEMENTS AND STYLES below)
This command modifies configuration options for an element in a column of an item. If no option is specified, the command returns a list describing all of the available options for the element (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 option(s) to have the given value(s) in the element inside column of the item(s) described by itemDesc; in this case the command returns an empty string. This is the only case where itemDesc may refer to multiple items.
It is possible to configure multiple elements in multiple columns with a single call. To configure another element in the same column, append a '+' argument followed by the element name. To configure elements in another column, append a ',' argument followed by the column. For example:
.t item element configure $I \ $C1 $E1 -text "hello" + $E2 -text "world" , \ $C2 $E3 -fill Blue , \ $C3 $E1 -text "apples and oranges"
Each of the column description arguments to this command may refer to multiple columns if at least one option-value pair is given.
This command returns the current value of the per-state option named option for element inside column of the item described by itemDesc. If stateList is specified, the list of state names (static and dynamic, see STATES) is used in place of the current state for item and column.
Returns 1 if the item described by itemDesc has the state enabled switched on, 0 otherwise. If boolean is specified, then the enabled state of every item described by the item description itemDesc is set accordingly. New items are enabled by default when created. Disabled items cannot be selected, and are ignored by the default key-navigation and mouse bindings.
Switches on the open state of the item(s) described by itemDesc. If an item has descendants, then they are now displayed. If an item is already open, then this command has no effect on that item. If -animate is specified, then the item's button will animate as it transitions between states if the theme supports it; in this case only one item may be specified. If -recurse is specified, then all descendants of the items described by itemDesc will also be expanded. For every item that actually will be expanded, two events are generated: an <Expand-before> event before the item state is changed, and an <Expand-after> event after the item state was changed.
If child is not specified, returns the item id of the first child of the item described by parent. If child is specified, it must describe an item that is neither the root item nor an ancestor of parent. Then it will become the new first child of parent.
This command resolves the item description itemDesc into a list of unique item identifiers. If itemDesc doesn't refer to any existing items, then this command returns an empty list.
This command sets or retrieves the value of the per-state -image option for the first image element in one or more columns. If no column is specified, this command returns a list of values, one per column. If no image is specified, this command returns the value for column.
If one or more column-image pairs is specified, then the value of the -image option in each column is set to image. In this case itemDesc may refer to multiple items and each column may refer to multiple columns.
Note that this command is provided as a convenience. Use the item element configure or item element cget commands if you want to set or retrieve the value of the -image option for a specific image element.
Returns 1 if the item described by itemDesc is a direct or indirect parent of the item decribed by descendant, 0 otherwise.
Returns 1 if the item described by itemDesc has the state open switched on, 0 otherwise.
If child is not specified, returns the item id of the last child of the item described by parent. If child is specified, it must describe an item that is not an ancestor of parent. Then it will become the new last child of parent.
If next is not specified, returns the item id of the next sibling of the item described by sibling. If next is specified, it must describe an item that is not an ancestor of sibling. Then it will become the new next sibling of sibling.
Returns the number of children of the item described by itemDesc.
This command returns the position of the item itemDesc relative to its toplevel ancestor (usually the root item, unless the ancestor is an orphan). If you imagine all the items flattened into a vertical list, the result of this command is the row the item falls in. If the optional argument -visible is given, only the items whose ancestors are expanded, and whose -visible option is true, get counted; in this case -1 is returned if the item is not visible.
Returns the item id of the parent of the item described by itemDesc.
If prev is not specified, returns the item id of the previous sibling of the item described by sibling. If prev is specified, it must describe an item that is not an ancestor of sibling. Then it will become the new previous sibling of sibling.
Returns a list containing the item ids of all items in the range between first and last, inclusive. The order between first and last doesn't matter, and the result is always sorted by the increasing order of the items (as returned by the item order command). The items specified by first and last must share a common ancestor.
Removes the item described by itemDesc from the list of children of its parent, so that it will become an orphan.
Returns a list of two integers, which corresponds to the row and column of the item described by itemDesc. The row and column corresponds to the on-screen arrangement of items as determined by the -orient and -wrap options. If the item is not displayed, this command returns an empty string.
Sorts the children of the item described by itemDesc, and redisplays the tree with the items in the new order.
The range of items which should be sorted can be restricted by means of the -first and/or -last options, which should be children of the item described by itemDesc; the order between these two limiting items doesn't matter.
The sort column can be specified by means of the -column option; this option can be used repeatedly to define a multicolumn sort. The sorting is done by looking at the text of the element specified by the -element option, which must be a text element defined in the style of the sorting column, by default the first text element is used.
If the -notreally option is specified, no rearranging of the items is done; instead the sorted items are returned as result of the command.
By default ASCII sorting is used with the result returned in increasing order. Any of the following options may be specified to control the sorting process of the previously specified column (unique abbreviations are accepted):
This command sets or retrieves the number of columns that a style covers. If no column is specified, the return value is a list of spans, one per column. If no numColumns is specified, the return value is the span for column.
If one or more column-numColumns pairs is specified, the span for each column is set to numColumns. In this case itemDesc may refer to multiple items and each column may refer to multiple columns.
This command is used to manipulate the states of an item. The exact behavior of the command depends on the command argument that follows the style argument. The following forms of the command are supported:
Defines a new state with the name stateName, which must not be the name of an existing state.
Just like item state set but manipulates dynamic states for a single item column, not the item as a whole. If stateDescList is unspecified, this command returns a list containing the names of all the dynamic states which are switched on in column.
If stateDescList is specified, then itemDesc may refer to multiple items and column may refer to multiple columns.
If no stateName is specified, returns a list containing the names of all (static and dynamic) states which are currently switched on for the item described by itemDesc. If a stateName is specified, 1 is returned if the specified state is currently switched on for the item, 0 otherwise.
Returns a string indicating whether the specified state is user-defined by means of the item state define widget command (dynamic) or predefined by the treectrl widget itself (static).
Returns a list containing the names of all user-defined states.
Every element of stateDescList must be the name of a dynamic state (see STATES below), optionally preceded by a ~ or ! character. Every state with a leading ! will be switched off for the item described by itemDesc, every state with a leading ~ will be toggled, and every state without leading ! or ~ will be switched on. If lastItem is specified, the state changes will be made for all items in the range between itemDesc and lastItem. If lastItem unspecified, then the state changes are made for all items described by itemDesc.
Every stateName must be the name of a user-defined state. Removes this state from the list of user-defined states.
This command is used to manipulate the styles of an item. The exact behavior of the command depends on the command argument that follows the style argument. The following forms of the command are supported:
This command returns a list containing the names of elements which were configured by the item element configure command for the item described by itemDesc in column. If there is no style assigned to column an error is returned.
Like the item style set command, this command may be used to assign a style to a specific column of an item. Unlike item style set, this command can transfer configuration values of elements in the current style to elements in the new style specified by style. Map must be a list of elementOld-elementNew pairs, where elementOld is an element in the current style, and elementNew is an element in the style specified by style. Both elementOld and elementNew must be of the same type (bitmap, text etc). ItemDesc may refer to multiple items and column may refer to multiple columns.
This command sets or retrieves the style assigned to one or more columns. If no column is specified, this command returns a list containing the names of the styles set for all columns of the item described by itemDesc. If no style is specified, this command returns the name of the style set for the item described by itemDesc in column.
If one or more column-style pairs is specified, then the style in each column is set to style. In this case itemDesc may refer to multiple items and each column may refer to multiple columns.
This command is used to manipulate tags on items. The exact behavior of the command depends on the option argument that follows the item tag argument. The following forms of the command are supported:
Adds each tag in tagList to the items specified by the item description itemDesc. Duplicate tags are ignored. The list of tags for an item can also be changed via an item's -tags option.
Evaluates the tag expression tagExpr against every item specified by the item description itemDesc. The result is 1 if the tag expression evaluates to true for every item, 0 otherwise.
Returns a list of tag names assigned to the items specified by the item description itemDesc. The result is the union of any tags assigned to the items.
Removes each tag in tagList from the items specified by the item description itemDesc. It is not an error if any of the items do not use any of the tags. The list of tags for an item can also be changed via an item's -tags option.
This command sets or retrieves the value of the -text option for the first text element in one or more columns. If no column is specified, this command returns a list of values, one per column. If no text is specified, this command returns the value for column.
If one or more column-text pairs is specified, then the value of the -text option in each column is set to text. In this case itemDesc may refer to multiple items and each column may refer to multiple columns.
Note that this command is provided as a convenience. Use the item element configure or item element cget commands if you want to set or retrieve the value of the -text option for a specific text element.
Changes the open state of the item(s) described by itemDesc. If the open state is currently switched off, then this command does the same as the item expand widget command; otherwise the same as the item collapse widget command. If -animate is specified, then the item's button will animate as it transitions between states if the theme supports it; in this case only one item may be specified. If -recurse is specified, then the open state of all descendants of the items described by itemDesc will also be toggled.
This command is used to manipulate the marquee, which can be used to implement a resizable selection rectangle, in a file browser for example. One corner point of the marquee is fixed as long as the marquee is visible and called the anchor; the diagonally opposite corner is dragged with the mouse while resizing the marquee and simply called the corner.
All coordinates handled by this widget command are canvas coordinates, i.e. the canvasx or canvasy widget command should be used to translate window coordinates to canvas coordinates.
By default, the marquee is displayed as a 1-pixel thick dotted rectangle. If either of the -fill or -outline options is specified, then the marquee is drawn as a filled and/or outlined rectangle of the specified color(s). The -fill option should specify a transparent gradient to avoid hiding what is inside the marquee. See GRADIENTS for more info.
The exact behavior of the command depends on the option argument that follows the marquee argument. The following forms of the command are supported:
Returns a list containing the x and y coordinates of the anchor, if no additional arguments are specified. If two coordinates are specified, sets the anchor to the given coordinates x and y.
This command returns the current value of the marquee option named option. Option may have any of the values accepted by the marquee configure widget command.
This command is similar to the configure widget command except that it modifies the marquee options instead of modifying options for the overall treectrl widget. If no option is specified, the command returns a list describing all of the available marquee options (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 marquee 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 marquee option(s) to have the given value(s); in this case the command returns an empty string.
The following marquee options are supported:
Returns a list containing the x and y coordinates of the anchor followed by the x and y coordinates of the corner, if no additional arguments are specified. If four coordinates are specified, sets the anchor to the given coordinates x1 and y1 and the corner to the coordinates x2 and y2.
Returns a list containing the x and y coordinates of the corner, if no additional arguments are specified. If two coordinates are specified, sets the corner to the given coordinates x and y.
Returns a list with information about any items intersecting the marquee. The format of the returned list is:
{ {item {column element element ...} {column element element ...} ...} {item {column element element ...} {column element element ...} ...} ... }
There may be zero sublists following an item id if the marquee is in the button/line area of an item. There may be zero element names following a column id if the item-column has no style or if the marquee does not intersect any elements in that column.
Many Tk widgets communicate with the outside world via -command callbacks and/or virtual events. For example, the Text widget evaluates its -yscrollcommand when the view in the widget changes, and generates a <<Modified>> virtual event when text is inserted or deleted. A treectrl widget replaces both methods of communication with its own event mechanism accessed through the notify subcommands.
The exact behavior of the command depends on the option argument that follows the notify argument. The following forms of the command are supported:
This command associates Tcl scripts with events generated by a treectrl widget. If all three arguments are specified, notify bind will arrange for script (a Tcl script) to be evaluated whenever the event(s) specified by pattern are generated by this treectrl widget. If script is prefixed with a "+", then it is appended to any existing binding for pattern; otherwise script replaces any existing binding. If script is an empty string then the current binding for pattern is destroyed, leaving pattern unbound. In all of the cases where a script argument is provided, notify bind returns an empty string.
If pattern is specified without a script, then the script currently bound to pattern is returned, or an empty string is returned if there is no binding for pattern. If neither pattern nor script is specified, then the return value is a list whose elements are all the patterns for which there exist bindings for object.
The object argument determines which window(s) the binding applies to. If object begins with a dot, as in .a.b.c, then it must be the path name for a window; otherwise it may be an arbitrary string. Like the regular bind command, bindings on window names are automatically removed if that window is destroyed.
This command sets and retrieves options for bindings created by the notify bind command.
If no option is specified, the command returns a list with option-value pairs describing all the available binding options for pattern on object. If option is specified with no value, then the command returns the current value of that option. If one or more option-value pairs are specified, then the command modifies the given option(s) to have the given value(s) for the binding; in this case the command returns an empty string.
The following binding options are supported:
Returns a list containing the names of all details, which are installed for the event with the name eventName by means of the notify install widget command or by the treectrl widget itself.
Returns a list containing the names of all events, which are installed by means of the notify install widget command or by the treectrl widget itself.
This command causes the treectrl widget to generate an event. This command is typically used to generate dynamic events created by the notify install command, but may be used to generate static events also. The event specified by pattern is generated, and any active binding scripts on the event are evaluated after undergoing %-substitution. If there are details defined for the event, pattern must describe an <eventName-detail> pair, otherwise pattern should be <eventName>.
The optional charMap is a list of char-value pairs as in the form returned by array get. Each char has to be exactly one character. The charMap is used in %-substitution.
If percentsCommand is specified, then it will be used to perform %-substitution on any scripts bound to the event. If percentsCommand is not specified and the event is dynamic, then the %-subtitution command passed to notify install will be used if it was provided. If the event is static or no %-substitution command is available, then all %-substitution is done using charMap only . See notify install for a description of percentsCommand.
This command installs a new event or detail specified by pattern. Events created by this command are called dynamic, whereas events created by the treectrl widget itself are called static. This command may be called to set or retrieve the percentsCommand for an existing dynamic event.
The optional percentsCommand is a list containing the name of a Tcl command, plus any optional arguments, to which five additional arguments will be appended. The command will be called to perform %-substitution on any scripts bound to the event specified by pattern (see EVENTS AND SCRIPT SUBSTITUTIONS). PercentsCommand should be defined as follows:
proc percentsCommand {?arg arg ...? char object event detail charMap} { switch -- $char { ... } return $value }
The optional arg arguments are part of the percentsCommand list. Char is the %-character to be substituted. Object is the same as the argument to notify bind. Event and detail specify the event. CharMap is the same as the argument to notify generate. PercentsCommand should return the value to replace the %-character by. If an error occurs evaluating percentsCommand, the %-character is replaced by itself.
notify install returns the current percentsCommand for the event, or an error if the event is not dynamic.
Deprecated. Use notify install with a pattern of <eventName-detail> instead.
Deprecated. Use notify install with a pattern of <eventName> instead.
Returns a string indicating whether the specified event or detail is created by means of the notify install widget command (dynamic) or by the treectrl widget itself (static).
Deprecated. Use notify linkage with a pattern of <eventName> or <eventName-detail> instead.
If no pattern is specified, all bindings on object are removed. If pattern is specified, then the current binding for pattern is destroyed, leaving pattern unbound.
If the event or detail specified by pattern is static (i.e. created by the treectrl widget itself), an error is generated. Otherwise the dynamic event or detail is removed. If an event name is specified without a detail, all details for that event are also removed.
Deprecated. Use notify uninstall with a pattern of <eventName-detail> instead.
Deprecated. Use notify uninstall with a pattern of <eventName> instead.
Deprecated. Use the column count command instead.
Deprecated. Use the item count command instead.
Returns a list containing the item ids of all items which have no parent. When an item is created, it has no parent by default, and can later become an orphan by means of the item remove widget command. The root item is not returned.
Deprecated. Use the item range command instead.
This command is used to implement scanning on treectrls. It has two forms, depending on option:
Records x and y and the treectrl's current view; used in conjunction with later scan dragto commands. Typically this command is associated with a mouse button press in the widget and x and y are the coordinates of the mouse. It returns an empty string.
This command computes the difference between its x and y arguments (which are typically mouse coordinates) and the x and y arguments to the last scan mark command for the widget. It then adjusts the view by gain times the difference in coordinates, where gain defaults to 10. This command is typically associated with mouse motion events in the widget, to produce the effect of dragging the treectrl at high speed through its window. The return value is an empty string.
Adjust the view in the treectrl so that the item described by itemDesc is visible. If the item is already visible then the command has no effect; otherwise the treectrl scrolls to bring the item into view, and the corresponding <Scroll-x> and/or <Scroll-y> events are generated. If columnDesc is specified then a specific column of the item is scrolled into view instead of the entire item.
The following options are supported:
This command is used to adjust the selection within a treectrl. It has several forms, depending on option:
First and last (if specified) must be valid item descriptions. If both first and last are specified, then they may refer to a single item only; in this case the command adds every unselected item in the range between first and last, inclusive, to the selection without affecting the selected state of items outside that range. If only first is specified, then every unselected item specified by first is added to the selection. A <Selection> event is generated if any items were added to the selection.
If itemDesc is specified, the selection anchor is set to the described item. The selection anchor is the end of the selection that is fixed while dragging out a selection with the mouse. The item description anchor may be used to refer to the anchor item. This command doesn't modify the selection state of any item. Returns the unique id of the selection anchor item.
First and last (if specified) must be valid item descriptions. If both first and last are specified, then they may refer to a single item only; in this case any selected items between first and last (inclusive) are removed from the selection without affecting the selected state of items outside that range. If only first is specified, then every selected item specified by first is removed from the selection. If neither first nor last are specified, then all selected items are removed from the selection. A <Selection> event is generated if any items were removed from the selection.
Returns an integer indicating the number of items in the treectrl that are currently selected.
When no additional arguments are given, the result is an unsorted list containing the item ids of all of the items in the treectrl that are currently selected. If there are no items selected in the treectrl, then an empty string is returned. The optional arguments first and last are treated as indices into the sorted list of selected items; these arguments allow in-place lindex and lrange operations on the selection. For example:
.t selection get 0 ; # return the first selected item .t selection get end ; # return the last selected item .t selection get 1 end-1 ; # return every selected item except the first and last
Returns 1 if the item described by itemDesc is currently selected, 0 if it isn't.
Both arguments select and deselect are a possibly-empty list of item descriptions. Any unselected items in select are added to the selection, and any selected items in deselect are removed from the selection (except for those items which are also in select). A <Selection> event is generated if any items were selected or deselected.
This command is used to manipulate the list of user-defined item states, see section STATES below. Item states can also be managed using the item state command. To manage states for header-rows, use the header state widget command. The exact behavior of the command depends on the option argument that follows the state argument. The following forms of the command are supported:
Defines a new state with the name stateName, which must not be the name of an existing state.
Returns a string indicating whether the specified state is user-defined by means of the state define widget command (dynamic) or predefined by the treectrl widget itself (static).
Returns a list containing the names of all user-defined states.
Every stateName must be the name of a user-defined state. Removes this state from the list of user-defined states.
This command is used to manipulate styles, which can be thought of as a geometry manager for elements. The exact behavior of the command depends on the option argument that follows the style argument. The following forms of the command are supported:
This command returns the current value of the option named option associated with the style given by style. Option may have any of the values accepted by the style configure widget command.
This command also accepts the -statedomain option.
This command is similar to the configure widget command except that it modifies options associated with the style given by style instead of modifying options for the overall treectrl widget. If no option is specified, the command returns a list describing all of the available options for style (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 option(s) to have the given value(s) in style; in this case the command returns an empty string.
The following options are supported:
Creates a new style with the unique user-defined name name. After name there may be any number of option-value pairs, each of which sets one of the configuration options for the style. See the style configure command for the possible options. The result of this command is the name of the new style (the same as the name option).
This command also accepts the -statedomain option with a value of either header or item to specify where this style will be displayed.
Deletes each of the named styles and returns an empty string. If a style is deleted while it is still used to display one or more items, it is also removed from the style list of these items.
Specifies the elements which should be layed out by this style. Each element of elementList must be the name of an element created by the widget command element create. Duplicate names in elementList are ignored. An element which was specified in a former call of this command for style but is not included in elementList, will be deleted from the elements layed out by style.
Every element used by a style must have been created with the same value for the -statedomain option.
If the elementList argument is not specified, a list is returned containing the currently defined elements of style.
This command is similar to the configure widget command except that it modifies options used by style for laying out element instead of modifying options for the overall treectrl widget. If no option is specified, the command returns a list with option-value pairs describing all of the available options for the layout. If option is specified with no value, then the command returns the value of the named option. If one or more option-value pairs are specified, then the command modifies the given option(s) to have the given value(s) for the layout; in this case the command returns an empty string.
The options of a layout have effect on exactly the one element element managed by style. The following options are supported:
Returns a list containing the names of all existing styles.
This command is used to interact with the platform-specific theme. The exact behavior of the command depends on the option argument that follows the theme argument. The following forms of the command are supported:
Returns the API used to draw themed parts of the treectrl. On Mac OS X the result is always aqua. On MS Windows the result is visualstyles if the uxtheme.dll was loaded and visual themes are in use, otherwise X11 is returned to indicate the Tk Xlib calls are drawing the themed parts. On Unix systems the result is gtk if the Gtk+ version of treectrl was built, otherwise X11 is returned.
The command is available on MS Windows only. If appname is "Explorer" then the item buttons look like those in the Explorer file browser (disclosure triangles under Windows Vista/7). If appname is an empty string then the buttons revert to their default appearance according to the system's current visual style.
Use item toggle instead.
This command is used to query and change the horizontal position of the information displayed in the treectrl's window. It can take any of the following forms:
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 tree's area is off-screen to the left, the middle 40% is visible in the window, and 40% of the tree is off-screen to the right. These are the same values passed to scrollbars via the -xscrollcommand option.
Adjusts the view in the window so that fraction of the total width of the tree is off-screen to the left. Fraction must be a fraction between 0 and 1. A <Scroll-x> event is generated.
This command shifts the view in the window left or right according to number and what. Number must be an integer. What must be either units or pages or an abbreviation of one of these. If what is units, the view adjusts left or right in units determined by the -xscrollincrement option (which may be zero, see the description of that option). If what is pages then the view adjusts in units of nine-tenths the window's width. If number is negative then information farther to the left becomes visible; if it is positive then information farther to the right becomes visible. A <Scroll-x> event is generated.
This command is used to query and change the vertical position of the information displayed in the treectrl's window. It can take any of the following forms:
Returns a list containing two elements. Each element is a real fraction between 0 and 1; together they describe the vertical span that is visible in the window. For example, if the first element is .6 and the second element is 1.0, the lowest 40% of the tree's area is visible in the window. These are the same values passed to scrollbars via the -yscrollcommand option.
Adjusts the view in the window so that fraction of the tree's area is off-screen to the top. Fraction is a fraction between 0 and 1. A <Scroll-y> event is generated.
This command adjusts the view in the window up or down according to number and what. Number must be an integer. What must be either units or pages. If what is units, the view adjusts up or down in units of the -yscrollincrement option (which may be zero, see the description of that option). If what is pages then the view adjusts in units of nine-tenths the window's height. If number is negative then higher information becomes visible; if it is positive then lower information becomes visible. A <Scroll-y> event is generated.
A treectrl widget can display zero or more rows of column headers. When a treectrl widget is created, a single row of column headers (aka a header-row) is created as well; this top header-row cannot be deleted. Additional header-rows can be created with the header create command and deleted with header delete.
There are no commands for changing the order of header-rows; they are displayed from top to bottom in the order they were created.
Drag-and-drop reordering of column headers is supported within a widget. To control column header drag-and-drop, use the header dragconfigure command.
Header-rows in a treectrl may be specified in a number of ways. See HEADER DESCRIPTION below.
The appearance of individual column headers within a header-row may be customized in two different ways:
By configuring various column header options with the header configure command
By assigning a style to a column header with the header style command.
When one of the options below is specified as per-state, the state names are those described in STATES for headers only, i.e. do not use item state names.
The following options are supported for each individual column header:
Many of the commands for a treectrl take as an argument a description of which header-rows to operate on. A header description is a properly-formed tcl list of keywords and arguments. The first word of a header description must be one of the following:
Specifies a unique header-row identifier, where id should be the return value of a prior call of the header create widget command, or 0 to specify the ever-present top header-row.
Specifies a list of qualifiers. This gives the same result as all followed by QUALIFIERS; i.e., every header-row is tested for a match.
TagExpr is a tag expression (see ITEM AND COLUMN TAGS) against which every header-row's tags are tested for a match. You may run into trouble if tagExpr looks like a header-row id or other keyword; also, tagExpr must look like a single list element since header-row descriptions are properly-formed lists. To be safe you may want to use the tag qualifier followed by tagExpr.
.t header dragconfigure {tag -funky} -draw yes
Matches every header-row which satisfies QUALIFIERS.
Indicates the top header-row of the treectrl, or the first header-row starting from the top that satisfies QUALIFIERS.
Indicates the last header-row which satisfies QUALIFIERS.
The word QUALIFIERS above represents a series of zero or more of the following terms that changes which header-row is chosen:
TagExpr is a tag expression (see ITEM AND COLUMN TAGS) against which a header-row's tags are tested for a match.
When this qualifier is given, only header-rows that are displayed are matched. A header-row is displayed only if both the -showheader widget option and -visible header-row option are true. Also, if only the tail column is visible, then header-rows are not displayed.
When this qualifier is given, only header-rows that are *not* displayed are matched.
A treectrl widget is capable of displaying multiple columns next to each other. An item can be considered as a row, which reaches over all columns.
Columns in a treectrl may be specified in a number of ways. See COLUMN DESCRIPTION below.
There is always one special column, the tail column, which fills all space to the right of the last ordinary column. This column has no unique ID; it can only be specified by the keyword tail.
For compatibility with older versions of treectrl (which did not support more than one row of column headers) any of the configuration options mentioned in the HEADERS section, such as -arrow, -text, etc, may be passed to the top header-row through the column configure command and queried with the column cget command.
The following options are supported for columns:
Many of the commands and options for a treectrl take as an argument a description of which column to operate on. See the EXAMPLES section for examples. The initial part of a column description must begin with one of the following terms:
Specifies the unique column identifier, where id should be the return value of a prior call of the column create widget command. See also the -columnprefix option.
Specifies a list of qualifiers. This gives the same result as all followed by QUALIFIERS; i.e., every column is tested for a match.
TagExpr is a tag expression (see ITEM AND COLUMN TAGS) against which every column's tags are tested for a match. This keyword cannot be followed by any modifiers unless a single column is matched. You may run into trouble if tagExpr looks like a column id or other keyword; also, tagExpr must look like a single list element since column descriptions are properly-formed lists. To be safe you may want to use the tag qualifier followed by tagExpr.
Indicates every column, including the tail column if the command allows it, which match QUALIFIERS.
Indicates the leftmost column of the treectrl which matches QUALIFIERS.
Indicates the rightmost column of the treectrl (but not the tail column) which matches QUALIFIERS.
ColumnDescs is a list (a single argument, i.e. "list {a b c}" not "list a b c") of other column descriptions. This keyword cannot be followed by any modifiers unless a single column is matched.
Indicates the nth column in the list of columns as returned by the column order command.
First and last specify a range of columns. This keyword cannot be followed by any modifiers unless a single column is specified.
Indicates the ever-present tail column of the treectrl.
Indicates the column specified by the -treecolumn option of the treectrl.
The initial part of the column description (matching any of the values above) may be followed by one or more modifiers. A modifier changes the column used relative to the description up to this point. It may be specified in any of the following forms:
Use the column to the right matching QUALIFIERS.
Use the column to the left matching QUALIFIERS.
Starting with (and counting) the single column specified by the column description so far, walk at most N columns rightwards, stopping if any of the following conditions is met:
A column does not match QUALIFIERS.
A column's -lock option does not match the first column's -lock option.
The word QUALIFIERS above represents a sequence of zero or more of the following terms that changes which column is chosen:
TagExpr is a tag expression (see ITEM AND COLUMN TAGS) against which a column's tags are tested for a match.
When this qualifier is given, the tail column is not matched.
When this qualifier is given, only columns whose -visible option is TRUE are considered.
When this qualifier is given, only columns whose -visible option is FALSE are considered.
For every column header and every item a set of boolean states is managed. These states play an integral role in the appearance of headers and items; that role is described in detail in PER-STATE OPTIONS. The set of states available to headers is separate from the set of states available to items.
The following states are predefined for every column header:
These states mirror the value of a column header's configuration option -state. Exactly one of these states is set at any time in each column header.
These states mirror the value of a column header's configuration option -arrow. If the -arrow option is none, then neither of these states is set.
This state is set for every header-row if the toplevel window containing the treectrl is not the foreground active window. This state cannot be modified by means of a widget command, but is maintained in reaction to the <Activate> and <Deactivate> windowing system events.
This state is set for every header-row if the treectrl widget currently has the focus. It cannot be modified by means of a widget command, but is maintained in reaction to the <FocusIn> and <FocusOut> windowing system events.
The following states are predefined for every item:
At all times this state is set for exactly one item. The active item is used with keyboard navigation. When the treectrl widget is created or when the active item is deleted, the root item will become the active item. This state can be modified by means of the widget command activate.
This state is set for every item when it is created. Disabled items cannot be selected and are ignored by the default bindings when navigating via the keyboard. This state can be modified by means of the widget command item enabled.
This state is set for every item if the treectrl widget currently has the focus. It cannot be modified by means of a widget command, but is maintained in reaction to the <FocusIn> and <FocusOut> events.
If this state is switched on, the descendants of the item are displayed - the item is expanded. If this state is switched off, the descendants of the item are not displayed - the item is collapsed. For a new item this state is switched on by default. This state can be modified by means of the widget commands item expand, item collapse, or item toggle.
This state is set for every item included in the selection. It can be modified by means of the widget command selection.
By means of the state define widget command, up to 27 additional states can be defined.
The visual appearance of an item can change depending on the state the item is in, such as being the active item, being included in the selection, being collapsed, or some combination of those or other states. When a configuration option is described as per-state, it means the option describes a value which varies depending on the state of the item. If a per-state option is specified as a single value, the value is used for all states. Otherwise the per-state option must be specified as an even-numbered list. For example, to use the font "Times 12 bold" in a text element regardless of the item state you can write:
$T element configure MyTextElement -font {{Times 12 bold}}
However, to use a different font when the item is selected you could write:
$T element configure MyTextElement -font {{Courier 10} selected {Times 12 bold} {}}
In the example above, the -font option reads "value stateList value stateList". If stateList is an empty list, the preceding value is used regardless of the item state. A non-empty stateList specifies a list of states which must be set for the item in order to use the preceding value. Each stateList can also include state names preceded by a ! sign, indicating the state must *not* be set for the item. For example:
$T element configure MyRectElement -fill {blue {selected focus} gray {selected !focus}}
In the example above, the rect element is filled with blue when the treectrl has the focus and the item is selected. If the treectrl does not have the focus, the example specifies that gray should be used for selected items. Also note that if the item is not selected, no color is specified for the -fill option.
Each value-stateList pair is checked in order from left to right. The value associated with the first stateList that matches the current item state is used. So stateLists should be listed from most-specific to least-specific.
$T element configure MyRectElement -fill {gray {selected} blue {selected focus}}
Written this way, gray will always be used for selected items since it appears first, and blue will never be used for selected items regardless of the focus.
A value followed by an empty stateList should always be last since it will be chosen regardless of the item's state.
Elements and styles are the core visual building blocks that determine the appearance of items (and optionally column headers). An element can be of type bitmap, border, header, image, rect, text or window. One or more elements can be assigned to a style which manages the layout of those elements. It may be helpful to think of an element as a Tk widget and a style as a Tk geometry manager such as grid, pack or place.
When an element is created by the element create command, that element is referred to as a master element. Similarly, a style that is created by style create is called a master style. When a master style is assigned to a column of an item by the item style set command, a new instance style is allocated which refers back to the master style and its master elements. In this way, a single master style may be shared by multiple columns of multiple items. If a master element or master style is modified, those changes affect all the items whose instance styles and elements refer to those masters.
Although you probably want the font and selection-rectangle colors to be shared by all items, you most likely don't want the text to be the same for every column of every item. The item element configure command can be used to override a master element's configuration options for a specific column of an item. When you call item element configure (or item text or item image), a new instance element is allocated, if one wasn't already, and that instance element's options will override the master element's.
All of the element configuration options described below are unspecified by default, meaning that no value whatsoever has been given to the option. It may seem strange to you that a boolean option would be unspecified instead of simply "true" or "false". The reason for this is that when an instance element used by an item has no value specified for an option, that instance element refers to the master element for the value of that option. This allows items which are displaying a certain element to be redisplayed when the master element's options change. The benefits of this are that you don't need to configure the font or text color for every item in a treectrl individually, saving CPU cycles and memory.
You may be thinking that to change the color of a selection rectangle you would call item element configure when an item was selected, but that is not usually the case. It would be wasteful to allocate a new instance element for a selection rectangle just because an item became selected. The solution is to allow the appearance of the selection rectangle master element to change based on the selected state of the item. This is described in PER-STATE OPTIONS.
For each element type there is a section below describing the options which can modify an element of that type.
An element of type bitmap can be used to display a bitmap in an item. The following options are supported for bitmap elements:
An element of type border can be used to display a 3D border in an item. The following options are supported for border elements:
An element of type header can be used to display a themed (or non-themed) column header background and sort arrow. Header elements are best used surrounding other elements via the style layout option -union, so that the sort arrow can be displayed correctly.
Some of the options for this type of element get their default values from the header state flags that are set in the column header in which the element is displayed. In particular, the -arrow option gets its default value by checking the up and down state flags, and the -state option gets its default value by checking the active, normal, and pressed state flags. If elements of this type are displayed in an item instead of a column header, then this behavior isn't used since those state flags aren't meaningful for items.
The following options are supported for header elements:
An element of type image can be used to display an image in an item. The following options are supported for image elements:
An element of type rect can be used to display a rectangle in an item. The following options are supported for rectangle elements:
An element of type text can be used to display a text in an item. The following options are supported for text elements:
An element of type window can be used to display a Tk window in an item. The following options are supported for window elements:
Many of the commands for a treectrl take as an argument a description of which items to operate on. An item description is a properly-formed tcl list of keywords and arguments. The first word of an item description must be one of the following:
Specifies the unique item identifier, where id should be the return value of a prior call of the item create widget command, or 0 to specify the ever-present root item. See also the -itemprefix option.
Specifies a list of qualifiers. This gives the same result as all followed by QUALIFIERS; i.e., every item is tested for a match.
TagExpr is a tag expression (see ITEM AND COLUMN TAGS) against which every item's tags are tested for a match. This keyword cannot be followed by any modifiers unless a single item is matched. You may run into trouble if tagExpr looks like an item id or other keyword; also, tagExpr must look like a single list element since item descriptions are properly-formed lists. To be safe you may want to use the tag qualifier followed by tagExpr.
Indicates the item that is currently active, i.e. normally the item specified as argument of the last successful activate widget command, or the root item if no such call happened yet.
Indicates the anchor item of the selection, i.e. normally the item specified as argument of the last successful selection anchor widget command, or the root item if no such call happened yet.
Indicates every item including orphans which match QUALIFIERS. This keyword cannot be followed by any modifiers unless a single item is matched.
Indicates the first item of the treectrl (the root item), or the first item matching QUALIFIERS.
Indicates the last item which matches QUALIFIERS.
ItemDescs is a list (a single argument, i.e. "list {a b c}" not "list a b c") of other item descriptions. This keyword cannot be followed by any modifiers unless a single item is matched.
Indicates the item nearest to the point given by x and y.
Indicates the item in the given row and column. The row and column corresponds to the on-screen arrangement of items as determined by the -orient and -wrap options. You can memorize rnc as an abbreviation of "row 'n' column".
First and last specify a range of items. This keyword cannot be followed by any modifiers unless a single item is matched.
Indicates the root item of the treectrl.
The initial part of the item description (matching any of the values above) may be followed by one or more modifiers. A modifier changes the item used relative to the description up to this point. It may be specified in any of the following forms:
Use the item one row above in this column.
Use the ancestors of the item (like item ancestors but QUALIFIERS may change which ancestors match). This keyword cannot be followed by any modifiers.
Use the item one row below in this column.
Use the item in the last row of this column.
Use the nth child of the item.
Use the children of the item (like item children but QUALIFIERS may change which children match). This keyword cannot be followed by any modifiers.
Use the descendants of the item (like item descendants but QUALIFIERS may change which descendants match). This keyword cannot be followed by any modifiers.
Use the first child of the item.
Use the last child of the item.
Use the item one column to the left in the same row.
Use the item of the first column in the same row.
Use the next item, which is the first item from the following list: the first child, the next sibling or the next sibling of the nearest ancestor which has one.
Use the next sibling of the item.
Use the parent of the item.
Use the last child of the previous sibling, or the parent if there is no previous sibling.
Use the previous sibling of the item.
Use the item one column to the right in the same row.
Use the item of the last column in the same row.
Use the nth child of the item's parent.
Use the item in the first row of this column.
The word QUALIFIERS above represents a series of zero or more of the following terms that changes which item is chosen:
Matches items whose depth (as returned by the depth command) is equal to depth.
StateList is a list of item state names (static and dynamic, see STATES). Only items that have the given states set (or unset if the '!' prefix is used) are considered.
TagExpr is a tag expression (see ITEM AND COLUMN TAGS) against which an item's tags are tested for a match.
When this qualifier is given, only items that are displayed are considered.
When this qualifier is given, only items that are *not* displayed are considered.
To get the first item in the list that is enabled:
$T item id "first state enabled"
To get the ancestors that are not open of the last item in the list:
$T item id "last ancestors state !open"
To get the visible descendants of the root item:
$T item id "root descendants visible"
To get the every hidden item with tag "a" or "b":
$T item id "all !visible tag a||b" $T item id "!visible tag a||b" $T item id "tag a||b !visible" $T item id "a||b !visible"
The script argument to notify bind is a Tcl script, which will be evaluated whenever the given event is generated. Script will be executed in the same interpreter that the notify bind command was executed in, and it will run at global level (only global variables will be accessible). If script contains any % characters, then the script will not be evaluated directly. Instead, a new script will be generated by replacing each %, and the character following it, with information from the current event. Unlike the regular Tk bind mechanism, each event generated by a treectrl widget has its own set of %-substitutions.
The following %-substitutions are valid for all static events:
The following events may be generated by a treectrl widget:
Generated whenever the active item changes.
Generated before an item is collapsed.
Generated after an item is collapsed.
Generated before an item is expanded. This event is useful if you want to add child items to the item just before the item is expanded.
Generated after an item is expanded.
Generated when items are about to be deleted by the item delete command.
Generated when items become visible on screen and when items are no longer visible on screen. This event is useful if you have a very large number of items and want to assign styles only when items are actually going to be displayed.
Generated whenever the view in the treectrl changes in such a way that a horizontal scrollbar should be redisplayed.
Generated whenever the view in the treectrl changes in such a way that a vertical scrollbar should be redisplayed.
Generated whenever the selection changes. This event gives information about how the selection changed.
In addition to the pre-defined static events such as <ActiveItem> and <Selection>, new dynamic events can be created by using the notify install command.
The library scripts provide an example of using a dynamic event called <Header-invoke>, which is generated when the mouse button is clicked and released over a column header.
# Example application code treectrl .t .t notify install <Header-invoke> .t notify bind MyTag <Header-invoke> { puts "column header %C clicked in header-row %H in treectrl %T" } # Library code in treectrl.tcl proc ::TreeCtrl::Release1 {w x y} { ... $w notify generate <Header-invoke> [list H $Priv(header) C $Priv(column)] \ [list ::TreeCtrl::PercentsCmd $w] ... }
In the example above, a new treectrl widget is created and the <Header-invoke> event is installed. A script is bound to the event with notify bind which will print out the column ID, header ID and widget name to the console. In a real application, any script bound to <Header-invoke> would be used to sort the list based on the column header that was clicked.
Note there is no percentsCommand argument to notify install; instead, the call to notify generate specifies the %-substitution command. The charMap argument to notify generate provides a list of %-substitution characters and values which is used by ::TreeCtrl::PercentsCmd. In the example, any %C in any script bound to the <Header-invoke> event would be replaced by the value of $Priv(column), and %H would be replaced by $Priv(header). The library procedure ::TreeCtrl::PercentsCmd also supports the same common %-substitution characters as the built-in static events, such as %T, %P, %? etc.
The following dynamic events may be generated by the library scripts:
This event is generated just after the user begins dragging a column header. At the time this event is generated, the header dragconfigure option -imagecolumn is set to the unique ID of the column being dragged, the -imageoffset option is set to the horizontal distance the mouse pointer has moved, and the -imagespan option is set to the span of the column header that was initially clicked.
This event is generated each time a new place to drop the dragged column header is found. At the time this event is generated, the header dragconfigure option -indicatorcolumn is set to the unique ID of the column before or after which the dragged column will be dropped, and the -indicatorspan option is set to the span of the column header for this newly-chosen indicator column.
This event is generated when the user has successfully dragged and dropped a column header to a new position. The library scripts do not actually move the dragged column. You must bind a script to this event to move the column. See EXAMPLES.
This event is generated after the user finally releases the left mouse button while dragging a column header. This event is generated after all the other <ColumnDrag> events even when the column wasn't dragged to a new location (i.e., even when no <ColumnDrag-receive> event was generated).
Generated whenever the user drag-and-drops a file into a directory. This event is generated by the filelist-bindings.tcl library code, which is not used by default. See the "Explorer" demos.
The filelist-bindings.tcl code will display a text-editing window if the user clicks on a selected file/folder name. See the "Explorer" demos.
Generated whenever the user clicks and releases the left mouse button in a column header if the column header's -button option is true. You can bind a script to this event to sort the list.
Generated when the column header option -state is changed by the library scripts during Motion and Button events.
Tk automatically creates class bindings for treectrl widgets that give them the following default behavior.
Clicking mouse button 1 over an item positions the active cursor on the item, sets the input focus to this widget, and resets the selection of the widget to this item, if it is not already in the selection.
Clicking mouse button 1 with the Control key down will reposition the active cursor and add the item to the selection without ever removing any items from the selection.
If the mouse is dragged out of the widget while button 1 is pressed, the treectrl will automatically scroll to make more items visible (if there are more items off-screen on the side where the mouse left the window).
The Left and Right keys move the active cursor one item to the left or right; for an hierarchical tree with vertical orientation nothing will happen, since it has no two items in the same row. The selection is set to include only the active item. If Left or Right is typed with the Shift key down, then the active cursor moves and the selection is extended to include the new item.
The Up and Down keys move the active cursor one item up or down. The selection is set to include only the active item. If Up or Down is typed with the Shift key down, then the active cursor moves and the selection is extended to include the new item.
The Next and Prior keys move the active cursor forward or backwards by one screenful, without affecting the selection.
Control-Next and Control-Prior scroll the view right or left by one page without moving the active cursor or affecting the selection. Control-Left and Control-Right behave the same.
The Home and End keys scroll to the left or right end of the widget without moving the active cursor or affecting the selection.
The Control-Home and Control-End keys scroll to the top or bottom of the widget, they also activate and select the first or last item. If also the Shift key is down, then the active cursor moves and the selection is extended to include the new item.
The Space and Select keys set the selection to the active item.
Control-/ selects the entire contents of the widget.
Control-\\ clears any selection in the widget.
The + and - keys expand or collapse the active item, the Return key toggles the active item.
The mousewheel scrolls the view of the widget four lines up or down depending on the direction, the wheel was turned. The active cursor or the selection is not affected.
Color gradients are an easy way to give your lists a more modern appearance. Since Tk provides no support for drawing gradients, the TkPath extension was used as a guide when implementing gradients in TkTreeCtrl. The current implementation has some limitations, however:
Only linear gradients are supported.
Gradients can only be painted left-to-right or top-to-bottom, not at arbitrary angles.
Gradients look bad on low-color displays. Before using gradients, you should check that the display's color depth is at least 15 or 16 by calling the winfo depth command.
Gradients are fully opaque when XFillRectangle() is used to draw them (see below). This means the opacity value of each color stop is ignored. Keep that in mind if your application is cross-platform.
Rounded rectangles cannot be filled or outlined with a gradient when XFillRectangle() is used to draw gradients (see below). Instead, the rounded rectangle is painted with the gradient's first -stops color.
Gradients may be used in the following places:
The -gridleftcolor and -gridrightcolor options of columns.
The -itembackground option of columns.
The -fill and -outline options of rect elements.
The -fill and -outline options of the marquee configure command.
On Microsoft Windows, GDI+ is used where it is available (gdiplus.dll is dynamically loaded at run-time). On Mac OS X, CoreGraphics is used to draw gradients. With the Gtk+ build of treectrl, libcairo is used to draw gradients. When native gradient support is available, all the talk below about -steps can safely be ignored.
When no native support for gradients is available, gradients are drawn simply by filling sub-rectangles using XFillRectangle(). The number of sub-rectangles drawn and number of colors that make up the displayed gradient are controlled by the gradient's -steps and -stops options. The number of sub-rectangles is equal to the length of the -stops option multiplied by the value of the -steps option. For example:
$T gradient create myGradient -stops {{0 white} {1 gray}} -steps 8
This gradient will be drawn with 2x8=16 sub-rectangles of color. The higher the -steps value, the smoother the color transitions will be, and the slower the gradient will be to draw. For the best appearance, make the number of sub-rectangles drawn less than or equal to the height or width of the gradient being drawn. So if you have a rect element 18 pixels tall, use a vertical gradient that has steps X stops=18. Avoid using gradients with steps X stops greater than the height or width of the rectangle being drawn, because then colors will overlap.
By default, a gradient brush is exactly the same size as whatever rectangle is being painted. For example, if a column's -itembackground option specifies a gradient name, then the background of an item is painted with all the colors of the gradient. So a vertical gradient from blue to green will start blue at the top and end with green at the bottom of every item.
By specifying any of the -bottom, -left, -right or -top gradient options the size of the gradient brush does not need to match that of the rectangle being painted. These options can be used to make a gradient appear to span across the entire width or height of the treectrl window, or across the entire canvas, for example.
There is no point specifying -left or -right if the gradient is vertical, since the gradient's colors are constant horizontally, so changing the horizontal size of the brush won't change the appearance of the gradient. The same reasoning applies for the -top and -bottom options for a horizontal gradient.
package require treectrl set T [treectrl .t -itemheight 20 -showheader no] $T gradient create G1 -orient vertical -top {0.0 canvas} -bottom {1.0 canvas} \ -stops {{0.0 blue} {0.5 green} {1.0 red}} -steps 25 $T column create -expand yes -itembackground G1 pack $T -expand yes -fill both
Get the unique identifier for the leftmost visible column:
set id [$T column index "first visible"]
Delete the leftmost column:
$T column delete "order 0"
Take the visible column that is to the left of the last column, and move that column in front of the tail column:
$T column move "last prev visible" tail
Get the unique identifier for the first visible item:
set id [$T item index "first visible"]
Delete the parent of the item that is under the point x,y:
$T item delete "nearest $x $y parent"
Add the 10th child of the second child of the root item to the selection:
$T selection add "root firstchild nextsibling child 10"
Move a column that the user drag-and-dropped:
$T header dragconfigure -enable yes $T notify install <ColumnDrag-receive> $T notify bind MyTag <ColumnDrag-receive> { %T column move %C %b }
bind(n), bitmap(n), image(n), listbox(n), options(n)
tree, widget