/usr/share/doc/tix/examples/MkSample.tcl is in tix-dev 8.4.3-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
#
# $Id: MkSample.tcl,v 1.3 2001/12/09 05:34:59 idiscovery Exp $
#
# MkSample.tcl --
#
# This file implements the "Sample" page in the widget demo
#
# This file has not been properly documented. It is NOT intended
# to be used as an introductory demo program about Tix
# programming. For such demos, please see the files in the
# demos/samples directory or go to the "Samples" page in the
# "widget demo"
#
#
# Copyright (c) 1996, Expert Interface Technologies
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#
#
set tix_demo_running 1
set samples_dir [file join $demo_dir samples]
set sample_filename {}
uplevel #0 source [list [file join $samples_dir AllSampl.tcl]]
proc MkSample {nb page} {
global tixOption
#----------------------------------------------------------------------
set w [$nb subwidget $page]
set pane [tixPanedWindow $w.pane -orient horizontal]
pack $pane -expand yes -fill both
set f1 [$pane add 1 -expand 1]
set f2 [$pane add 2 -expand 3]
$f1 config -relief flat
$f2 config -relief flat
# Left pane: the Tree:
#
set lab [label $f1.lab -text "Select a sample program:" -anchor w]
set tree [tixTree $f1.slb \
-options {
hlist.selectMode single
hlist.width 40
}]
$tree config \
-command "Sample:Action $w $tree run" \
-browsecmd "Sample:Action $w $tree browse"
pack $lab -side top -fill x -padx 5 -pady 5
pack $tree -side top -fill both -expand yes -padx 5
# Right pane: the Text
#
set labe [tixLabelEntry $f2.lab -label "Source:" -options {
label.anchor w
}]
$labe subwidget entry config -state disabled
set stext [tixScrolledText $f2.stext]
set f3 [frame $f2.f3]
set run [button $f3.run -text "Run ..." \
-command "Sample:Action $w $tree run"]
set view [button $f3.view -text "View Source in Browser ..." \
-command "Sample:Action $w $tree view"]
pack $run $view -side left -fill y -pady 2
pack $labe -side top -fill x -padx 7 -pady 2
pack $f3 -side bottom -fill x -padx 7
pack $stext -side top -fill both -expand yes -padx 7
#
# Set up the text subwidget
set text [$stext subwidget text]
bind $text <Up> "%W yview scroll -1 unit"
bind $text <Down> "%W yview scroll 1 unit"
bind $text <Left> "%W xview scroll -1 unit"
bind $text <Right> "%W xview scroll 1 unit"
bind $text <Tab> {focus [tk_focusNext %W]; break}
bindtags $text "$text Text [winfo toplevel $text] all"
$text config -bg [$tree subwidget hlist cget -bg] \
-state disabled -font $tixOption(fixed_font) -wrap none
$run config -state disabled
$view config -state disabled
global demo
set demo(w:run) $run
set demo(w:view) $view
set demo(w:tree) $tree
set demo(w:lab1) $labe
set demo(w:stext) $stext
set hlist [$tree subwidget hlist]
$hlist config -separator "." -width 30 -drawbranch 0 \
-wideselect false
set style [tixDisplayStyle imagetext -refwindow $hlist \
-fg $tixOption(fg) -padx 4]
set file [tix getimage textfile]
set folder [tix getimage openfold]
ForAllSamples root "" \
[list AddSampleToHList $tree $hlist $style $file $folder]
}
# AddSampleToHList --
#
# A callback from ForAllSamples. Add all the possible sample files
# into the Tree widget.
#
proc AddSampleToHList {tree hlist style file folder token type text dest} {
case $type {
d {
return [$hlist addchild $token -itemtype imagetext -style $style \
-image $folder -text $text]
}
done {
if {![tixStrEq $token ""]} {
$tree setmode $token close
$tree close $token
}
}
f {
return [$hlist addchild $token -itemtype imagetext \
-image $file -text $text -data [list $text $dest]]
}
}
}
proc Sample:Action {w slb action args} {
global samples demo_dir demo samples_dir
set hlist [$slb subwidget hlist]
set ent [$hlist info anchor]
if {$ent == ""} {
$demo(w:run) config -state disabled
$demo(w:view) config -state disabled
return
}
if {[$hlist info data $ent] == {}} {
# This is just a comment
$demo(w:run) config -state disabled
$demo(w:view) config -state disabled
return
} else {
$demo(w:run) config -state normal
$demo(w:view) config -state normal
}
set theSample [$hlist info data $ent]
set title [lindex $theSample 0]
set prog [lindex $theSample 1]
case $action {
"run" {
RunProg $title $prog
}
"view" {
LoadFile [file join $samples_dir $prog]
}
"browse" {
# Bring up a short description of the sample program
# in the scrolled text about
set text [$demo(w:stext) subwidget text]
uplevel #0 set sample_filename [list [file join $samples_dir $prog]]
tixWidgetDoWhenIdle ReadFileWhenIdle $text
$demo(w:lab1) subwidget entry config -state normal
$demo(w:lab1) subwidget entry delete 0 end
$demo(w:lab1) subwidget entry insert end [file join $samples_dir $prog]
$demo(w:lab1) subwidget entry xview end
$demo(w:lab1) subwidget entry config -state disabled
}
}
}
proc RunProg {title prog} {
global samples demo_dir demo samples_dir
set w .[lindex [split $prog .] 0]
set w [string tolower $w]
if [winfo exists $w] {
wm deiconify $w
raise $w
return
}
uplevel #0 source [list [file join $samples_dir $prog]]
toplevel $w
wm title $w $title
RunSample $w
}
proc LoadFile {filename} {
global tixOption
set tmp $filename
regsub -all . $filename _ tmp
set w [string tolower .$tmp]
if [winfo exists $w] {
wm deiconify $w
raise $w
return
}
toplevel $w
wm title $w "Source View: $filename"
button $w.b -text Close -command "destroy $w"
set t [tixScrolledText $w.text]
tixForm $w.b -left 0 -bottom -0 -padx 4 -pady 4
tixForm $w.text -left 0 -right -0 -top 0 -bottom $w.b
$t subwidget text config -highlightcolor [$t cget -bg] -bd 2 \
-bg [$t cget -bg] -font $tixOption(fixed_font)
if {$filename == {}} {
return
}
set text [$w.text subwidget text]
$text config -wrap none
ReadFile $text $filename
}
proc ReadFileWhenIdle {text} {
global sample_filename
if ![file isdir $sample_filename] {
ReadFile $text $sample_filename
}
}
proc ReadFile {text filename} {
set oldState [$text cget -state]
$text config -state normal
$text delete 0.0 end
set fd [open $filename {RDONLY}]
$text delete 1.0 end
while {![eof $fd]} {
$text insert end [gets $fd]\n
}
close $fd
$text see 1.0
$text config -state $oldState
}
|