blt::treeview(3tcl)
๐ธ blt::treeview โ NAME ๐
treeview โ bestie, this is the one that creates and manipulates hierarchical table widgets. It lives in BLT Built-In Commands (that's the blt::treeview(3tcl) energy, iykyk).
โจ SYNOPSIS โจ
treeview pathName ?options?
๐ DESCRIPTION ๐
Okay so the treeview widget shows you a tree of data. It's the glow-up replacement for both the hiertable and hierbox widgets. And listen โ the treeview is 100% syntax compatible with the hiertable widget. The hiertable command is still hanging around purely for script-level compatibility reasons (legacy bestie, we still love her). Meanwhile this widget obsoletes the hierbox widget entirely โ it does everything the old hierbox did, but it ALSO gives you data sharing (through tree data objects) and the ability to tag nodes. Obsessed, honestly. ๐
๐ฆ INTRODUCTION ๐ฆ
The treeview widget displays hierarchical data. Data is represented as nodes in a general-ordered tree. Each node may have sub-nodes, and those nodes can in turn have their own children. It's giving family tree, but make it data.
A node is displayed as a row entry in the widget. Each entry has a text label and an icon. When a node has children, its entry is drawn with a little button to the left of the label. Clicking the mouse over that button opens or closes the node. When a node is open, its children are exposed. When it's closed, the children and their descendants are hidden. That button is normally a + or - symbol (ala Windows Explorer), but it can be swapped out for a pair of Tk images (open and closed images). Cute, right? ๐
If the node has data associated with it, that data can be displayed in columns running vertically on either side of the tree. You can control the color, font, etc. of each entry. And any entry label or data field can be edited in-place. Main character behavior. ๐
๐ TREE DATA OBJECT ๐
Big important thing: the tree is not stored inside the widget โ it lives in a tree data object (peep the tree command for a fuller explanation, bestie). Tree data objects can be shared among different clients, like a treeview widget or the tree command. You can walk the tree and manage its data with the tree command tree, while displaying it with the treeview widget. And whenever the tree gets updated, the treeview widget is automatically redrawn. No manual refreshing, we love a self-sufficient icon. โจ
By default, the treeview widget creates its own tree object. That tree initially contains just a root node. But you can also display trees created by the tree command using the -tree configuration option. And yes โ multiple treeview widgets can share the same tree object, possibly displaying different views of the same data. Sharing is caring fr fr.
A tree object has both a Tcl and a C API. You can insert or delete nodes using treeview widget or tree command operations, but also from C code. Like, you could load the tree from your C code while still managing and displaying the tree from Tcl. The widget gets automatically notified whenever the tree is modified via C or Tcl. She's always paying attention. ๐
๐ธ SYNTAX ๐ธ
treeview pathName ?option value?...
The treeview command creates a new window pathName and makes it into a treeview widget. At the time this command is invoked, there must not already exist a window named pathName โ but pathName's parent must exist. Additional options may be specified on the command line or in the option database to configure aspects of the widget such as its colors and font. See the configure operation below for the exact details about what option and value pairs are valid.
If successful, treeview returns the path name of the widget. It also creates a new Tcl command by the same name. You can use this command to invoke various operations that query or modify the widget. The general form is:
pathName operation ?arg?...
Both operation and its arguments determine the exact behavior of the command. The operations available are described in the TREEVIEW OPERATIONS section.
๐ IDS AND TAGS ๐
Nodes can be inserted into a tree using the treeview widget:
blt::treeview .t
set node [.t insert end root "one"]
...or the tree command:
set tree [blt::tree create]
set node [$tree insert root "one"]
In both cases, a number identifying the node is returned (the value of $node). This serial number or id uniquely identifies the node. Please note โ and this is important, bestie โ you can't infer a location or position of a node from its id. The only exception is that the root node is always id 0. Since nodes may have the same labels or be moved within the tree, ids provide a convenient way to identify nodes. If a tree is shared, the ids will be the same regardless of whether you're using the treeview widget or the tree command. Ids are recycled when the node is deleted. โป๏ธ
A node may also have any number of tags associated with it. A tag is just a string of characters, and it may take any form except that of an integer. For example, "x123" is valid, but "123" isn't. The same tag may be associated with many different nodes โ this is typically done to associate a group of nodes. Many operations in the treeview widget take either node ids or tag names as arguments. Using a tag says to apply the operation to all nodes with that tag.
The tag all is implicitly associated with every node in the tree. It may be used to invoke operations on all the nodes in the tree. ๐ซ
Tags may be shared, just like trees, between clients. For example, you can use the tags created by the tree command with treeview widgets.
๐ SPECIAL NODE IDS ๐
There are also several special non-numeric ids. Special ids differ from tags in that they are always translated to their numeric equivalent. They also take precedence over tags. So for example, you can't use a tag name that is a special id. These ids are specific to the treeview widget.
activeโ The node where the mouse pointer is currently located. When a node is active, it is drawn using its active icon (see the-activeiconoption). Theactiveid is changed automatically by moving the mouse pointer over another node or by using theentry activateoperation. Note that there can be only one active node at a time.anchorโ The node representing the fixed end of the current selection. The anchor is set by theselection anchoroperation.currentโ The node where the mouse pointer is currently located. But unlikeactive, this id changes while the selection is dragged. It is used to determine the current node during button drags.downโ The next open node from the currentfocus. Thedownof the last open node is the same.endโ The last open node (in depth-first order) on the tree.focusโ The node that currently has focus. When a node has focus, it receives key events. To indicate focus, the node is drawn with a dotted line around its label. You can change the focus using thefocusoperation.lastโ The last open node from the currentfocus. But unlikeup, when the focus is at root,lastwraps around to the last open node in the tree.markโ The node representing the non-fixed end of the current selection. The mark is set by theselection markoperation.nextโ The next open node from the currentfocus. But unlikedown, when the focus is on the last open node,nextwraps around to the root node.nextsiblingโ The next sibling from the node with the currentfocus. If the node is already the last sibling then it is thenextsibling.parentโ The parent of the node with the currentfocus. The parent of the root is also the root.prevsiblingโ The previous sibling from the node with the currentfocus. If the node is already the first sibling then it is theprevsibling.rootโ The root node. You can also use id0to indicate the root.upโ The last open node (in depth-first order) from the currentfocus. Theupof the root node (i.e. the root has focus) is also the root.view.topโ First node that's currently visible in the widget.view.bottomโ Last node that's currently visible in the widget.pathโ Absolute path of a node. Path names refer to the node name, not their entry labels. Paths don't have to start with a separator (see the-separatorconfiguration option), but component names must be separated by the designated separator.@x,yโ Indicates the node that covers the point in the treeview window specified byxandy(in pixel coordinates). If no part of the entry covers that point, then the closest node to that point is used.
A node may be specified as an id or a tag. If the specifier is an integer then it is assumed to refer to the single node with that id. If the specifier is not an integer, it's checked to see if it's a special id (such as focus). Otherwise, it's assumed to be a tag. Some operations only operate on a single node at a time; if a tag refers to more than one node, then an error is generated. ๐ญ So watch out for that one.
๐ DATA FIELDS ๐
A node in the tree can have data fields. A data field is a name-value pair, used to represent arbitrary data in the node. Nodes can contain different fields (they aren't required to contain the same fields). You can optionally display these fields in the treeview widget in columns running on either side of the displayed tree. A node's value for the field is drawn in the column alongside its node in the hierarchy. Any node that doesn't have a specific field is left blank. Columns can be interactively resized, hidden, or moved. Slay. ๐
๐ง ENTRY BINDINGS ๐ง
You can bind Tcl commands to be invoked when events occur on nodes (much like Tk canvas items). You can bind a node using its id or its bindtags. Bindtags are simply names that associate a binding with one or more nodes. There is a built-in tag all that all node entries automatically have. Built-in, bestie. Free of charge. ๐ซถ
๐ฅ TREEVIEW OPERATIONS ๐ฅ
The treeview operations are invoked by specifying the widget's pathname, the operation, and any arguments that pertain to that operation. The general form is:
pathName operation ?arg arg ...?
operation and the args determine the exact behavior of the command. The following operations are available for treeview widgets:
pathName bbox ?-screen? tagOrId...
okay so this one hands you the bounding box โ that lil rectangle that wraps around whatever entries you point at ๐
You pass in one or more tagOrId arguments and it gives you back a list of 4 numbers that describe the box around those entries. Want the coords in screen terms instead of virtual ones? Slap on the -screen flag and the x-y coordinates come back as screen coordinates, not virtual coordinates. (iykyk: virtual coordinates start from 0 from the root node ๐ฑ)
The returned list has these four values, in order:
xโ X-coordinate of the upper-left corner of the bounding box.yโ Y-coordinate of the upper-left corner of the bounding box.widthโ Width of the bounding box.heightโ Height of the bounding box.
pathName bind tagName ?sequence command?
This is the glue โจ It associates command with tagName so that whenever the event sequence happens on a node carrying that tag, command gets invoked. The syntax is basically the same as the bind command โ except this one operates on treeview entries instead of widgets. For the full tea on sequence and all the substitutions done to command before it's invoked, go read the bind manual entry ๐ซถ
Now the rules, bestie, listen up:
- Give it all the arguments and a fresh binding gets created, replacing any existing binding for the same
sequenceandtagName. - If the first character of
commandis+, thencommandaugments an existing binding instead of replacing it. - No
commandargument? Then you get back the command currently associated withtagNameandsequenceโ and yep, it's an error if there's no such binding ๐ญ - Both
commandandsequencemissing? Then you get a list of all the event sequences for which bindings have been defined fortagName.
pathName button operation ?args?
This is your remote control for the button selectors inside a treeview widget ๐๏ธ It's got a few forms, depending on operation:
pathName button activate tagOrId
Designates the node given by tagOrId as active ๐
When a node is active, its entry is drawn using its active icon (see the -activeicon option). Heads up though โ there can be only one active entry at a time. The special id active points at the currently active node ๐
pathName button bind tagName ?sequence command?
Associates command with tagName so that whenever the event sequence occurs for a button of a node entry with this tag, command gets invoked. Same deal as the bind command syntax-wise โ except it operates on treeview buttons, not widgets. Again, the bind manual entry has all the deets on sequence and the substitutions done to command before invoking ๐ซถ
The rules, once more for the people in the back:
- All arguments specified โ a new binding is created, replacing any existing binding for the same
sequenceandtagName. - First character of
commandis+โcommandaugments an existing binding rather than replacing it. - No
commandargument โ the command currently associated withtagNameandsequenceis returned (and yes, it's an error if there's no such binding ๐ญ). - Both
commandandsequencemissing โ a list of all the event sequences for which bindings have been defined fortagName.
pathName button cget option
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the configure operation described below โฌ๏ธ
pathName button configure ?option? ?value option value ...?
Query or modify the configuration options of the widget ๐ ๏ธ
- No option specified โ returns a list describing all the available options for
pathName(peepTk_ConfigureInfofor info on the format of this list). - option specified with no value โ returns a list describing that one named option (this list will be identical to the corresponding sublist of the value returned when no option is specified).
- One or more option-value pairs โ the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string.
Option and value are described in the section BUTTON OPTIONS below.
pathName cget option
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the configure operation described below โฌ๏ธ
pathName close ?-recurse? tagOrId...
Closes the node specified by tagOrId ๐ช In addition, if a Tcl script was specified by the -closecommand option, it is invoked. If the node is already closed, this command has no effect โ it's giving "nothing to see here." If the -recurse flag is present, each child node is recursively closed ๐
pathName column operation ?args?
The following operations are available for treeview columns ๐
pathName column activate column
Sets the active column to column. Column is the name of a column in the widget. When a column is active, it's drawn using its -activetitlebackground and -activetitleforeground options ๐จ If column is the "", then no column will be active. If no column argument is provided, then the name of the currently active column is returned ๐
pathName column cget name option
Returns the current value of the column configuration option given by option for name. Name is the name of a column that corresponds to a data field. Option may have any of the values accepted by the configure operation described below โฌ๏ธ
pathName column configure name ?option? ?value option value ...?
Query or modify the configuration options of the column designated by name. Name is the name of the column corresponding to a data field ๐
- No option specified โ returns a list describing all the available options for
pathName(seeTk_ConfigureInfofor the format of this list). - option specified with no value โ returns a list describing that one named option (identical to the corresponding sublist of the value returned when no option is specified).
- One or more option-value pairs โ the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string.
Option and value are described in the section COLUMN OPTIONS below.
pathName column delete field ?field...?
Deletes one or more columns designated by field ๐๏ธ Note: this does not delete the data fields themselves โ those stay put, bestie, this is purely a visual thing ๐
pathName column insert position field ?options...?
Inserts one or more columns designated by field โ A column displays each node's data field by the same name. If the node doesn't have the given field, the cell is left blank. Position indicates where in the list of columns to add the new column โ it may be either a number or end.
pathName column invoke field
Invokes the Tcl command associated with the column field, if there is one (using the column's -command option) ๐ช The command is ignored if the column's -state option is set to disabled.
pathName column move name dest
Moves the column name to the destination position ๐ Dest is the name of another column, or a screen position in the form @x,y.
pathName column names
Returns a list of the names of all columns in the widget ๐ The list is ordered the way the columns are drawn, left-to-right.
pathName column nearest x ?y?
Returns the name of the column closest to the given X-Y screen coordinate ๐ฏ If you provide a y argument (it's optional!), a name is returned only when the point is over a column's title.
pathName configure ?option? ?value option value ...?
Query or modify the configuration options of the widget ๐ ๏ธ
- No option specified โ returns a list describing all the available options for
pathName(seeTk_ConfigureInfofor info on the format of this list). - option specified with no value โ returns a list describing that one named option (this list will be identical to the corresponding sublist of the value returned when no option is specified).
- One or more option-value pairs โ the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string.
Option and value are described in the section TREEVIEW OPTIONS below.
pathName curselection
Returns a list containing the ids of all of the entries that are currently selected ๐ซถ If there are no entries selected, then the empty string is returned.
pathName delete tagOrId...
Deletes one or more entries given by tagOrId and its children ๐ (yes, the whole lil family goes, sorry not sorry).
pathName entry operation ?args?
The following operations are available for treeview entries ๐
pathName entry activate tagOrId
Sets the active entry to the one specified by tagOrId. When an entry is active it is drawn using its active icon (see the -activeicon option) โจ Note that there can be only one active node at a time. The special id of the currently active node is active ๐
pathName entry cget option
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the configure operation described below โฌ๏ธ
okay bestie we're back in the operations and it does NOT stop being a lot ๐ every single one of these is a real command you can actually call, no cap, so let's go one by one.
pathName entry children โ the group chat, but for one node's kids ๐ถ
pathName entry children tagOrId ?first? ?last?
Returns a list of ids for the given range of children of tagOrId. tagOrId is the id or tag of the node you're snooping on. If you pass only a first argument, then you get back the id of the child sitting at that numeric position โ just the one. If both first and last are given, you get the ids of every child in that range. Otherwise? Every child. All of them. The whole squad. ๐
pathName entry configure โ the makeover station โจ
pathName entry configure ?option? ?value option value ...?
Query or modify the configuration options of the widget, iconic behaviour.
- No
optionat all? You get a list describing all the available options forpathName(peepTk_ConfigureInfofor info on the format of that list, iykyk). optionwith novalue? You get a list describing just that one named option. And bestie, that list is identical to the corresponding sublist of the value you'd get if you'd specified no option at all. Same thing, smaller portion ๐.- One or more
option-valuepairs? The command modifies the given widget option(s) to have the given value(s), and in this case it returns an empty string. Nothing. Silence. ๐
Option and value are described below, so keep scrolling bestie.
pathName entry delete โ bye bye bestie ๐
pathName entry delete tagOrId ?first ?last?
Deletes the one or more children nodes of the parent tagOrId. If first and last are present, they're positions designating a range of children nodes to be deleted. Rude but necessary ๐
pathName entry isbefore โ the lineup check ๐ซถ
pathName entry isbefore tagOrId1 tagOrId2
Returns 1 if tagOrId1 is before tagOrId2 and 0 otherwise. That's it, that's the whole thing.
pathName entry ishidden โ vibe check: hiding? ๐
pathName entry ishidden tagOrId
Returns 1 if the node is currently hidden and 0 otherwise. And lowkey important: a node is also hidden if any of its ancestor nodes are closed or hidden. So it's giving inherited invisibility, not main character energy ๐
pathName entry isopen โ vibe check: open? ๐ธ
pathName entry isopen tagOrId
Returns 1 if the node is currently open and 0 otherwise.
pathName entry size โ headcount, optionally recursive ๐ฅ
pathName entry size -recurse tagOrId
Returns the number of children for parent node tagOrId. If the -recurse flag is set, then the number of all its descendants is returned. And no, the node itself is not counted. She's not her own child, that's not the vibe. ๐
pathName find โ the search era ๐
pathName find ?flags? first last
Finds all entries matching the criteria given by flags. A list of ids for all matching nodes gets returned. first and last are ids designating the range of the search in depth-first order. And plot twist: if last is before first, then nodes are searched in reverse order ๐ฆ
The valid flags are:
-namepattern โ Specifies pattern to match against node names.-fullpattern โ Specifies pattern to match against node pathnames.-optionpattern โ Specifies pattern to match against the node entry's configuration option.-exactโ Patterns must match exactly. This is the default.-globโ Use global pattern matching. Matching is done in a fashion similar to that used by the C-shell. For the two strings to match, their contents must be identical except that the following special sequences may appear in pattern:*โ Matches any sequence of characters in string, including a null string.?โ Matches any single character in string.[chars]โ Matches any character in the set given by chars. If a sequence of the formx-yappears in chars, then any character betweenxandy, inclusive, will match.\xโ Matches the single characterx. This provides a way of avoiding the special interpretation of the characters*?[]\in the pattern.
-regexpโ Use regular expression pattern matching (i.e. the same as implemented by theregexpcommand).-nonmatchingโ Pick entries that don't match. Not like other girls ๐-execstring โ Specifies a Tcl script to be invoked for each matching node. Percent substitutions are performed on string before it is executed. The following substitutions are valid:%Wโ The pathname of the widget.%pโ The name of the node.%Pโ The full pathname of the node.%#โ The id of the node.%%โ Translates to a single percent.
-countnumber โ Stop searching after number matches.--โ Indicates the end of flags.
pathName focus โ she's the main character now ๐
pathName focus tagOrId
Sets the focus to the node given by tagOrId. When a node has focus, it can receive keyboard events. The special id focus designates the node that currently has focus. Periodt. โจ
pathName get โ ids to names, the glow-up ๐
pathName get ?-full? tagOrId tagOrId...
Translates one or more ids to their node entry names. It returns a list of names for all the ids specified. If the -full flag is set, then the full pathnames are returned instead. Casual vs. formal, your choice ๐
pathName hide โ making things vanish ๐
pathName hide ?flags? tagOrId...
Hides all nodes matching the criteria given by flags. The search is performed recursively for each node given by tagOrId. The valid flags are described below:
-namepattern โ Specifies pattern to match against node names.-fullpattern โ Specifies pattern to match against node pathnames.-optionpattern โ Specifies pattern to match against the node entry's configuration option.-exactโ Match patterns exactly. This is the default.-globโ Use global pattern matching. Matching is done in a fashion similar to that used by the C-shell. For the two strings to match, their contents must be identical except that the following special sequences may appear in pattern:*โ Matches any sequence of characters in string, including a null string.?โ Matches any single character in string.[chars]โ Matches any character in the set given by chars. If a sequence of the formx-yappears in chars, then any character betweenxandy, inclusive, will match.\xโ Matches the single characterx. This provides a way of avoiding the special interpretation of the characters*?[]\in the pattern.
-regexpโ Use regular expression pattern matching (i.e. the same as implemented by theregexpcommand).-nonmatchingโ Hide nodes that don't match. Chaotic, honestly. Respect. ๐--โ Indicates the end of flags.
pathName index โ where does this point, actually ๐ง
pathName index ?-at tagOrId? string
Returns the id of the node specified by string. String may be a tag or node id. Some special ids are normally relative to the node that has focus. The -at flag lets you select another node, so you're not stuck with whatever's focused. Slay ๐ซถ
pathName insert โ new node just dropped ๐ฆ
pathName insert ?-at tagOrId? position path ?options...? ?path? ?options...?
Inserts one or more nodes at position. Position is the location (number or end) where the new nodes are added to the parent node. Path is the pathname of the new node. Pathnames can be formated either as a Tcl list (each element is a path component) or as a string separated by a special character sequence (using the -separator option). Pathnames are normally absolute, but the -at switch lets you select a relative starting point โ its value is the id of the starting node.
Okay so the rules, listen up:
- All ancestors of the new node must already exist, unless the
-autocreateoption is set. - It is also an error if a node already exists, unless the
-allowduplicatesoption is set.
Option and value may have any of the values accepted by the entry configure operation described in the ENTRY OPERATIONS section below. This command returns a list of the ids of the new entries. Obsessed. ๐
pathName move โ relocation, but make it cute ๐ฆ
pathName move tagOrId how destId
Moves the node given by tagOrId to the destination node. The node can not be an ancestor of the destination โ no putting a node inside its own descendant, that's a paradox bestie ๐ญ. DestId is the id of the destination node and can not be the root of the tree. In conjunction with how, it describes how the move is performed.
beforeโ Moves the node before the destination node.afterโ Moves the node after the destination node.intoโ Moves the node to the end of the destination's list of children.
pathName nearest โ which node is closest to this pixel ๐
pathName nearest x y ?varName?
Returns the id of the node entry closest to the given X-Y screen coordinate. The optional argument varName is the name of variable which is set to either button or select to indicate over what part of the node the coordinate lies. And if the coordinate is not directly over any node, then varName will contain the empty string. Nothing. Void. ๐
pathName open โ unfold that glow-up โจ
pathName open ?-recurse? tagOrId...
Opens the one or more nodes specified by tagOrId. If a node is not already open, the Tcl script specified by the -opencommand option is invoked. If the -recurse flag is present, then each descendant is recursively opened. The whole bloodline gets expanded, we love to see it ๐ธ
pathName range โ depth-first and proud ๐
pathName range ?-open? first last
Returns the ids in depth-first order of the nodes between the first and last ids. If the -open flag is present, it indicates to consider only open nodes. And if last is before first, then the ids are returned in reverse order. Flip the script, literally ๐
pathName scan โ the scrolling era ๐ฑ๏ธ
pathName scan option args
This command implements scanning. It has two forms, depending on option:
pathName scan mark โ drop a pin ๐
pathName scan mark x y
Records x and y and the current view in the treeview window; used in conjunction with later scan dragto commands. Typically this command is associated with a mouse button press in the widget. It returns an empty string.
okay bestie the second form of scan is coming right up, do not scroll away ๐
pathName scan dragto x yโ okay bestie, this one does the math between itsxandyand thexandyfrom the lastscan markcommand for the widget. Then it shifts the view by 10 times that coordinate difference. It's the vibe you attach to mouse motion events so dragging the list at high speed through the window feels โจsmoothโจ. Return value? An empty string, periodt. ๐pathName see ?-anchor anchor? tagOrIdโ adjusts the view so the node fromtagOrIdis visible in the widget window. > IftagOrIdis a tag that refers to more than one node, it's an error, no cap. By default the node's entry is displayed in the middle of the window, but you can change that with the-anchorflag. Its value is a Tk anchor position. ๐pathName selection option argโ this command adjusts the selection inside a treeview widget. It has several forms depending onoption:pathName selection anchor tagOrIdโ sets the selection anchor to the node given bytagOrId. IftagOrIdrefers to a non-existent node, the closest node is used. The selection anchor is the end of the selection that stays fixed while you drag out a selection with the mouse. The special idanchorcan refer to the anchor node. ๐ฆpathName selection cancelโ clears the temporary selection of entries back to the current anchor. Temporary selections are created by theselection markoperation. ๐pathName selection clear first ?last?โ removes entries betweenfirstandlast(inclusive) from the selection. Bothfirstandlastare ids representing a range of entries. Iflastisn't given, onlyfirstis deselected. Entries outside the selection are not affected. ๐pathName selection clearallโ clears the entire selection. ๐pathName selection mark tagOrIdโ sets the selection mark to the node given bytagOrId. This makes the range of entries between the anchor and the mark temporarily added to the selection. The selection mark is the end of the selection that stays fixed while dragging out a selection with the mouse. The special idmarkcan refer to the current mark node. IftagOrIdrefers to a non-existent node, the mark is ignored. Resetting the mark will unselect the previous range. Setting the anchor finalizes the range. ๐ฅpathName selection includes tagOrIdโ returns1if the node given bytagOrIdis currently selected,0if it isn't. ๐ธpathName selection presentโ returns1if any nodes are currently selected and0otherwise. โจpathName selection set first ?last?โ selects all nodes in the range betweenfirstandlast, inclusive, without affecting the selection state of nodes outside that range. ๐pathName selection toggle first ?last?โ selects/deselects nodes in the range betweenfirstandlast, inclusive. If a node is currently selected, it becomes deselected, and vice versa. ๐
pathName show ?flags? tagOrId...โ exposes all nodes matching the criteria given byflags. This is the inverse of thehideoperation. The search is recursive for each node given bytagOrId. Valid flags are:-name patternโ specifies pattern to match against node names.-full patternโ specifies pattern to match against node pathnames.-option patternโ specifies pattern to match against the entry's configuration option.-exactโ match patterns exactly. This is the default. ๐-globโ use global pattern matching. Matching is done like the C-shell. For two strings to match, their contents must be identical except that these special sequences may appear inpattern:*โ matches any sequence of characters in string, including a null string.?โ matches any single character in string.[chars]โ matches any character in the set given bychars. If a sequence of the formx-yappears inchars, then any character betweenxandy, inclusive, will match.\xโ matches the single characterx. This provides a way to avoid the special interpretation of the characters*?[]\in the pattern.
-regexpโ use regular expression pattern matching (same as implemented by theregexpcommand).-nonmatchingโ expose nodes that don't match.--โ indicates the end of flags. ๐
pathName sort ?operation? args...pathName sort auto ?booleanโ turns on/off automatic sorting of node entries. Ifbooleanis true, entries will be automatically sorted as they are opened, closed, inserted, or deleted. If nobooleanargument is provided, the current state is returned. ๐ฅpathName sort cget optionโ returns the current value of the configuration option given byoption.Optionmay have any of the values accepted by theconfigureoperation described below. ๐ธpathName sort configure ?option? ?value option value ...?โ query or modify the sorting configuration options of the widget. If nooptionis specified, returns a list describing all available options forpathName(seeTk_ConfigureInfofor info on the format of this list). Ifoptionis specified with novalue, the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if nooptionis specified). If one or moreoption-valuepairs are specified, the command modifies the given sorting option(s) to have the given value(s); in this case the command returns an empty string.Optionandvalueare described below:-column stringโ specifies the column to sort. Entries in the widget are rearranged according to this column. Ifcolumnis""then no sort is performed.-command stringโ specifies a Tcl procedure to be called when sorting nodes. The procedure is called with three arguments: the pathname of the widget and the fields of two entries. The procedure returns1if the first node is greater than the second,-1if the second is greater, and0if equal.-decreasing booleanโ indicates to sort in ascending/descending order. Ifbooleanis true, then the entries are in descending order. The default isno.-mode stringโ specifies how to compare entries when sorting.Stringmay be one of the following:asciiโ use string comparison based upon the ASCII collation order.dictionaryโ use dictionary-style comparison. This is the same asasciiexcept (a) case is ignored except as a tie-breaker and (b) if two strings contain embedded numbers, the numbers compare as integers, not characters. For example,"bigBoy"sorts between"bigbang"and"bigboy", and"x10y"sorts between"x9y"and"x11y".integerโ compares fields as integers.realโ compares fields as floating point numbers.commandโ use the Tcl proc specified by the-commandoption to compare entries when sorting. If no command is specified, the sort reverts toasciisorting.
pathName sort once ?flags? tagOrId...โ sorts the children for each entry specified bytagOrId. By default, entries are sorted by name, but you can specify a Tcl proc to do your own comparisons.-recurseโ recursively sort the entire branch, not just the children. ๐
pathName tag operation argsโ tags are a general means of selecting and marking nodes in the tree. A tag is just a string of characters, and it may take any form except that of an integer. The same tag may be associated with many different nodes. Bothoperationand its arguments determine the exact behavior of the command. The operations available for tags are:pathName tag add string id...โ adds the tagstringto one or more entries.pathName tag delete string id...โ deletes the tagstringfrom one or more entries.pathName tag forget stringโ removes the tagstringfrom all entries. It's not an error if no entries are tagged asstring.pathName tag names ?id?โ returns a list of tags used. If anidargument is present, only those tags used by the node designated byidare returned. ๐
pathName tag nodes string ๐ท๏ธ
okay so you give it a tag, it gives you back a list of ids โ every single node that's wearing that tag. that's it, that's the whole vibe. and if nobody is tagged as string? you get an empty string back. empty. nada. the void. ๐ซ
pathName text operation ?args? โ๏ธ
bestie this one is your text editing girlie. she handles the whole editing sitch for cells (that's the data fields in a column, iykyk) and for entry labels. she's got a bunch of different forms and which one you get depends on operation. let's go through them one by one ๐
pathName text applyโ applies the edited buffer, replacing the entry label or the data field. then the edit window gets hidden. poof, gone, bye. โจpathName text cancelโ nope, never mind, undo it. reverts the entry label or the data value back to whatever it was before. and yeah, the edit window gets hidden too. ๐pathName text cget valueโ returns the current value of the configuration option given byoption. andoptioncan be literally any of the values that theconfigureoperation (described below, keep reading bestie) accepts. ๐pathName text configure ?option value?โ query or modify the config options of the edit window. no option specified? you get back a list describing all the available options (go checkTk_ConfigureInfoif you wanna know the format of that list, she's the source). option specified but no value? you get a list describing just that one named option โ and it'll be identical to the matching sublist from the no-option version. and if you pass one or moreoption-valuepairs? then it modifies the given widget option(s) to have the given value(s), and returns an empty string.optionandvalueare described down in TEXT EDITING OPTIONS below. ๐pathName text delete first lastโ deletes the characters in the edit buffer between the two given character positions. bye bye text ๐๏ธpathName text get ?-root? x yโ (this one's just sitting there, no description given, she's mysterious like that ๐ง)pathName text icursor indexโ (same energy, no description provided, iconic enigma ๐)pathName text index indexโ returns the text index of the givenindex. ๐ซpathName text insert index stringโ inserts the textstringinto the edit buffer at positionindex. for example, an index of0will prepend the buffer. front of the line, main character energy ๐pathName text selection argsโ this operation controls the selection of the editing window. and heads up bestie: this is not the same as the selection of entries. different girl entirely. she's got these forms:pathName text selection adjust indexโ adjusts either the first or last index of the selection. โจpathName text selection clearโ clears the selection. deselect, we don't know her ๐pathName text selection from indexโ sets the anchor of the selection. โpathName text selection presentโ indicates if a selection is present. yes or no bestie ๐pathName text selection range start endโ sets both the anchor and mark of the selection. the full package ๐pathName text selection to indexโ sets the unanchored end (the mark) of the selection. ๐ฆ
pathName toggle tagOrId ๐
opens or closes the node given by tagOrId. flip it, flip it back, you know how it goes. and if the matching -opencommand or -closecommand option is set? that command gets invoked too. so it's not just a visual thing, she does stuff. ๐ฅ
pathName xview args โ๏ธ
this command queries and changes the horizontal position of the info in the widget's window. she takes any of these forms:
pathName xviewโ returns a list with two elements. each one is a real fraction between0and1, and together they describe the horizontal span that's visible in the window. example time: if the first element is.2and the second is.6, then 20% of the treeview widget's text is off-screen to the left, the middle 40% is visible in the window, and 40% of the text is off-screen to the right. and these are literally the same values passed to scrollbars via the-xscrollcommandoption. ๐pathName xview tagOrIdโ adjusts the view so that the character position given bytagOrIdgets displayed at the left edge of the window. and btw, character positions are defined by the width of the character0. yep, that zero is the ruler. ๐งpathName xview moveto fractionโ adjusts the view so thatfractionof the total width of the treeview widget's text is off-screen to the left.fractionhas to be a fraction between0and1. no funny business. โจpathName xview scroll number whatโ shifts the view in the window left or right according tonumberandwhat.numbermust be an integer.whatmust be eitherunitsorpages, or an abbreviation of one of those. ifwhatisunits, the view adjusts left or right bynumbercharacter units (that's the width of the0character, same ruler as before ๐ ) on the display. if it'spages, then the view adjusts bynumberscreenfuls. and: ifnumberis negative, characters farther to the left become visible. if it's positive, characters farther to the right become visible. โฌ ๏ธโก๏ธ
pathName yview ?args? โ๏ธ
this one queries and changes the vertical position of the text in the widget's window. forms incoming:
pathName yviewโ returns a list of two elements, both real fractions between0and1. the first element gives the position of the node at the top of the window, relative to the widget as a whole (so0.5means it's halfway through the treeview window, for example). the second element gives the position of the node just after the last one in the window, relative to the widget as a whole. and again โ same values passed to scrollbars via the-yscrollcommandoption. ๐pathName yview tagOrIdโ adjusts the view so that the node given bytagOrIdis displayed at the top of the window. put her up top, she's the main character now ๐pathName yview moveto fractionโ adjusts the view so that the node given byfractionappears at the top of the window.fractionis a fraction between0and1.0indicates the first node,0.33indicates the node one-third of the way through the treeview widget, and so on. math but make it cute ๐งฎโจpathName yview scroll number whatโ adjusts the view in the window up or down according tonumberandwhat.numbermust be an integer.whatmust be eitherunitsorpages. ifwhatisunits, the view adjusts up or down bynumberlines. if it'spages, then the view adjusts bynumberscreenfuls. ifnumberis negative, earlier nodes become visible. if it's positive, later nodes become visible. โฌ๏ธโฌ๏ธ
โจ TREEVIEW OPTIONS โจ
So like, besides the configure operation, you can also set widget configuration options with Tk's option command. The class resource name is TreeView. Bestie, watch this:
option add *TreeView.Foreground white
option add *TreeView.Background blue
And here's the full lineup of widget options, no gatekeeping ๐ :
-activebackgroundcolor โ Sets the background color for active entries. A node is active when the mouse passes over its entry, or when you use theactivateoperation. It's giving "notice me" energy.-activeforegroundcolor โ Sets the foreground color of the active node. Same deal: a node is active when the mouse passes over its entry or via theactivateoperation.-activeiconsimages โ Specifies images to display for an entry's icon when it's active. images is a list of two Tk images: the first one shows when the node is open, the second when it's closed. Two looks, both iconic ๐ฆ-autocreateboolean โ If boolean is true, missing ancestor nodes get created automatically when you insert new nodes. Otherwise it flags an error. The default isno.-allowduplicatesboolean โ If boolean is true, nodes with duplicate pathnames are allowed when inserting new nodes. Otherwise it flags an error. The default isno.-backgroundcolor โ Sets the background color of the widget. The default iswhite.-borderwidthpixels โ Sets the width of the 3-D border around the outside edge of the widget. The-reliefoption decides whether that border actually gets drawn. The default is2.-closecommandstring โ Specifies a Tcl script to be invoked when a node is closed. You can override this for individual entries using the entry's-closecommandoption. The default is"". Percent substitutions are performed on string before it's executed. These substitutions are valid:%Wโ The pathname of the widget.%pโ The name of the node.%Pโ The full pathname of the node.%#โ The id of the node.%%โ Translates to a single percent.
-cursorcursor โ Specifies the widget's cursor. The default cursor is"".-dashesnumber โ Sets the dash style of the horizontal and vertical lines drawn connecting entries. number is the length in pixels of the dashes and the gaps in the line. If number is0, solid lines get drawn. The default is1(dotted).-exportselectionboolean โ Indicates if the selection is exported. If the widget is exporting its selection, it observes the standard X11 protocols for handling the selection. Selections are available as typeSTRING; the value of the selection is the label of the selected nodes, separated by newlines. The default isno.-flatboolean โ Indicates whether to display the tree as a flattened list. If boolean is true, the hierarchy becomes a list of full paths for the nodes. This option also has an effect on sorting โ see the SORT OPERATIONS section for more info. The default isno.-focusdashesdashList โ Sets the dash style of the outline rectangle drawn around the entry label of the node that currently has focus. number is the length in pixels of the dashes and gaps in the line. If number is0, a solid line gets drawn. The default is1.-focusforegroundcolor โ Sets the color of the focus rectangle. The default isblack.-fontfontName โ Specifies the font for entry labels. You can override this for individual entries with the entry's-fontconfiguration option. The default is*-Helvetica-Bold-R-Normal-*-12-120-*.-foregroundcolor โ Sets the text color of entry labels. You can override this for individual entries with the entry's-foregroundconfiguration option. The default isblack.-heightpixels โ Specifies the requested height of the widget. The default is400.-hiderootboolean โ If boolean is true, it means no entry for the root node should be displayed. The default isno.-highlightbackgroundcolor โ Specifies the normal color of the traversal highlight region when the widget doesn't have the input focus.-highlightcolorcolor โ Specifies the color of the traversal highlight rectangle when the widget has the input focus. The default isblack.-highlightthicknesspixels โ Specifies the width of the highlight rectangle indicating when the widget has input focus. The value may have any of the forms acceptable toTk_GetPixels. If the value is zero, no focus highlight gets displayed. The default is2.-iconsimages โ Specifies images for the entry's icon. images is a list of two Tk images: the first shows when the node is open, the second when it's closed.-linecolorcolor โ Sets the color of the connecting lines drawn between entries. The default isblack.-linespacingpixels โ Sets the number of pixels of spacing between entries. The default is0.-linewidthpixels โ Sets the width of the lines drawn connecting entries. If pixels is0, no vertical or horizontal lines get drawn. The default is1.-opencommandstring โ Specifies a Tcl script to be invoked when a node is open. You can override this for individual entries with the entry's-opencommandconfiguration option. The default is"". Percent substitutions are performed on string before it's executed. These substitutions are valid:%Wโ The pathname of the widget.%pโ The name of the node.%Pโ The full pathname of the node.%#โ The id of the node.%%โ Translates to a single percent.
-reliefrelief โ Specifies the 3-D effect for the widget. relief says how the treeview widget should appear relative to the widget it's packed into; for example,raisedmeans the treeview widget should appear to protrude. The default issunken.-scrollmodemode โ Specifies the style of scrolling to use. These styles are valid. The default ishierbox.listboxโ Like the listbox widget, the last entry can always be scrolled to the top of the widget window. This lets the scrollbar thumb shrink as the last entry gets scrolled upward.hierboxโ Like the hierbox widget, the last entry can only be viewed at the bottom of the widget window. The scrollbar stays a constant size.canvasโ Like the canvas widget, the entries are bound within the scrolling area.
-selectbackgroundcolor โ Sets the background color of selected node entries. The default is#ffffea.-selectborderwidthpixels โ Sets the width of the raised 3-D border drawn around the labels of selected entries. The default is0.-selectcommandstring โ Specifies a Tcl script to be invoked when the set of selected nodes changes. The default is"".-selectforegroundcolor โ Sets the color of the labels of selected node entries. The default isblack.-selectmodemode โ Specifies the selection mode. If mode issingle, only one node can be selected at a time. Ifmultiple, more than one node can be selected. The default issingle.-separatorstring โ Specifies the character sequence to use when splitting the path components. The separator may be several characters wide (like"::"). Consecutive separators in a pathname are treated as one. If string is the empty string, the pathnames are Tcl lists. Each element is a path component. The default is"".-showtitlesboolean โ If boolean is false, column titles are not displayed. The default isyes.-sortselectionboolean โ If boolean is true, nodes in the selection are ordered as they're currently displayed (depth-first or sorted), not in the order they were selected. The default isno.-takefocusfocus โ Provides info used when moving the focus from window to window via keyboard traversal (like Tab and Shift-Tab). If focus is0, this window should be skipped entirely during keyboard traversal.1means this window should always receive the input focus. An empty value means the traversal scripts decide whether to focus on the window. The default is"1".-trimstring โ Specifies a string of leading characters to trim from entry pathnames before parsing. This only makes sense if-separatoris also set. The default is"".-widthpixels โ Sets the requested width of the widget. If pixels is0, the width gets computed from the contents of the treeview widget. The default is200.-xscrollcommandstring โ Specifies the prefix for a command used to communicate with horizontal scrollbars. Whenever the horizontal view in the widget's window changes, the widget generates a Tcl command by concatenating the scroll command and two numbers. If this option isn't specified, no command gets executed.-xscrollincrementpixels โ Sets the horizontal scrolling distance. The default is20pixels.-yscrollcommandstring โ Specifies the prefix for a command used to communicate with vertical scrollbars. Whenever the vertical view in the widget's window changes, the widget generates a Tcl command by concatenating the scroll command and two numbers. If this option isn't specified, no command gets executed.-yscrollincrementpixels โ Sets the vertical scrolling distance. The default is20pixels.
๐ ENTRY OPTIONS ๐
Okay bestie, so here's the tea: a bunch of the widget config options have their own little twin inside entries. Like, -closecommand exists both for the widget itself and for individual entries. Options you set at the widget level? Those are global, they apply to every single entry. But if you set the option on the entry, then the entry one wins and overrides the widget one. Why tho? To avoid wasting memory by replicating options everywhere โ most entries end up with redundant options, so this is the slay-efficient way to do it. โจ
Ngl there is no resource class or name for entries. That's just how it is, periodt.
-activeiconsimages โ sets which images get shown as the entry's icon when the node is active. Overrides the global-activeiconsfor this one specific entry. images is a list of two Tk images: the first shows when the node is open, the second when it's closed. ๐ฆ-bindtagstagList โ the binding tags for nodes. tagList is a list of binding tag names. The tags AND their order decide how events get handled for nodes. Every tag in the list that matches the current event sequence gets its Tcl command executed. Default isall.-buttonstring โ should a button show up on the left side of the node entry? string can beyes,no, orauto. If it'sauto, a button is automatically displayed if the node has children. Andautois the default. ๐-closecommandstring โ a Tcl script to be invoked when the node is closed. Overrides the global-closecommandoption for this entry. Default is"". Percent substitutions are performed on string before it's executed, and these are the valid ones:%Wโ the pathname of the widget.%pโ the name of the node.%Pโ the full pathname of the node.%#โ the id of the node.%%โ translates to a single percent.
-datastring โ sets data fields for the node. string is a list of name-value pairs to be set. Default is"".-fontfontName โ sets the font for entry labels. This overrides the widget's-fontoption for this node. Default is*-Helvetica-Bold-R-Normal-*-12-120-*.-foregroundcolor โ sets the text color of the entry label. Overrides the widget's-foregroundconfiguration option. Default is"".-iconsimages โ the images displayed for the entry's icon. Overrides the global-iconsconfiguration option. images is a list of two Tk images: first one shows when the node is open, second when it's closed. Same energy as-activeiconsbut for the regular (non-active) state. ๐-labelstring โ sets the text for the entry's label. If you don't set it, it defaults to the name of the node. Default is"".-opencommandstring โ a Tcl script to be invoked when the entry is opened. Overrides the widget's-opencommandoption for this node. Default is"". Percent substitutions run on string before it executes, and these are valid:%Wโ the pathname of the widget.%pโ the name of the node.%Pโ the full pathname of the node.%#โ the id of the node.%%โ translates to a single percent.
๐ BUTTON OPTIONS ๐
Button config options can also be set through the option command. The resource subclass is Button. The resource name is always button. Watch:
option add *TreeView.Button.Foreground white
option add *TreeView.button.Background blue
Here's every configuration option you can give a button, bestie:
-activebackgroundcolor โ the background color of active buttons. A button becomes active when the mouse passes over it, or via thebutton activateoperation.-activeforegroundcolor โ the foreground color of active buttons. A button becomes active when the mouse passes over it, or via thebutton activateoperation.-backgroundcolor โ the background of the button. Default iswhite.-borderwidthpixels โ the width of the 3-D border around the button. The-reliefoption decides whether a border actually gets drawn. Default is1.-closereliefrelief โ the 3-D effect for the closed button. relief says how the button should appear relative to the widget โ like,raisedmeans it looks like it's protruding. Default issolid.-cursorcursor โ sets the widget's cursor. Default cursor is"".-foregroundcolor โ the foreground color of buttons. Default isblack.-imagesimages โ the images displayed for the button. images is a list of two Tk images: first when the button is open, second when it's closed. If images is the empty string, then a plus/minus gadget gets drawn instead. Default is"".-openreliefrelief โ the 3-D effect of the open button. relief says how the button should appear relative to the widget;raisedmeans it looks like it protrudes, etc. Default isflat.-sizepixels โ sets the requested size of the button. Default is0.
๐ COLUMN OPTIONS ๐
Column configuration options can also be set with the option command. Resource subclass is Column. The resource name is the name of the column. Like so:
option add *TreeView.Column.Foreground white
option add *TreeView.treeView.Background blue
And these are the configuration options available for columns, no cap:
-backgroundcolor โ background color of the column. Overrides the widget's-backgroundoption. Default iswhite.-borderwidthpixels โ width of the 3-D border of the column. The-reliefoption determines if a border gets drawn. Default is0.-editboolean โ can the column's data fields be edited? If boolean is false, the data fields in that column may not be edited. Default isyes.-foregroundcolor โ the foreground color of the column. You can override this per-entry using the entry's-foregroundoption. Default isblack.-fontfontName โ the font for a column. Override it per-entry with the entry's-fontoption. Default is*-Helvetica-Bold-R-Normal-*-12-120-*.-hideboolean โ if boolean is true, the column isn't displayed. Default isyes.-justifyjustify โ how the column data fields title should be justified inside the column. Only matters when the column is wider than the data field being displayed. justify must beleft,right, orcenter. Default isleft.-padpad โ how much padding for the left and right sides of the column. pad is a list of one or two screen distances. Two elements โ left side padded by the first distance, right side by the second. One distance โ both sides padded evenly. Default is2.-reliefrelief โ the 3-D effect of the column. relief says how the column should appear relative to the widget;raisedmeans it looks like it protrudes. Default isflat.-statestate โ sets the state of the column. If state isdisable, then the column title can not be activated nor invoked. Default isnormal.-textstring โ sets the title for the column. Default is"".-titleforegroundcolor โ foreground color of the column title. Default isblack.-titleshadowcolor โ the color of the drop shadow of the column title. Default is"". ๐-widthpixels โ the requested width of the column. This overrides the computed width of the column. If pixels is0, the width is computed from the contents of the column. Default is0.
โ๏ธ TEXT EDITING OPTIONS โ๏ธ
Text edit window configuration options can also be set with the option command. The resource class is TreeViewEditor. The resource name is always edit. Behold:
option add *TreeViewEditor.Foreground white
option add *edit.Background blue
These are the configuration options available for the text editing window:
-backgroundcolor โ background of the text edit window. Default iswhite.-borderwidthpixels โ width of the 3-D border around the edit window. The-reliefoption determines if a border gets drawn. Default is1.-exportselectionboolean โ is the text selection exported? If the edit window is exporting its selection, it will observe the standard X11 protocols for handling the selection. Selections are available as typeSTRING. Default isno.-reliefrelief โ the 3-D effect of the edit window. relief says how the background should appear relative to the edit window;raisedmeans the background looks like it protrudes. Default issolid.-selectbackgroundcolor โ background of the selected text in the edit window. Default iswhite.-selectborderwidthpixels โ width of the 3-D border around the selected text in the edit window. The-selectreliefoption determines if a border gets drawn. Default is1.-selectforegroundcolor โ foreground of the selected text in the edit window. Default iswhite.-selectreliefrelief โ the 3-D effect of the selected text in the edit window. relief says how the text should appear relative to the edit window;raisedmeans the text looks like it protrudes. Default isflat. ๐ธ
โจ DEFAULT BINDINGS โจ
okay so Tk is out here being a whole overachiever and it automatically creates class bindings for treeviews so they get that classic Motif-like behavior ๐
and honestly? a lot of how your treeview acts is decided by its -selectmode option, which picks between two whole ways of dealing with the selection. bestie it's giving "choose your fighter" energy fr fr.
If the selection mode is single, only one node can be selected at a time. Clicking button 1 on an node selects it and deselects any other selected item. one at a time, no sharing, no drama ๐
If the selection mode is multiple, any number of entries may be selected at once, including discontiguous ranges. Clicking Control-Button-1 on a node entry toggles its selection state without affecting any other entries. Pressing Shift-Button-1 on a node entry selects it, extends the selection. slay, chaotic, we love her ๐
- In extended mode, the selected range can be adjusted by pressing
button 1with theShiftkey down: this modifies the selection to consist of the entries between the anchor and the entry under the mouse, inclusive. The un-anchored end of this new selection can also be dragged with the button down. literally drag-select but make it fancy โจ - In extended mode, pressing
button 1with theControlkey down starts a toggle operation: the anchor is set to the entry under the mouse, and its selection state is reversed. The selection state of other entries isn't changed. If the mouse is dragged withbutton 1down, then the selection state of all entries between the anchor and the entry under the mouse is set to match that of the anchor entry; the selection state of all other entries remains what it was before the toggle operation began. iconic behavior, no notes ๐ - If the mouse leaves the treeview window with
button 1down, the window scrolls away from the mouse, making information visible that used to be off-screen on the side of the mouse. The scrolling continues until the mouse re-enters the window, the button is released, or the end of the hierarchy is reached. auto-scroll queen ๐ Mouse button 2may be used for scanning. If it is pressed and dragged over the treeview widget, the contents of the hierarchy drag at high speed in the direction the mouse moves. wheeee ๐ผ- If the
UporDownkey is pressed, the location cursor (active entry) moves up or down one entry. If the selection mode isbrowseorextendedthen the new active entry is also selected and all other entries are deselected. Inextendedmode the new active entry becomes the selection anchor. - In
extendedmode,Shift-UpandShift-Downmove the location cursor (active entry) up or down one entry and also extend the selection to that entry in a fashion similar to dragging withmouse button 1. - The
LeftandRightkeys scroll the treeview widget view left and right by the width of the character0.Control-LeftandControl-Rightscroll the treeview widget view left and right by the width of the window.Control-PriorandControl-Nextalso scroll left and right by the width of the window. (yes, the width of the literal character0, that's not a typo, that's just the unit they picked ๐) - The
PriorandNextkeys scroll the treeview widget view up and down by one page (the height of the window). - The
HomeandEndkeys scroll the treeview widget horizontally to the left and right edges, respectively. Control-Homesets the location cursor to the the first entry, selects that entry, and deselects everything else in the widget. (and yes, the original really does say "the the", we're keeping her exactly as she is ๐ซถ)Control-Endsets the location cursor to the the last entry, selects that entry, and deselects everything else in the widget.- In
extendedmode,Control-Shift-Homeextends the selection to the first entry andControl-Shift-Endextends the selection to the last entry. - In
multiplemode,Control-Shift-Homemoves the location cursor to the first entry andControl-Shift-Endmoves the location cursor to the last entry. - The
spaceandSelectkeys make a selection at the location cursor (active entry) just as ifmouse button 1had been pressed over this entry. - In
extendedmode,Control-Shift-spaceandShift-Selectextend the selection to the active entry just as ifbutton 1had been pressed with theShiftkey down. - In
extendedmode, theEscapekey cancels the most recent selection and restores all the entries in the selected range to their previous selection state. the undo button of selections, we stan ๐ญ Control-slashselects everything in the widget, except insingleandbrowsemodes, in which case it selects the active entry and deselects everything else.Control-backslashdeselects everything in the widget, except inbrowsemode where it has no effect.- The
F16key (labelledCopyon many Sun workstations) orMeta-wcopies the selection in the widget to the clipboard, if there is a selection.
The behavior of treeview widgets can be changed by defining new bindings for individual widgets or by redefining the class bindings. so like, if you don't vibe with any of this, you can absolutely just rewrite it yourself, go off ๐
WIDGET BINDINGS
On top of all that above behavior, the following additional behavior is defined by the default widget class (TreeView) bindings. ๐ฆ
<ButtonPress-2>โ Starts scanning.<B2-Motion>โ Adjusts the scan.<ButtonRelease-2>โ Stops scanning.<B1-Leave>โ Starts auto-scrolling.<B1-Enter>โ Starts auto-scrolling<KeyPress-Up>โ Moves the focus to the previous entry.<KeyPress-Down>โ Moves the focus to the next entry.<Shift-KeyPress-Up>โ Moves the focus to the previous sibling.<Shift-KeyPress-Down>โ Moves the focus to the next sibling.<KeyPress-Prior>โ Moves the focus to first entry. Closed or hidden entries are ignored.<KeyPress-Next>โ Move the focus to the last entry. Closed or hidden entries are ignored.<KeyPress-Left>โ Closes the entry. It is not an error if the entry has no children.<KeyPress-Right>โ Opens the entry, displaying its children. It is not an error if the entry has no children.<KeyPress-space>โ In"single"select mode this selects the entry. In"multiple"mode, it toggles the entry (if it was previous selected, it is not deselected).<KeyRelease-space>โ Turns off select mode.<KeyPress-Return>โ Sets the focus to the current entry.<KeyRelease-Return>โ Turns off select mode.<KeyPress>โ Moves to the next entry whose label starts with the letter typed. type-ahead bestie ๐ฅ<KeyPress-Home>โ Moves the focus to first entry. Closed or hidden entries are ignored.<KeyPress-End>โ Move the focus to the last entry. Closed or hidden entries are ignored.<KeyPress-F1>โ Opens all entries.<KeyPress-F2>โ Closes all entries (except root).
BUTTON BINDINGS
Buttons have bindings. There are associated with the "all" bindtag (see the entry's -bindtag option). You can use the bind operation to change them. ๐
<Enter>โ Highlights the button of the current entry.<Leave>โ Returns the button back to its normal state.<ButtonRelease-1>โ Adjust the view so that the current entry is visible.
ENTRY BINDINGS
Entries have default bindings. There are associated with the "all" bindtag (see the entry's -bindtag option). You can use the bind operation to modify them. ๐
<Enter>โ Highlights the current entry.<Leave>โ Returns the entry back to its normal state.<ButtonPress-1>โ Sets the selection anchor the current entry.<Double-ButtonPress-1>โ Toggles the selection of the current entry.<B1-Motion>โ For"multiple"mode only. Saves the current location of the pointer for auto-scrolling. Resets the selection mark.<ButtonRelease-1>โ For"multiple"mode only. Sets the selection anchor to the current entry.<Shift-ButtonPress-1>โ For"multiple"mode only. Extends the selection.<Shift-Double-ButtonPress-1>โ Place holder. Does nothing.<Shift-B1-Motion>โ Place holder. Does nothing.<Shift-ButtonRelease-1>โ Stop auto-scrolling.<Control-ButtonPress-1>โ For"multiple"mode only. Toggles and extends the selection.<Control-Double-ButtonPress-1>โ Place holder. Does nothing.<Control-B1-Motion>โ Place holder. Does nothing.<Control-ButtonRelease-1>โ Stops auto-scrolling.<Control-Shift-ButtonPress-1>โ ???<Control-Shift-Double-ButtonPress-1>โ Place holder. Does nothing.<Control-Shift-B1-Motion>โ Place holder. Does nothing.
not the ??? bestie, the docs really did just leave that one undocumented and honestly? respect for the honesty ๐
COLUMN BINDINGS
Columns have bindings too. They are associated with the column's "all" bindtag (see the column -bindtag option). You can use the column bind operation to change them. ๐ธ
<Enter>โ Highlights the current column title.<Leave>โ Returns the column back to its normal state.<ButtonRelease-1>โ Invokes the command (see the column's-commandoption) if one if specified.
COLUMN RULE BINDINGS
<Enter>โ Highlights the current and activates the ruler.<Leave>โ Returns the column back to its normal state. Deactivates the ruler.<ButtonPress-1>โ Sets the resize anchor for the column.<B1-Motion>โ Sets the resize mark for the column.<ButtonRelease-1>โ Adjust the size of the column, based upon the resize anchor and mark positions.
๐ EXAMPLE ๐
Okay bestie, real talk โ this is the part where it all clicks. Let's build a whole widget from scratch, step by step. ๐ซถ
The treeview command creates a new widget.
treeview .h -bg white
A new Tcl command .h is also created. This command can be used to query and modify the treeview widget. So like, for example, to change the background color of the table to "green", you use the new command and the widget's configure operation.
# Change the background color.
.h configure -background "green"
By default, the treeview widget will automatically create a new tree object to contain the data. The name of the new tree is the pathname of the widget. Above, the new tree object name is ".h". But you can use the -tree option to specify the name of another tree.
# View the tree "myTree".
.h configure -tree "myTree"
When a new tree is created, it contains only a root node. The node is automatically opened. The id of the root node is always 0 (you can use also use the special id root). The insert operation lets you insert one or more new entries into the tree. The last argument is the node's pathname.
# Create a new entry named "myEntry"
set id [.h insert end "myEntry"]
This appends a new node named "myEntry". It will positioned as the last child of the root of the tree (using the position "end"). You can supply another position to order the node within its siblings.
# Prepend "fred".
set id [.h insert 0 "fred"]
Entry names do not need to be unique. By default, the node's label is its name. To supply a different text label, add the -label option.
# Create a new node named "fred"
set id [.h insert end "fred" -label "Fred Flintstone"]
The insert operation returns the id of the new node. You can also use the index operation to get this information.
# Get the id of "fred"
.h index "fred"
To insert a node somewhere other than root, use the -at switch. It takes the id of the node where the new child will be added.
# Create a new node "barney" in "fred".
.h insert -at $id end "barney"
A pathname describes the path to an entry in the hierarchy. It's a list of entry names that compose the path in the tree. Therefore, you can also add "barney" to "fred" as follows.
# Create a new sub-entry of "fred"
.h insert end "fred barney"
Every name in the list is ancestor of the next. All ancestors must already exist. That means that an entry "fred" is an ancestor of "barney" and must already exist. But you can use the -autocreate configuration option to force the creation of ancestor nodes.
# Force the creation of ancestors.
.h configure -autocreate yes
.h insert end "fred barney wilma betty"
Sometimes the pathname is already separated by a character sequence rather than formed as a list. A file name is a good example of this. You can use the -separator option to specify a separator string to split the path into its components. Each pathname inserted is automatically split using the separator string as a separator. Multiple separators are treated as one. โจ
.h configure -separator /
.h insert end "/usr/local/tcl/bin"
If the path is prefixed by extraneous characters, you can automatically trim it off using the -trim option. It removed the string from the path before it is parsed.
.h configure -trim C:/windows -separator /
.h insert end "C:/window/system"
You can insert more than one entry at a time with the insert operation. This can be much faster than looping over a list of names. ๐๏ธ
# The slow way
foreach f [glob $dir/*] {
.h insert end $f
}
# The fast way
eval .h insert end [glob $dir/*]
In this case, the insert operation will return a list of ids of the new entries.
You can delete entries with the delete operation. It takes one or more tags of ids as its argument. It deletes the entry and all its children.
.h delete $id
Entries have several configuration options. They control the appearance of the entry's icon and label. We have already seen the -label option that sets the entry's text label. The entry configure operation lets you set or modify an entry's configuration options.
.h entry configure $id -color red -font fixed
You can hide an entry and its children using the -hide option.
.h entry configure $id -hide yes
More that one entry can be configured at once. All entries specified are configured with the same options.
.h entry configure $i1 $i2 $i3 $i4 -color brown
An icon is displayed for each entry. It's a Tk image drawn to the left of the label. You can set the icon with the entry's -icons option. It takes a list of two image names: one to represent the open entry, another when it is closed. ๐ธ
set im1 [image create photo -file openfolder.gif]
set im2 [image create photo -file closefolder.gif]
.h entry configure $id -icons "$im1 $im2"
If -icons is set to the empty string, no icons are display.
If an entry has children, a button is displayed to the left of the icon. Clicking the mouse on this button opens or closes the sub-hierarchy. The button is normally a + or - symbol, but can be configured in a variety of ways using the button configure operation. For example, the + and - symbols can be replaced with Tk images.
set im1 [image create photo -file closefolder.gif]
set im2 [image create photo -file downarrow.gif]
.h button configure $id -images "$im1 $im2" \
-openrelief raised -closerelief raised
Entries can contain an arbitrary number of data fields. Data fields are name-value pairs. Both the value and name are strings. The entry's -data option lets you set data fields.
.h entry configure $id -data {mode 0666 group users}
The -data takes a list of name-value pairs.
You can display these data fields as columns in the treeview widget. You can create and configure columns with the column operation. For example, to add a new column to the widget, use the column insert operation. The last argument is the name of the data field that you want to display.
.h column insert end "mode"
The column title is displayed at the top of the column. By default, it's is the field name. You can override this using the column's -text option.
.h column insert end "mode" -text "File Permissions"
Columns have several configuration options. The column configure operation lets you query or modify column options.
.h column configure "mode" -justify left
The -justify option says how the data is justified within in the column. The -hide option indicates whether the column is displayed.
.h column configure "mode" -hide yes
Entries can be selected by clicking on the mouse. Selected entries are drawn using the colors specified by the -selectforeground and -selectbackground configuration options. The selection itself is managed by the selection operation.
# Clear all selections
.h selection clear 0 end
# Select the root node
.h selection set 0
The curselection operation returns a list of ids of all the selected entries.
set ids [.h curselection]
You can use the get operation to convert the ids to their pathnames.
set names [eval .h get -full $ids]
If a treeview is exporting its selection (using the -exportselection option), then it will observe the standard X11 protocols for handling the selection. Treeview selections are available as type STRING; the value of the selection will be the pathnames of the selected entries, separated by newlines.
The treeview supports two modes of selection: single and multiple. In single select mode, only one entry can be selected at a time, while multiple select mode allows several entries to be selected. The mode is set by the widget's -selectmode option.
.h configure -selectmode "multiple"
You can be notified when the list of selected entries changes. The widget's -selectcommand specifies a Tcl procedure that is called whenever the selection changes.
proc SelectNotify { widget } {
set ids [$widget curselection]
}
.h configure -selectcommand "SelectNotify .h"
The widget supports the standard Tk scrolling and scanning operations. The treeview can be both horizontally and vertically. You can attach scrollbars to the treeview the same way as the listbox or canvas widgets.
scrollbar .xbar -orient horizontal -command ".h xview"
scrollbar .ybar -orient vertical -command ".h yview"
.h configure -xscrollcommand ".xbar set" \
-yscrollcommand ".ybar set"
There are three different modes of scrolling: listbox, canvas, and hierbox. In listbox mode, the last entry can always be scrolled to the top of the widget. In hierbox mode, the last entry is always drawn at the bottom of the widget. The scroll mode is set by the widget's -selectmode option. ๐
.h configure -scrollmode "listbox"
Entries can be programmatically opened or closed using the open and close operations respectively.
.h open $id
.h close $id
When an entry is opened, a Tcl procedure can be automatically invoked. The -opencommand option specifies this procedure. This procedure can lazily insert entries as needed. ๐
proc AddEntries { dir } {
eval .h insert end [glob -nocomplain $dir/*]
}
.h configure -opencommand "AddEntries %P"
Now when an entry is opened, the procedure AddEntries is called and adds children to the entry. Before the command is invoked, special "%" substitutions (like bind) are performed. Above, %P is translated to the pathname of the entry.
The same feature exists when an entry is closed. The -closecommand option specifies the procedure.
proc DeleteEntries { id } {
.h entry delete $id 0 end
}
.h configure -closecommand "DeleteEntries %#"
When an entry is closed, the procedure DeleteEntries is called and deletes the entry's children using the entry delete operation (%# is the id of entry).
โจ KEYWORDS โจ
treeviewwidget
And that's the whole page, bestie!! ๐ You just read the entire blt::treeview(3tcl) manual. Iconic. ๐
This one's from BLT, version 2.5, and the page is blt::treeview(3tcl). Go build something cute with it, fr fr. ๐๐๐ฆ
๐ฆ where this page comes from
- debian bookworm: blt-dev 2.5.3+dfsg-4.1
- debian trixie: blt-dev 2.5.3+dfsg-8
- ubuntu jammy: blt-dev 2.5.3+dfsg-4.1build2
- ubuntu noble: blt-dev 2.5.3+dfsg-7build1
- ubuntu questing: blt-dev 2.5.3+dfsg-8
- ubuntu resolute: blt-dev 2.5.3+dfsg-8build1
- ubuntu stonking: blt-dev 2.5.3+dfsg-9
- Copyright 2001-2 by Silicon Metrics Corporation
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms