iwidgets::hierarchy(1)
π iwidgets::hierarchy π
okay so bestie, this is the iwidgets::hierarchy manual page from the [incr Widgets] collection. It creates and manipulates a hierarchy widget. periodt. π
πΈ NAME πΈ
iwidgets::hierarchy β Create and manipulate a hierarchy widget. That's the whole vibe. π¦
β¨ SYNOPSIS β¨
iwidgets::hierarchy pathName ?options?
π¦ INHERITANCE π¦
itk::Widget <- iwidgets::Labeledwidget <- iwidgets::Scrolledwidget <-
iwidgets::Hierarchy
β STANDARD OPTIONS β
activeBackgroundactiveForegroundbackgroundborderWidthcursordisabledForegroundforegroundhighlightColorhighlightThicknessreliefselectBackgroundselectForeground
Peep the options manual entry for the full tea on these standard options. π
π ASSOCIATED OPTIONS π
activeReliefelementBorderWidthjumptroughColor
The scrollbar widget manual entry has the details on those associated options above. Slay. β¨
spacing1spacing2spacing3tabs
The text widget manual entry has the details on those associated options above. π«Ά
π INHERITED OPTIONS π
labelBitmaplabelFontlabelImagelabelMarginlabelPoslabelTextlabelVariablesticky
The labeledwidget class manual entry has the details on those inherited options. π
π WIDGET-SPECIFIC OPTIONS π
- Name:
alwaysQueryClass:AlwaysQueryCommand-Line Switch:-alwaysquery
Boolean flag, bestie. It tells the hierarchy widget whether or not every refresh of the display should go get a fresh query using the command value of the -querycommand option, or just use the values it found last time the query was made. Default? no.
- Name:
closedIconClass:IconCommand-Line Switch:-closedicon
Names an existing closed icon image to show in the hierarchy before nodes that are collapsed. If you don't give one, a folder icon gets generated β pixmap if possible, bitmap otherwise. Iconic. π
- Name:
dblClickCommandClass:CommandCommand-Line Switch:-dblclickcommand
Command to run when the user double-clicks (mouse button one) the text label of an entry. If it has %n, that gets swapped for the name of the selected node. If it has %s, a boolean indicator of the node's current selection status gets substituted.
- Name:
expandedClass:ExpandedCommand-Line Switch:-expanded
When true, the hierarchy is fully expanded the first time it's displayed. Want a fresh display? Reset the -querycommand option. Default is false.
- Name:
filterClass:FilterCommand-Line Switch:-filter
When true, only branch nodes and selected items show up. Compact view of the important stuff. Default false.
- Name:
heightClass:HeightCommand-Line Switch:-height
Sets the height of the whole hierarchy as one unit. Value can be in any form Tk_GetPixels accepts. Extra space needed for labels, margins, scrollbars etc. forces the hierarchy to squish. If you set this to zero and width to zero too, then the visibleitems option's value takes over and handles geometry constraints a different way. Default height is zero.
- Name:
iconCommandClass:CommandCommand-Line Switch:-iconcommand
Command to run when the user selects (mouse button one) any extra icons given in the values returned by the command tied to the -querycommand option. %n becomes the name of the node the icon belongs to. %i becomes the icon name.
- Name:
iconDblCommandClass:CommandCommand-Line Switch:-icondblcommand
Command to run when the user double-clicks (mouse button one) the icon of an entry. %n becomes the name of the node the icon belongs to. %i becomes the icon name.
- Name:
imageCommandClass:CommandCommand-Line Switch:-imagecommand
Command to run when the user selects an image of an entry. %n becomes the name of the selected node. %s becomes a boolean indicator of the node's current selection status.
- Name:
imageDblCommandClass:CommandCommand-Line Switch:-imagedblcommand
Command to run when the user double-clicks (mouse button one) the image of an entry. %n becomes the name of the node the icon belongs to. %i becomes the icon name.
- Name:
imageMenuLoadCommandClass:CommandCommand-Line Switch:-imagemenuloadcommand
Command to run when the user selects (mouse button three) the image or icon; it dynamically loads the itemMenu for the widget.
- Name:
markBackgroundClass:ForegroundCommand-Line Switch:-markbackground
Background color to use when displaying marked nodes.
- Name:
markForegroundClass:BackgroundCommand-Line Switch:-markforeground
Foreground color to use when displaying marked nodes.
- Name:
menuCursorClass:CursorCommand-Line Switch:-menucursor
Mouse cursor for the item and background menus. Value can be any form Tk_GetCursor accepts.
- Name:
nodeIconClass:IconCommand-Line Switch:-nodeicon
Names an existing node icon image to show in the hierarchy before nodes that are leafs. If you don't provide one, a dog-eared page icon gets generated β pixmap if possible, bitmap otherwise.
- Name:
openIconClass:IconCommand-Line Switch:-openicon
Names an existing open icon image to show in the hierarchy before nodes that are expanded. If you don't provide one, an open folder icon gets generated β pixmap if possible, bitmap otherwise.
- Name:
queryCommandClass:CommandCommand-Line Switch:-querycommand
Specifies the command executed to query the contents of each node. If this command contains %n, it gets replaced with the name of the desired node. In its simplest form it should return the children of the given node as a list, which will be depicted in the display. Since the names of the children are used as tags in the underlying text widget, each child must be unique in the hierarchy. Because of that unique requirement, the nodes shall be referred to as uids or uid in the singular sense. The format of returned list is:
{uid [uid ...]}
where uid is a unique id and primary key for the hierarchy entry
If the unique requirement is a problem, the returned list can take on another, more extended form that enables associating text to be displayed with the uids. The uid must still be unique, but the text does not have to obey the unique rule. Plus, the format also allows specifying additional tags to be used on the same entry in the hierarchy as the uid, and additional icons to be displayed just before the node. The tags and icons are considered to be the property of the user β the hierarchy widget will not depend on any of their values. The extended format is:
{{uid [text [tags [icons]]]} {uid [text [tags [icons]]]} ...}
where uid is a unique id and primary key for the hierarchy entry
text is the text to be displayed for this uid
tags is a list of user tags to be applied to the entry
icons is a list of icons to be displayed in front of the text
The hierarchy widget does a look ahead from each node to determine if the node has a children. This can cost some performance with large hierarchies. Users can avoid this by providing a hint in the user tags. A tag of "leaf" or "branch" tells the hierarchy widget the information it needs to know, thereby avoiding the look ahead operation.
- Name:
hscrollModeClass:ScrollModeCommand-Line Switch:-hscrollmode
Display mode for the horizontal scrollbar: static, dynamic, or none. In static mode, the scrollbar is always there. dynamic shows it as needed. none disables it. Default is static.
- Name:
sbWidthClass:WidthCommand-Line Switch:-sbwidth
Width of the scrollbar, in any form Tk_GetPixels accepts.
- Name:
scrollMarginClass:MarginCommand-Line Switch:-scrollmargin
Distance between the text part of the hierarchy and the scrollbars, in any form Tk_GetPixels accepts. Default is 3 pixels.
- Name:
selectCommandClass:CommandCommand-Line Switch:-selectcommand
part 2 incoming, don't touch that dial π
- the node-selection command option β specifies a Tcl command to be evaluated when you select a node in the hierarchy via left mouse click. If
"%n"is included in the command, it is substituted with the node name. Similarly,"%s"is substituted with the node's current selection status:1for selected,0otherwise. - Name:
textBackgroundΒ· Class:BackgroundΒ· Command-Line Switch:-textbackgroundβ specifies the background color for the text portion of the hierarchy, in any of the forms acceptable toTk_GetColor. - Name:
textFontΒ· Class:FontΒ· Command-Line Switch:-textfontβ specifies the font to be used in the text portion of the hierarchy. π - Name:
textMenuLoadCommandΒ· Class:CommandΒ· Command-Line Switch:-textmenuloadcommandβ specifies a command to be executed upon user selection via mouse button three, that will dynamically load theitemMenufor the widget. - Name:
visibleitemsΒ· Class:VisibleItemsΒ· Command-Line Switch:-visibleitemsβ specifies thewidthxheightin characters and lines for the hierarchy. Bestie, listen: this option is only administered if thewidthandheightoptions are both set to zero, otherwise they take precedence. The default value is80x24. With thevisibleitemsoption engaged, geometry constraints are maintained only on the text portion of the hierarchy. The size of the other components such as labels, margins, and scroll bars, are additive and independent, effecting the overall size of the hierarchy. In contrast, should thewidthandheightoptions have non zero values, they are applied to the hierarchy as a whole. The hierarchy is compressed or expanded to maintain the geometry constraints. - Name:
vscrollModeΒ· Class:ScrollModeΒ· Command-Line Switch:-vscrollmodeβ specifies the display mode to be used for the vertical scrollbar:static,dynamic, ornone. Instaticmode, the scroll bar is displayed at all times.Dynamicmode displays the scroll bar as required, andnonedisables the scroll bar display. The default isstatic. π - Name:
widthΒ· Class:WidthΒ· Command-Line Switch:-widthβ specifies the width of the hierarchy as an entire unit. The value may be specified in any of the forms acceptable toTk_GetPixels. Any additional space needed to display the other components such as labels, margins, and scrollbars force the text portion of the hierarchy to be compressed. A value of zero along with the same value for theheightcauses the value given for thevisibleitemsoption to be applied, which administers geometry constraints in a different manner. The default width is zero.
β¨ DESCRIPTION β¨
The iwidgets::hierarchy command creates a hierarchical data view widget. It lets you graphically manage a list of nodes that can be expanded or collapsed. Individual nodes can be highlighted. Clicking with the right mouse button on any item brings up a special item menu. Clicking on the background area brings up a different popup menu. Options exist to provide user control over the loading of the nodes and actions associated with node selection. Since the hierarchy is based on the scrolledtext widget, it includes options to control the method in which the scrollbars are displayed, i.e. statically or dynamically. Options also exist for adding a label to the hierarchy and controlling its position. π¦
π METHODS π
The iwidgets::hierarchy command creates a new Tcl command whose name is pathName. This command may be used to invoke various operations on the widget. It has the following general form:
pathName option ?arg arg ...?
Option and the args determine the exact behavior of the command. The following commands are possible for hierarchy widgets:
πΈ ASSOCIATED METHODS πΈ
bbox compare debug delete dlineinfo dump get index insert scan search see tag window xview yview
See the "text" manual entry for details on the standard methods. π
π WIDGET-SPECIFIC METHODS π
pathName cget optionβ Returns the current value of the configuration option given byoption.Optionmay have any of the values accepted by theiwidgets::hierarchycommand.pathName clearβ Removes all items from the hierarchy display including all tags and icons. The display will remain empty until the-filteror-querycommandoptions are set.pathName collapse uidβ Collapses the hierarchy beneath the node with the specified unique id by one level. Since this can take a moment for large hierarchies, the cursor will be changed to a watch during the collapse. Also, if any of the nodes beneath the node being collapsed are selected, their status is changed to unselected.pathName configure ?option? ?value option value ...?β Query or modify the configuration options of the widget. If nooptionis specified, returns a list describing all of the available options forpathName(seeTk_ConfigureInfofor information on the format of this list). Ifoptionis specified with novalue, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if nooptionis specified). If one or moreoption-valuepairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string.Optionmay have any of the values accepted by theiwidgets::hierarchycommand.pathName currentβ Returns the tags for the node that was most recently selected by the right mouse button when the item menu was posted. Usually used by the code in the item menu to figure out what item is being manipulated.pathName draw ?when?β Performs a complete redraw of the entire hierarchy.Whenmay be either-nowor-eventuallywhere the latter means the draw can be performed after idle.pathName expand uidβ Expands the hierarchy beneath the node with the specified unique id by one level. Since this can take a moment for large hierarchies, the cursor will be changed to a watch during the expansion. βpathName expanded uidβ Returns the current state of expansion for the node with the specified unique id.pathName expStateβ Returns a list of all expanded nodes in the tree.pathName mark option ?arg arg ...?β This command is used to manipulate marks, which is quite similar to selection, adding a secondary means of hilighting an item in the hierarchy. The exact behavior of the command depends on theoptionargument that follows themarkargument. The following forms of the command are currently supported:pathName mark clearβ Clears all the currently marked nodes in the hierarchy.pathName mark add uid ?uid uid ...?β Marks the nodes with the specifieduidsin the hierarchy using the-markbackgroundand-markforegroundoptions and without affecting the mark state of any other nodes that were already marked.pathName mark remove uid ?uid uid ...?β Unmarks the nodes with the specifieduidsin the hierarchy without affecting the mark state of any other nodes that were already marked.pathName mark getβ Returns a list of the unique ids that are currently marked.
pathName refresh uidβ Performs a redraw of a specific node that has the givenuid. If the node is not currently visible or in other words already drawn on the text, then no action is taken.pathName prune uidβ Removes the node specified by the givenuidfrom the hierarchy. Should the node have children, then all of its children will be removed as well. πpathName selection option ?arg arg ...?β This command is used to manipulate the selection of nodes in the hierarchy. The exact behavior of the command depends on theoptionargument that follows theselectionargument. The following forms of the command are currently supported:pathName selection clearβ Clears all the currently selected nodes in the hierarchy.pathName selection add uid ?uid uid ...?β Selects the nodes with the specifieduidsin the hierarchy using the-selectionbackgroundand-selectionforegroundoptions and without affecting the selection state of any other nodes that were already selected.pathName selection remove uid ?uid uid ...?β Deselects the nodes with the specifieduidsin the hierarchy without affecting the selection state of any other nodes that were already selected.pathName selection getβ Returns a list of the unique ids that are currently selected.
Heads up bestie, this one matters: a node's selection status is also dependent on it being visible. If a node is selected and its parent is then collapsed making the selected node not visible, then its selection status is changed to unselected. π
pathName toggle uidβ Toggles the hierarchy beneath the node with the specified unique id. If the hierarchy is currently expanded, then it is collapsed, and vice-versa. π«Ά
β¨ COMPONENTS β¨
okay bestie, this widget is literally built out of five little sub-widgets and they all have names, classes, and jobs. let's meet the whole squad π
- Name:
listClass:Text
the list component is the text widget where the whole hierarchy actually shows up. it's the main character of the display, fr fr. for all the deets on the text component item, go read the "text" widget manual entry. π
- Name:
bgMenuClass:Menu
the bgMenu component is the popup menu that shows up when you press the right mouse button in the background β like, not over any specific node. so you right-click the empty void and boom, menu. πΈ you can add menu items and their commands through the component command. for all the deets on the bgMenu component item, check the "menu" widget manual entry.
- Name:
horizsbClass:Scrollbar
the horizsb component is the horizontal scroll bar. that's it, that's the vibe. sideways scrolling energy β¨ see the "scrollbar" widget manual entry for the details on the horizsb component item.
- Name:
itemMenuClass:Menu
the itemMenu component is the popup menu that pops off when you select a hierarchy node with the right mouse button. right-click on a node instead of the void β different menu, slay. π menu items can be added along with their commands via the component command. see the "menu" widget manual entry for details on the itemMenu component item.
- Name:
vertsbClass:Scrollbar
the vertsb component is the vertical scroll bar. up-and-down, the classic. π¦ see the "scrollbar" widget manual entry for details on the vertsb component item.
π EXAMPLE π
okay this is the part where it all comes together. here's the actual example, copied exactly so you can just vibe and run it:
package require Iwidgets 4.0 proc get_files {file} {
global env
if {$file == ""} {
set dir $env(HOME)
} else {
set dir $file
}
if {[catch {cd $dir}] != 0} {
return ""
}
set rlist ""
foreach file [lsort [glob -nocomplain *]] {
lappend rlist [list [file join $dir $file] $file]
}
return $rlist }
iwidgets::hierarchy .h -querycommand "get_files %n" -visibleitems 30x15
-labeltext $env(HOME) pack .h -side left -expand yes -fill both
lowkey iconic. a get_files proc that walks a directory and hands back {path name} pairs, wired straight into -querycommand "get_files %n", with -visibleitems 30x15 and -labeltext $env(HOME), then packed -side left -expand yes -fill both. periodt. π
π AUTHOR π
Mark L. Ulferts Michael J. McLennan
π KEYWORDS π
hierarchy, text, widget
that's the whole page bestie!! this one came out of the Tk source, and it's the iwidgets::hierarchy(1) manual entry β the classic manpage footer energy, just with way better vibes. go build something cute with it πβ¨π
π¦ where this page comes from
- debian bookworm: iwidgets4-doc 4.1.1-2.1
- debian trixie: iwidgets4-doc 4.1.1-4
- ubuntu jammy: iwidgets4-doc 4.1.1-2.1
- ubuntu noble: iwidgets4-doc 4.1.1-2.1
- ubuntu resolute: iwidgets4-doc 4.1.1-4
- ubuntu stonking: iwidgets4-doc 4.1.1-4
- Copyright (c) 1997 DSC Technologies Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms