dgw::tvmixins

NAME

dgw::tvmixins - functionality extensions for the ttk::treeview widget such as sorting, tooltips, banding stripes, key based navigation.

DESCRIPTION

dgw::tvmixins - The package dgw::tvmixins implements several snit::widgetadaptors which extend the standard *ttk::treeview* widget with different functionalities. Different adaptors can be chained together to add the required functionalities. Please note that most of the functionalities are not coded mainly by the author of the package DDG but just wrappers of the functionalities into snit::widgetadaptors for easy usage and combining the different properties and functionalities.

The following adaptors are currently available:

  • dgw::tvband - providing banding stripes (will be obsolete with Tcl/Tk 8.7)
  • dgw::tvedit - inline edit of cells of a ttk::treeview widget, code based on Inplace edit in ttk::treeview
  • dgw::tvfilebrowser - providing a interactive file browser widget with standard icons
  • dgw::tvksearch - key based navigation using Home and End keys as well as by typing starting letters
  • dgw::tksortable - adds easily sorting facilities to the treeview widget as well a <<SortEnd>> event
  • dgw::tvtooltip - adds row tooltips by providing <<RowEnter>> and <<RowLeave>> events
  • dgw::tvtree - an addition to the *ttk::treeview* with open and close response images

There is further a convenience function which simplifies addition of adaptors without a lot of nesting calls:

  • dgw::mixin - add widgets adaptors to existing widgets

LINKS

EXAMPLE

# wrapper function 
proc fbrowse {path args} {
    set fb [dgw::tvtooltip [dgw::tvsortable [dgw::tvksearch \
        [dgw::tvfilebrowser [dgw::tvband \
        [ttk::treeview $path]] {*}$args]] \
         -sorttypes [list Name directory Size real Modified dictionary]]]
     return $fb
}

set fb [fbrowse .fp2]
pack $fb -side top -fill both -expand yes
pack [::ttk::label .msg -font "Times 12 bold" -textvariable ::msg -width 20 \
     -background salmon -borderwidth 2 -relief ridge] \
     -side top -fill x -expand false -ipadx 5 -ipady 4
bind $fb <<RowEnter>> { set ::msg "  Entering row %d"}
bind $fb <<RowLeave>> { set ::msg "  Leaving row %d"}

See the following image for an example run:

treeview-mixin-image-04

Here an addition to the example before which uses in the third example the dgw::mixin command for stepwise addition of widget adaptors:

# wrapper function 
proc fbrowse {path args} {
     set fb [dgw::tvtooltip [dgw::tvsortable [dgw::tvksearch \
        [dgw::tvfilebrowser [dgw::tvband \
        [ttk::treeview $path]] {*}$args]] \
         -sorttypes [list Name directory Size real Modified dictionary]]]
     return $fb
}
set pw [ttk::panedwindow .pw -orient horizontal]
set f0 [ttk::frame $pw.f]
set f1 [ttk::frame $f0.f]
set fb [fbrowse $f1.fb]
pack $fb -side left -fill both -expand yes
pack [ttk::scrollbar $f1.yscroll -command [list $fb yview]] \
      -side left -fill y -expand false
$fb configure -yscrollcommand [list $f1.yscroll set]
pack $f1 -side top -fill both -expand true
# demo tvtooltip
pack [::ttk::label $f0.msg -font "Times 12 bold" -textvariable ::msg -width 20 \
     -background salmon -borderwidth 2 -relief ridge] \
     -side top -fill x -expand false -ipadx 5 -ipady 4
bind $fb <<RowEnter>> { set ::msg "  Entering row %d"}
bind $fb <<RowLeave>> { set ::msg "  Leaving row %d"}

$pw add $f0
set tree [dgw::tvtree [ttk::treeview $pw.tree -height 15 -show tree -selectmode browse] -icon folder]
foreach txt {first second third} {
   set id [$tree insert {} end -text " $txt item" -open 1]
   for {set i [expr {1+int(rand()*5)}]} {$i > 0} {incr i -1} {
       set child [$tree insert $id 0 -text " child $i"]
       for {set j [expr {int(rand()*3)}]} {$j > 0} {incr j -1} {
          $tree insert $child 0 -text " grandchild $i"
       }
   }
}
$pw add $tree

# another example using mixin syntax
set tv [ttk::treeview $pw.tv -columns "A B C" -show headings]
dgw::mixin $tv dgw::tvsortable

$tv heading A -text A
$tv heading B -text B
$tv heading C -text C
$pw add $tv
for {set i 0} {$i < 20} {incr i} { 
    $tv insert {} end -values [list [expr {rand()*4}] \
        [expr {rand()*10}] [expr {rand()*20}]] 
}
dgw::mixin $tv dgw::tvband
$tv configure  -bandcolors [list white ivory]
pack $pw -side top -fill both -expand true

treeview-mixin-image-06

CHANGES

  • 2020-04-10: 0.2 first official release
  • 2020-04-14: 0.3 second release which adds the dgw::mixin command and dgw::tvedit and dgw::tvtree adaptors

SEE ALSO

  • ttk::treeview mixins - initial starting version of this package
  • dgw::basegui - application framework which as well delivers a set of small functionalities embeddable into existing or new Tk applications.

DISCUSSION

Please discuss here.