basegui - combobox - dgw - drawcanvas - hyperhelp - sbuttonbar - seditor - sfilebrowser - sfinddialog - sqlview - statusbar - tablelist - tlistbox - tvmixins

dgw::tvmixins 0.3

Detlef Groth, Schwielowsee, Germany

2020-04-16

NAME

dgw::tvmixins - implementations of extensions for the ttk::treeview widget which can be added dynamically using chaining of commands at widget creation or using the dgw::mixin command after widget creation.

TABLE OF CONTENTS

SYNOPSIS

package require Tk
package require snit
package require dgw::tvmixins
::dgw::mixin pathName widgetAdaptor ?options?
::dgw::tvband [ttk::treeview pathName ?options?] ?options?
::dgw::tvedit [ttk::treeview pathName ?options?] ?options?
::dgw::tvfilebrowser [ttk::treeview pathName ?options?] ?options?
::dgw::tvksearch [ttk::treeview pathName ?options?] ?options?
::dgw::tvsortable [ttk::treeview pathName ?options?] ?options?
::dgw::tvtooltip [ttk::treeview pathName ?options?] ?options?
::dgw::tvtree [ttk::treeview pathName ?options?] ?options?
::dgw::tvfilebrowser [dgw::tvband [dgw::tvsortable [dgw::tvsearch \
     [ttk::treeview pathName ?options?] ?options?] ?options?] ?options?]
set tv [ttk::treeview pathName ?options?]
dgw::mixin $tv dgw::tvband ?options?

DESCRIPTION

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. Furthermore at any later time point using the dgw::mixin command other adaptors can be installed on the widget.

WIDGET COMMANDS

dgw::mixin pathName mixinWidget ?-option value ...?

Adds the properties and methods of a snit::widgetadaptor specified with mixinWidget to the exising widget created before with the given pathName and configures the widget using the given options.

Example:

# demo: mixin
# standard treeview widget
set tv [ttk::treeview .tv -columns "A B C" -show headings]
$tv heading A -text A
$tv heading B -text B
$tv heading C -text C
pack $tv -side top -fill both -expand true
# add  sorting after object creation using the mixin command
dgw::mixin $tv dgw::tvsortable
# fill the widget
for {set i 0} {$i < 20} {incr i} { 
    $tv insert {} end -values [list [expr {rand()*4}] \
        [expr {rand()*10}] [expr {rand()*20}]] 
}
# add another widget adaptor
dgw::mixin $tv dgw::tvband
# configure the new options of this adaptor at a later point
$tv configure  -bandcolors [list white ivory]

dgw::tvband [ttk::treeview pathName] ?-option value ...?

Creates and configures the dgw::tvband widget using the Tk window id pathName and the given options. Please note that this adaptor might have performace issues and that the ttk::treeview widget of Tk 8.7 probably will have a configure option -striped and -stripedbackgroundcolor which can replace this adaptor.

The following option is available:

Example:

# demo: tvband
dgw::tvband [ttk::treeview .fb -columns [list A B C] -show headings]
foreach col [list A B C] { .fb heading $col -text $col }
for {set i 0} {$i < 20} {incr i 1} {
   .fb insert {} end -values [list  [expr {int(rand()*100)}] \
                  [expr {int(rand()*1000)}] [expr {int(rand()*1000)}]]
}
pack .fb -side top -fill both -expand yes

dgw::tvedit [ttk::treeview pathName] ?-option value ...?

Creates and configures the dgw::tvedit widget using the Tk window id pathName and the given options. This widget adaptor allows to do in place edits of the text within the ttk::treeview widget. The code is largly based on the wiki code in Inplace edit in ttk::treeview. Note: Currently only tabular, non hierarchical ttk::treeview widget's can be edited.

The following options are available:

The widget provides the follwing events:

Bindings:

Example:

# demo: tvedit
proc editDone {args} {
      puts "done: $args"
}
pack [dgw::tvedit [ttk::treeview .tv -columns {bool int list} -show {headings} \
   -selectmode extended -yscrollcommand {.sb set}] \
   -edittypes [list bool bool int [list int 0 100]] \
   -editdefault "" -editendcmd editDone] -fill both -expand true -side left
pack [ttk::scrollbar .sb -orient v -command ".tv yview"] -fill y -side left
.tv insert {} end -values {true 15 {Letter B}}
.tv insert {} end -values {true 35 {Letter D}}
for {set i 0} {$i<20} {incr i} {
     .tv insert {} end -values [list true $i {Letter B}]
}
dgw::mixin .tv dgw::tvband

dgw::tvfilebrowser [ttk::treeview pathName] ?-option value ...?

Creates and configures the dgw::tvfilebrowser widget using the Tk window id pathName and the given options.

The following option is available:

The following method(s) is(are) available:

Example:

# demo: tvfilebrowser
dgw::tvfilebrowser [dgw::tvsortable [dgw::tvksearch [dgw::tvband \
         [ttk::treeview .fb]]] \
        -sorttypes [list Name directory Size real Modified dictionary]]
pack .fb -side top -fill both -expand yes

dgw::tvksearch [ttk::treeview pathName] ?-option value ...?

Creates and configures the dgw::tvksearch widget using the Tk window id pathName and the given options. With this widget you can use the Home and End keys for navigation and further letter typing starts searching in the first column shifting focus and display to the current matching entry.

There are currently no options or methods available for this widget.

Example:

# demo: tvksearch
dgw::tvfilebrowser [dgw::tvksearch [ttk::treeview .fb]]
pack .fb -side top -fill both -expand yes

dgw::tvsortable [ttk::treeview pathName] ?-option value ...?

Creates and configures the dgw::tvsortable widget using the Tk window id pathName and the given options.

The following option is available:

The following methods are available:

The widget further provides the following event:

Example:

# demo: tvsortable
dgw::tvsortable [dgw::tvband [ttk::treeview .fb -columns [list A B C] \
       -show headings]] -sorttypes [list A real B real C integer]
foreach col [list A B C] { .fb heading $col -text $col }
for {set i 0} {$i < 20} {incr i 1} {
   .fb insert {} end -values [list  [expr {int(rand()*100)}] \
                  [expr {int(rand()*1000)}] [expr {int(rand()*1000)}]]
}
pack .fb -side top -fill both -expand yes

dgw::tvtooltip [ttk::treeview pathName] ?-option value ...?

Creates and configures the dgw::tvtooltip widget using the Tk window id pathName and the given options.

There are currently no options available.

The widget provides the following events:

Example:

# demo: tvtooltip
set fb [dgw::tvtooltip [dgw::tvfilebrowser [ttk::treeview .fp2] \
         -directory . -fileimage movie \
         -filepattern {\.(3gp|mp4|avi|mkv|mp3|ogg)$}]]
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"}

dgw::tvtree [ttk::treeview pathName] ?-option value ...?

Creates and configures the dgw::tvtree widget using the Tk window id pathName and the given options.

There is(are) currently the following option(s) available:

The widget provides the following event:

Example:

# demo: tvtree
set tree [dgw::tvtree [ttk::treeview .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"
       }
   }
}
pack $tree -side top -fill both -expand true

EXAMPLE

In the examples below we create first a filebrowser widget using all the widget adaptors for demonstration purposes. Therafter comes a tooltip demonstration, a tree demonstration and finally a demonstration on how to use the dgw::mixin command which simplifies the addition of new behaviors to our ttk::treewidget in a stepwise manner. The latter approach is as well nice to extend existing widgets in a more controlled manner avoiding restarts of applications during developing the widget.

# 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

INSTALLATION

Installation is easy you can install and use the dgw::tvmixins package if you have a working install of:

For installation you copy the complete dgw folder into a path of your auto_path list of Tcl or you append the auto_path list with the parent dir of the dgw directory. Alternatively you can install the package as a Tcl module by creating a file dgw/tvmixins-0.3.tm in your Tcl module path.

Only if you you like to extract the HTML documentation and run the examples, you need the complete dgw package and for the HTML generation the tcllib Markdown package.

DEMO

Example code for this package in the EXAMPLE section can be executed by running this file using the following command line:

$ wish tvmixins.tcl --demo

Specific code examples outside of the EXAMPLE section can be executed using the string after the demo: prefix string in the code block for the individual code adaptors such as:

$ wish tvmixins.tcl --demo tvband

The example code used for the demo in the EXAMPLE section can be seen in the terminal by using the following command line:

$ tclsh tvmixins.tcl --code

DOCUMENTATION

The script contains embedded the documentation in Markdown format. To extract the documentation you should use the following command line:

$ tclsh tvmixins.tcl --markdown

This will extract the embedded manual pages in standard Markdown format. You can as well use this markdown output directly to create html pages for the documentation by using the --html flag.

$ tclsh tvmixins.tcl --html

If the tcllib Markdown package is installed, this will directly create a HTML page tvmixins.html which contains the formatted documentation.

Github-Markdown can be extracted by using the --man switch:

$ tclsh tvmixins.tcl --man

The output of this command can be used to feed a Markdown processor for conversion into a html, docx or pdf document. If you have pandoc installed for instance, you could execute the following commands:

tclsh ../tvmixins.tcl --man > tvmixins.md
pandoc -i tvmixins.md -s -o tvmixins.html
pandoc -i tvmixins.md -s -o tvmixins.tex
pdflatex tvmixins.tex

SEE ALSO

CHANGES

TODO

AUTHORS

The dgw::tvmixins widget was written by Detlef Groth, Schwielowsee, Germany.

Copyright

Copyright (c) 2020 Dr. Detlef Groth, E-mail: detlef(at)dgroth(dot)de

LICENSE

dgw::tvmixins package, version 0.3.

Copyright (c) 2019-2020 Dr. Detlef Groth, E-mail: detlef(at)dgroth(dot)de

This library is free software; you can use, modify, and redistribute it for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions.

This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.