A simple way of toggling text is to assign a tag and manipulate its -invisible option, again using the event handling capability of a tag to control the setting. Notice that the snippet below, for each array two tags are created _${a} and _${a}_ where the former is the display header with the control, and the latter the tag to be elided.
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
package require Gnocl
set txt [gnocl::text -tabs 150 -editable 0]
gnocl::window -child $txt -onDelete { exit } -setSize 0.25
array set app [gnocl::application]
array set fruit [list apple 1 bannana 2 cherry 3]
array set cars [list morris a humber b austin c]
proc addLabel {wid str tag} {
$wid addChild [gnocl::label -text $str]
$wid tag apply lineStart lineEnd -tags $tag
$wid insert end \n
}
proc tagClick {w n event} {
if { $event == "buttonPress-1" } {
$w tag configure ${n}_ -invisible [ gnocl::toggle [$w tag cget ${n}_ -invisible]]
}
}
foreach a [list fruit cars app] {
$txt tag create _$a -paragraph blue -onEvent { %w clearSelection ; tagClick %w %n %t-%b }
$txt insert end $a\n -tags _$a
foreach n [array names $a] {
$txt tag create _${a}_ -indent 10 -data 1
$txt insert end "${n}\t[set ${a}($n)]\n" -tags _${a}_
}
}
$txt tag create _${a}_ -indent 10 -data 1
$txt insert end "${n}\t[set ${a}($n)]\n" -tags _${a}_
}
}
Comments