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 -activeicon option). The active id is changed automatically by moving the mouse pointer over another node or by using the entry activate operation. 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 the selection anchor operation.
  • current โ€” The node where the mouse pointer is currently located. But unlike active, 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 current focus. The down of 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 the focus operation.
  • last โ€” The last open node from the current focus. But unlike up, when the focus is at root, last wraps 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 the selection mark operation.
  • next โ€” The next open node from the current focus. But unlike down, when the focus is on the last open node, next wraps around to the root node.
  • nextsibling โ€” The next sibling from the node with the current focus. If the node is already the last sibling then it is the nextsibling.
  • parent โ€” The parent of the node with the current focus. The parent of the root is also the root.
  • prevsibling โ€” The previous sibling from the node with the current focus. If the node is already the first sibling then it is the prevsibling.
  • root โ€” The root node. You can also use id 0 to indicate the root.
  • up โ€” The last open node (in depth-first order) from the current focus. The up of 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 -separator configuration 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 by x and y (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 sequence and tagName.
  • If the first character of command is +, then command augments an existing binding instead of replacing it.
  • No command argument? Then you get back the command currently associated with tagName and sequence โ€” and yep, it's an error if there's no such binding ๐Ÿ˜ญ
  • Both command and sequence missing? Then you get a list of all the event sequences for which bindings have been defined for tagName.

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 sequence and tagName.
  • First character of command is + โ†’ command augments an existing binding rather than replacing it.
  • No command argument โ†’ the command currently associated with tagName and sequence is returned (and yes, it's an error if there's no such binding ๐Ÿ˜ญ).
  • Both command and sequence missing โ†’ a list of all the event sequences for which bindings have been defined for tagName.

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 (peep Tk_ConfigureInfo for 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 (see Tk_ConfigureInfo for 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 (see Tk_ConfigureInfo for 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 option at all? You get a list describing all the available options for pathName (peep Tk_ConfigureInfo for info on the format of that list, iykyk).
  • option with no value? 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-value pairs? 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:

  • -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 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 form x-y appears in chars, then any character between x and y, inclusive, will match.
    • \x โ€” Matches the single character x. 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 the regexp command).
  • -nonmatching โ€” Pick entries that don't match. Not like other girls ๐Ÿ’…
  • -exec string โ€” 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.
  • -count number โ€” 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:

  • -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 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 form x-y appears in chars, then any character between x and y, inclusive, will match.
    • \x โ€” Matches the single character x. 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 the regexp command).
  • -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 -autocreate option is set.
  • It is also an error if a node already exists, unless the -allowduplicates option 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 its x and y and the x and y from the last scan mark command 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 from tagOrId is visible in the widget window. > If tagOrId is 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 -anchor flag. 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 on option:
    • pathName selection anchor tagOrId โ€” sets the selection anchor to the node given by tagOrId. If tagOrId refers 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 id anchor can refer to the anchor node. ๐Ÿฆ‹
    • pathName selection cancel โ€” clears the temporary selection of entries back to the current anchor. Temporary selections are created by the selection mark operation. ๐Ÿ’…
    • pathName selection clear first ?last? โ€” removes entries between first and last (inclusive) from the selection. Both first and last are ids representing a range of entries. If last isn't given, only first is 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 by tagOrId. 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 id mark can refer to the current mark node. If tagOrId refers 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 โ€” returns 1 if the node given by tagOrId is currently selected, 0 if it isn't. ๐ŸŒธ
    • pathName selection present โ€” returns 1 if any nodes are currently selected and 0 otherwise. โœจ
    • pathName selection set first ?last? โ€” selects all nodes in the range between first and last, inclusive, without affecting the selection state of nodes outside that range. ๐Ÿ‘‘
    • pathName selection toggle first ?last? โ€” selects/deselects nodes in the range between first and last, inclusive. If a node is currently selected, it becomes deselected, and vice versa. ๐ŸŒˆ
  • pathName show ?flags? tagOrId... โ€” exposes all nodes matching the criteria given by flags. This is the inverse of the hide operation. The search is recursive for each node given by tagOrId. 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 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 form x-y appears in chars, then any character between x and y, inclusive, will match.
      • \x โ€” matches the single character x. 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 the regexp command).
    • -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. If boolean is true, entries will be automatically sorted as they are opened, closed, inserted, or deleted. If no boolean argument is provided, the current state is returned. ๐Ÿ”ฅ
    • pathName sort 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 sort configure ?option? ?value option value ...? โ€” query or modify the sorting configuration options of the widget. If no option is specified, returns a list describing all available options for pathName (see Tk_ConfigureInfo for info on the format of this list). If option is specified with no value, 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, the command modifies the given sorting option(s) to have the given value(s); in this case the command returns an empty string. Option and value are described below:
      • -column string โ€” specifies the column to sort. Entries in the widget are rearranged according to this column. If column is "" 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 returns 1 if the first node is greater than the second, -1 if the second is greater, and 0 if equal.
      • -decreasing boolean โ€” indicates to sort in ascending/descending order. If boolean is true, then the entries are in descending order. The default is no.
      • -mode string โ€” specifies how to compare entries when sorting. String may be one of the following:
        • ascii โ€” use string comparison based upon the ASCII collation order.
        • dictionary โ€” use dictionary-style comparison. This is the same as ascii except (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 -command option to compare entries when sorting. If no command is specified, the sort reverts to ascii sorting.
    • pathName sort once ?flags? tagOrId... โ€” sorts the children for each entry specified by tagOrId. 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. Both operation and its arguments determine the exact behavior of the command. The operations available for tags are:
    • pathName tag add string id... โ€” adds the tag string to one or more entries.
    • pathName tag delete string id... โ€” deletes the tag string from one or more entries.
    • pathName tag forget string โ€” removes the tag string from all entries. It's not an error if no entries are tagged as string.
    • pathName tag names ?id? โ€” returns a list of tags used. If an id argument is present, only those tags used by the node designated by id are 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 by option. and option can be literally any of the values that the configure operation (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 check Tk_ConfigureInfo if 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 more option-value pairs? then it modifies the given widget option(s) to have the given value(s), and returns an empty string. option and value are 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 given index. ๐Ÿ’ซ
  • pathName text insert index string โ€” inserts the text string into the edit buffer at position index. for example, an index of 0 will 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 between 0 and 1, and together they describe the horizontal span that's visible in the window. example time: if the first element is .2 and 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 -xscrollcommand option. ๐Ÿ“Š
  • pathName xview tagOrId โ€” adjusts the view so that the character position given by tagOrId gets displayed at the left edge of the window. and btw, character positions are defined by the width of the character 0. yep, that zero is the ruler. ๐Ÿงš
  • pathName xview moveto fraction โ€” adjusts the view so that fraction of the total width of the treeview widget's text is off-screen to the left. fraction has to be a fraction between 0 and 1. no funny business. โœจ
  • pathName xview scroll number what โ€” 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 those. if what is units, the view adjusts left or right by number character units (that's the width of the 0 character, same ruler as before ๐Ÿ’…) on the display. if it's pages, then the view adjusts by number screenfuls. and: if number is 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 between 0 and 1. the first element gives the position of the node at the top of the window, relative to the widget as a whole (so 0.5 means 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 -yscrollcommand option. ๐Ÿ“Š
  • pathName yview tagOrId โ€” adjusts the view so that the node given by tagOrId is 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 by fraction appears at the top of the window. fraction is a fraction between 0 and 1. 0 indicates the first node, 0.33 indicates 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 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 by number lines. if it's pages, then the view adjusts by number screenfuls. if number is 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 ๐Ÿ’…:

  • -activebackground color โ€” Sets the background color for active entries. A node is active when the mouse passes over its entry, or when you use the activate operation. It's giving "notice me" energy.
  • -activeforeground color โ€” Sets the foreground color of the active node. Same deal: a node is active when the mouse passes over its entry or via the activate operation.
  • -activeicons images โ€” 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 ๐Ÿฆ‹
  • -autocreate boolean โ€” If boolean is true, missing ancestor nodes get created automatically when you insert new nodes. Otherwise it flags an error. The default is no.
  • -allowduplicates boolean โ€” If boolean is true, nodes with duplicate pathnames are allowed when inserting new nodes. Otherwise it flags an error. The default is no.
  • -background color โ€” Sets the background color of the widget. The default is white.
  • -borderwidth pixels โ€” Sets the width of the 3-D border around the outside edge of the widget. The -relief option decides whether that border actually gets drawn. The default is 2.
  • -closecommand string โ€” Specifies a Tcl script to be invoked when a node is closed. You can override this for individual entries using the entry's -closecommand 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.
  • -cursor cursor โ€” Specifies the widget's cursor. The default cursor is "".
  • -dashes number โ€” 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 is 0, solid lines get drawn. The default is 1 (dotted).
  • -exportselection boolean โ€” 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 type STRING; the value of the selection is the label of the selected nodes, separated by newlines. The default is no.
  • -flat boolean โ€” 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 is no.
  • -focusdashes dashList โ€” 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 is 0, a solid line gets drawn. The default is 1.
  • -focusforeground color โ€” Sets the color of the focus rectangle. The default is black.
  • -font fontName โ€” Specifies the font for entry labels. You can override this for individual entries with the entry's -font configuration option. The default is *-Helvetica-Bold-R-Normal-*-12-120-*.
  • -foreground color โ€” Sets the text color of entry labels. You can override this for individual entries with the entry's -foreground configuration option. The default is black.
  • -height pixels โ€” Specifies the requested height of the widget. The default is 400.
  • -hideroot boolean โ€” If boolean is true, it means no entry for the root node should be displayed. The default is no.
  • -highlightbackground color โ€” Specifies the normal color of the traversal highlight region when the widget doesn't have the input focus.
  • -highlightcolor color โ€” Specifies the color of the traversal highlight rectangle when the widget has the input focus. The default is black.
  • -highlightthickness pixels โ€” Specifies the width of the highlight rectangle indicating when the widget has input focus. The value may have any of the forms acceptable to Tk_GetPixels. If the value is zero, no focus highlight gets displayed. The default is 2.
  • -icons images โ€” 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.
  • -linecolor color โ€” Sets the color of the connecting lines drawn between entries. The default is black.
  • -linespacing pixels โ€” Sets the number of pixels of spacing between entries. The default is 0.
  • -linewidth pixels โ€” Sets the width of the lines drawn connecting entries. If pixels is 0, no vertical or horizontal lines get drawn. The default is 1.
  • -opencommand string โ€” Specifies a Tcl script to be invoked when a node is open. You can override this for individual entries with the entry's -opencommand configuration 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.
  • -relief relief โ€” 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, raised means the treeview widget should appear to protrude. The default is sunken.
  • -scrollmode mode โ€” Specifies the style of scrolling to use. These styles are valid. The default is hierbox.
    • 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.
  • -selectbackground color โ€” Sets the background color of selected node entries. The default is #ffffea.
  • -selectborderwidth pixels โ€” Sets the width of the raised 3-D border drawn around the labels of selected entries. The default is 0.
  • -selectcommand string โ€” Specifies a Tcl script to be invoked when the set of selected nodes changes. The default is "".
  • -selectforeground color โ€” Sets the color of the labels of selected node entries. The default is black.
  • -selectmode mode โ€” Specifies the selection mode. If mode is single, only one node can be selected at a time. If multiple, more than one node can be selected. The default is single.
  • -separator string โ€” 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 "".
  • -showtitles boolean โ€” If boolean is false, column titles are not displayed. The default is yes.
  • -sortselection boolean โ€” 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 is no.
  • -takefocus focus โ€” Provides info used when moving the focus from window to window via keyboard traversal (like Tab and Shift-Tab). If focus is 0, this window should be skipped entirely during keyboard traversal. 1 means 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".
  • -trim string โ€” Specifies a string of leading characters to trim from entry pathnames before parsing. This only makes sense if -separator is also set. The default is "".
  • -width pixels โ€” Sets the requested width of the widget. If pixels is 0, the width gets computed from the contents of the treeview widget. The default is 200.
  • -xscrollcommand string โ€” 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.
  • -xscrollincrement pixels โ€” Sets the horizontal scrolling distance. The default is 20 pixels.
  • -yscrollcommand string โ€” 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.
  • -yscrollincrement pixels โ€” Sets the vertical scrolling distance. The default is 20 pixels.

๐Ÿ’– 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.
  • -activeicons images โ€” sets which images get shown as the entry's icon when the node is active. Overrides the global -activeicons for 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. ๐Ÿฆ‹
  • -bindtags tagList โ€” 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 is all.
  • -button string โ€” should a button show up on the left side of the node entry? string can be yes, no, or auto. If it's auto, a button is automatically displayed if the node has children. And auto is the default. ๐Ÿ’…
  • -closecommand string โ€” a Tcl script to be invoked when the node is closed. Overrides the global -closecommand option 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.
  • -data string โ€” sets data fields for the node. string is a list of name-value pairs to be set. Default is "".
  • -font fontName โ€” sets the font for entry labels. This overrides the widget's -font option for this node. Default is *-Helvetica-Bold-R-Normal-*-12-120-*.
  • -foreground color โ€” sets the text color of the entry label. Overrides the widget's -foreground configuration option. Default is "".
  • -icons images โ€” the images displayed for the entry's icon. Overrides the global -icons configuration 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 -activeicons but for the regular (non-active) state. ๐ŸŽ€
  • -label string โ€” sets the text for the entry's label. If you don't set it, it defaults to the name of the node. Default is "".
  • -opencommand string โ€” a Tcl script to be invoked when the entry is opened. Overrides the widget's -opencommand option 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:

  • -activebackground color โ€” the background color of active buttons. A button becomes active when the mouse passes over it, or via the button activate operation.
  • -activeforeground color โ€” the foreground color of active buttons. A button becomes active when the mouse passes over it, or via the button activate operation.
  • -background color โ€” the background of the button. Default is white.
  • -borderwidth pixels โ€” the width of the 3-D border around the button. The -relief option decides whether a border actually gets drawn. Default is 1.
  • -closerelief relief โ€” the 3-D effect for the closed button. relief says how the button should appear relative to the widget โ€” like, raised means it looks like it's protruding. Default is solid.
  • -cursor cursor โ€” sets the widget's cursor. Default cursor is "".
  • -foreground color โ€” the foreground color of buttons. Default is black.
  • -images images โ€” 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 "".
  • -openrelief relief โ€” the 3-D effect of the open button. relief says how the button should appear relative to the widget; raised means it looks like it protrudes, etc. Default is flat.
  • -size pixels โ€” sets the requested size of the button. Default is 0.

๐Ÿ“Š 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:

  • -background color โ€” background color of the column. Overrides the widget's -background option. Default is white.
  • -borderwidth pixels โ€” width of the 3-D border of the column. The -relief option determines if a border gets drawn. Default is 0.
  • -edit boolean โ€” can the column's data fields be edited? If boolean is false, the data fields in that column may not be edited. Default is yes.
  • -foreground color โ€” the foreground color of the column. You can override this per-entry using the entry's -foreground option. Default is black.
  • -font fontName โ€” the font for a column. Override it per-entry with the entry's -font option. Default is *-Helvetica-Bold-R-Normal-*-12-120-*.
  • -hide boolean โ€” if boolean is true, the column isn't displayed. Default is yes.
  • -justify justify โ€” 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 be left, right, or center. Default is left.
  • -pad pad โ€” 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 is 2.
  • -relief relief โ€” the 3-D effect of the column. relief says how the column should appear relative to the widget; raised means it looks like it protrudes. Default is flat.
  • -state state โ€” sets the state of the column. If state is disable, then the column title can not be activated nor invoked. Default is normal.
  • -text string โ€” sets the title for the column. Default is "".
  • -titleforeground color โ€” foreground color of the column title. Default is black.
  • -titleshadow color โ€” the color of the drop shadow of the column title. Default is "". ๐Ÿ’…
  • -width pixels โ€” the requested width of the column. This overrides the computed width of the column. If pixels is 0, the width is computed from the contents of the column. Default is 0.

โœ๏ธ 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:

  • -background color โ€” background of the text edit window. Default is white.
  • -borderwidth pixels โ€” width of the 3-D border around the edit window. The -relief option determines if a border gets drawn. Default is 1.
  • -exportselection boolean โ€” 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 type STRING. Default is no.
  • -relief relief โ€” the 3-D effect of the edit window. relief says how the background should appear relative to the edit window; raised means the background looks like it protrudes. Default is solid.
  • -selectbackground color โ€” background of the selected text in the edit window. Default is white.
  • -selectborderwidth pixels โ€” width of the 3-D border around the selected text in the edit window. The -selectrelief option determines if a border gets drawn. Default is 1.
  • -selectforeground color โ€” foreground of the selected text in the edit window. Default is white.
  • -selectrelief relief โ€” the 3-D effect of the selected text in the edit window. relief says how the text should appear relative to the edit window; raised means the text looks like it protrudes. Default is flat. ๐ŸŒธ

โœจ 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 ๐ŸŒˆ

  1. In extended mode, the selected range can be adjusted by pressing button 1 with the Shift key 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 โœจ
  2. In extended mode, pressing button 1 with the Control key 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 with button 1 down, 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 ๐Ÿ’–
  3. If the mouse leaves the treeview window with button 1 down, 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 ๐Ÿ‘‘
  4. Mouse button 2 may 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 ๐Ÿ›ผ
  5. If the Up or Down key is pressed, the location cursor (active entry) moves up or down one entry. If the selection mode is browse or extended then the new active entry is also selected and all other entries are deselected. In extended mode the new active entry becomes the selection anchor.
  6. In extended mode, Shift-Up and Shift-Down move the location cursor (active entry) up or down one entry and also extend the selection to that entry in a fashion similar to dragging with mouse button 1.
  7. The Left and Right keys scroll the treeview widget view left and right by the width of the character 0. Control-Left and Control-Right scroll the treeview widget view left and right by the width of the window. Control-Prior and Control-Next also scroll left and right by the width of the window. (yes, the width of the literal character 0, that's not a typo, that's just the unit they picked ๐Ÿ’€)
  8. The Prior and Next keys scroll the treeview widget view up and down by one page (the height of the window).
  9. The Home and End keys scroll the treeview widget horizontally to the left and right edges, respectively.
  10. Control-Home sets 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 ๐Ÿซถ)
  11. Control-End sets the location cursor to the the last entry, selects that entry, and deselects everything else in the widget.
  12. In extended mode, Control-Shift-Home extends the selection to the first entry and Control-Shift-End extends the selection to the last entry.
  13. In multiple mode, Control-Shift-Home moves the location cursor to the first entry and Control-Shift-End moves the location cursor to the last entry.
  14. The space and Select keys make a selection at the location cursor (active entry) just as if mouse button 1 had been pressed over this entry.
  15. In extended mode, Control-Shift-space and Shift-Select extend the selection to the active entry just as if button 1 had been pressed with the Shift key down.
  16. In extended mode, the Escape key 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 ๐Ÿ˜ญ
  17. Control-slash selects everything in the widget, except in single and browse modes, in which case it selects the active entry and deselects everything else.
  18. Control-backslash deselects everything in the widget, except in browse mode where it has no effect.
  19. The F16 key (labelled Copy on many Sun workstations) or Meta-w copies 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 -command option) 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 โœจ

  • treeview
  • widget

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