| 1 |
#!/usr/bin/env wish |
| 2 |
|
| 3 |
#package require BLT |
| 4 |
# -------------------------------------------------------------------------- |
| 5 |
# Starting with Tcl 8.x, the BLT commands are stored in their own |
| 6 |
# namespace called "blt". The idea is to prevent name clashes with |
| 7 |
# Tcl commands and variables from other packages, such as a "table" |
| 8 |
# command in two different packages. |
| 9 |
# |
| 10 |
# You can access the BLT commands in a couple of ways. You can prefix |
| 11 |
# all the BLT commands with the namespace qualifier "blt::" |
| 12 |
# |
| 13 |
# blt::graph .g |
| 14 |
# blt::table . .g -resize both |
| 15 |
# |
| 16 |
# or you can import all the command into the global namespace. |
| 17 |
# |
| 18 |
# namespace import blt::* |
| 19 |
# graph .g |
| 20 |
# table . .g -resize both |
| 21 |
# |
| 22 |
# -------------------------------------------------------------------------- |
| 23 |
if { $tcl_version >= 8.0 } { |
| 24 |
namespace import -force blt::* |
| •25 |
#interp alias {} table {} blttable |
| 26 |
#namespace import -force blt::tile::* |
| 27 |
} |
| 28 |
source scripts/demo.tcl |
| 29 |
#option add *Scrollbar.relief flat |
| 30 |
set oldLabel "dummy" |
| 31 |
#wm geometry . 1020x750 |
| 32 |
variable pc |
| 33 |
set pc(-bgexec) 0 |
| 34 |
set pc(-tearoff) 0 |
| 35 |
array set pc $argv |
| 36 |
set pc(top) 0 |
| 37 |
set pc(win) {} |
| 38 |
|
| 39 |
set pc(int) {} |
| 40 |
proc killint {{c {}} {op {}} args} { |
| 41 |
variable pc |
| 42 |
if {$c == {}} { set c $pc(int) } |
| 43 |
if {$pc(int) != $c || $c == {}} return |
| 44 |
if {$op == "win" && [lindex $args 0] != "."} return |
| 45 |
set pc(int) {} |
| 46 |
#puts "KILL [info level 0]" |
| 47 |
catch "interp delete $c" |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
proc RunDemo { program } { |
| 52 |
variable pc |
| 53 |
set tt .pw.swd.tab |
| 54 |
if {[string tolower [file extension [set pfile $program]]] != ".tcl"} { |
| 55 |
append pfile .tcl |
| 56 |
} |
| 57 |
if { ![file exists $pfile] } { |
| 58 |
return |
| 59 |
} |
| 60 |
if {$pc(-bgexec)} { |
| 61 |
global programInfo |
| 62 |
set cmd [list [info nameofexecutable] $pfile -name "demo:$program" -geom -4000-4000] |
| 63 |
if { [info exists programInfo(lastProgram)] } { |
| 64 |
set programInfo($programInfo(lastProgram)) 0 |
| 65 |
} |
| 66 |
eval bgexec programInfo($program) $cmd & |
| 67 |
set programInfo(lastProgram) $program |
| 68 |
} else { |
| 69 |
} |
| 70 |
$tt.f2.t delete 1.0 end |
| 71 |
set data [read [set fp [open $pfile]]] |
| 72 |
close $fp |
| 73 |
$tt.f2.t insert end $data |
| 74 |
update |
| 75 |
#puts stderr [$tt.f1 find -name demo:$program] |
| 76 |
if {$pc(-bgexec)} { |
| 77 |
$tt.f1 configure -name demo:$program |
| 78 |
} else { |
| 79 |
set w .pw.swd.tab.f1.f |
| 80 |
if {[winfo exists $w]} { destroy $w } |
| 81 |
if {$pc(int) != {}} { killint $pc(int) } |
| 82 |
set c [interp create] |
| 83 |
interp eval $c [list set auto_path $::auto_path] |
| 84 |
set tl [winfo toplevel $tt] |
| 85 |
set tl $tt |
| 86 |
set maxg [winfo width $tl]x[winfo height $tl] |
| 87 |
if {$pc(-tearoff)} { |
| 88 |
pack [container $w] -fill both -expand y |
| 89 |
$c eval "set argv { -geom $maxg }" |
| 90 |
$c eval "set argv0 {}" |
| 91 |
} else { |
| 92 |
pack [frame $w -container 1] -fill both -expand y |
| 93 |
$c eval "set argv {-use [winfo id $w] -geom $maxg }" |
| 94 |
$c eval "set argv0 {}" |
| 95 |
} |
| 96 |
|
| 97 |
catch {interp eval $c {load {} Tk}} |
| 98 |
interp eval $c {package require Tk} |
| 99 |
interp eval $c {package require BLT} |
| 100 |
interp eval $c "bind . <Destroy> {__delete_interp %W}" |
| 101 |
interp alias $c __delete_interp {} killint $c win |
| 102 |
interp alias $c exit {} killint $c exit |
| 103 |
update |
| 104 |
if {$pc(-tearoff)} { |
| 105 |
update |
| 106 |
$c eval { if {![winfo ismapped .]} { tkwait visibility .} } |
| 107 |
$w conf -window $c. |
| 108 |
set pc(win) $c. |
| 109 |
set pc(top) 0 |
| 110 |
} |
| 111 |
set pc(int) $c |
| 112 |
if {[catch {interp eval $c "source $pfile"} rc]} { |
| 113 |
tclLog "SRC=$pfile: $rc" |
| 114 |
} |
| 115 |
} |
| 116 |
if {$::tcl_platform(platform) == "unix"} { |
| 117 |
if {[catch { |
| 118 |
set prog [string trim $program {0123456789}] |
| 119 |
set man [exec man ../man/$prog.mann |& col -b] |
| 120 |
$tt.f3.t delete 1.0 end |
| 121 |
$tt.f3.t insert end $man |
| 122 |
} erc]} { |
| 123 |
tclLog "MAN=$pfile: $erc" |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
pack [panedwindow .pw] -fill both -expand y |
| 129 |
frame .pw.swt |
| 130 |
labelframe .pw.swd -text "Synopsis" |
| 131 |
hierbox .pw.swt.hier -separator "." -scrollmode canvas -xscrollincrement 1 \ |
| 132 |
-yscrollcommand { .pw.swt.yscroll set } -xscrollcommand { .pw.swt.xscroll set } \ |
| 133 |
-selectcommand { |
| 134 |
set index [.pw.swt.hier curselection] |
| 135 |
set label [.pw.swt.hier entry cget $index -label] |
| 136 |
.pw.swd configure -text $label |
| 137 |
.pw.swd.tab tab configure Example -window .pw.swd.tab.f1 |
| 138 |
if { $label != $oldLabel } { |
| 139 |
RunDemo $label |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
proc toplev {} { |
| 144 |
variable pc |
| 145 |
set ww .pw.swd.tab.f1.f |
| 146 |
set new [expr {!$pc(top)?$pc(win):{}}] |
| 147 |
if {$new != [$ww cget -window]} { |
| 148 |
$ww conf -window $new |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
scrollbar .pw.swt.yscroll -command { .pw.swt.hier yview } |
| 153 |
scrollbar .pw.swt.xscroll -command { .pw.swt.hier xview } -orient horizontal |
| 154 |
#label .pw.swt.mesg -relief groove -borderwidth 2 |
| 155 |
#label .pw.swd.title -text "Synopsis" -highlightthickness 0 |
| 156 |
if {$pc(-tearoff)} { |
| 157 |
pack [checkbutton .pw.swd.ext -variable ::pc(top) -text "Tearoff" -command "toplev"] -anchor e |
| 158 |
} |
| 159 |
tabset .pw.swd.tab -side bottom -relief flat -bd 0 -highlightthickness 0 \ |
| 160 |
-pageheight 4i |
| 161 |
|
| 162 |
.pw.swd.tab insert end \ |
| 163 |
"Example" \ |
| 164 |
"See Code" \ |
| 165 |
"Manual" |
| 166 |
|
| 167 |
image create photo graph.img -file images/mini-windows.gif |
| 168 |
|
| 169 |
.pw.swt.hier entry configure root -label "BLT" |
| 170 |
.pw.swt.hier insert end \ |
| 171 |
"Plotting" \ |
| 172 |
"Plotting.graph" \ |
| 173 |
"Plotting.graph.graph1" \ |
| 174 |
"Plotting.graph.graph2" \ |
| 175 |
"Plotting.graph.graph3" \ |
| 176 |
"Plotting.graph.graph4" \ |
| 177 |
"Plotting.graph.graph5" \ |
| 178 |
"Plotting.graph.graph6" \ |
| 179 |
"Plotting.barchart" \ |
| 180 |
"Plotting.barchart.barchart1" \ |
| 181 |
"Plotting.barchart.barchart2" \ |
| 182 |
"Plotting.barchart.barchart3" \ |
| 183 |
"Plotting.barchart.barchart4" \ |
| 184 |
"Plotting.barchart.barchart5" \ |
| 185 |
"Plotting.stripchart" \ |
| 186 |
"Plotting.stripchart.stripchart1" \ |
| 187 |
"Plotting.stripchart.spline" \ |
| 188 |
"Composition" \ |
| 189 |
"Composition.htext1" \ |
| 190 |
"Composition.tabset" \ |
| 191 |
"Composition.tabset.tabset1" \ |
| 192 |
"Composition.tabset.tabset2" \ |
| 193 |
"Composition.tabset.tabset3" \ |
| 194 |
"Composition.tabset.tabset4" \ |
| 195 |
"Composition.hierbox" \ |
| 196 |
"Composition.hierbox.hierbox1" \ |
| 197 |
"Composition.hierbox.hierbox2" \ |
| 198 |
"Composition.hierbox.hierbox3" \ |
| 199 |
"Composition.hierbox.hierbox4" \ |
| 200 |
"Composition.hiertable" \ |
| 201 |
"Composition.hiertable.hiertable1" \ |
| 202 |
"Composition.hiertable.hiertable2" \ |
| 203 |
"Composition.hiertable.hiertable3" \ |
| 204 |
"Composition.treeview" \ |
| 205 |
"Composition.treeview.treeview1" \ |
| 206 |
"Miscellaneous" \ |
| 207 |
"Miscellaneous.bitmap" \ |
| 208 |
"Miscellaneous.bitmap.bitmap" \ |
| 209 |
"Miscellaneous.bitmap.bitmap2" \ |
| 210 |
"Miscellaneous.busy" \ |
| 211 |
"Miscellaneous.busy.busy1" \ |
| 212 |
"Miscellaneous.busy.busy2" \ |
| 213 |
"Miscellaneous.bgexec" \ |
| 214 |
"Miscellaneous.bgexec.bgexec1" \ |
| 215 |
"Miscellaneous.bgexec.bgexec2" \ |
| 216 |
"Miscellaneous.bgexec.bgexec3" \ |
| 217 |
"Miscellaneous.bgexec.bgexec4" \ |
| 218 |
"Miscellaneous.bgexec.bgexec5" \ |
| 219 |
"Miscellaneous.container" \ |
| 220 |
"Miscellaneous.container.container" \ |
| 221 |
"Miscellaneous.container.container3" \ |
| 222 |
"Miscellaneous.dnd" \ |
| 223 |
"Miscellaneous.dnd.dnd1" \ |
| 224 |
"Miscellaneous.dnd.dnd2" \ |
| 225 |
"Miscellaneous.dnd.dragdrop1" \ |
| 226 |
"Miscellaneous.dnd.dragdrop2" \ |
| 227 |
"Miscellaneous.winop" \ |
| 228 |
"Miscellaneous.winop.winop1" \ |
| 229 |
"Miscellaneous.winop.winop2" \ |
| 230 |
"Miscellaneous.eps" |
| 231 |
.pw.swt.hier open -r root |
| 232 |
.pw.swt.hier entry configure root -labelfont *-helvetica*-bold-r-*-18-* \ |
| 233 |
-labelcolor red -labelshadow red3 |
| 234 |
.pw.swt.hier entry configure "Plotting" "Composition" "Miscellaneous" \ |
| 235 |
-labelfont *-helvetica*-bold-r-*-14-* \ |
| 236 |
-labelcolor blue4 -labelshadow blue2 |
| 237 |
|
| 238 |
.pw.swt.hier entry configure "Plotting.graph" \ |
| 239 |
-labelfont *-helvetica*-bold-r-*-14-* -label "X-Y Graph" |
| 240 |
.pw.swt.hier entry configure "Plotting.barchart" \ |
| 241 |
-labelfont *-helvetica*-bold-r-*-14-* -label "Bar Chart" |
| 242 |
|
| 243 |
.pw.swt.hier entry configure "Plotting.stripchart" \ |
| 244 |
-labelfont *-helvetica*-bold-r-*-14-* -label "X-Y Graph" |
| 245 |
.pw.swt.hier entry configure "Plotting.stripchart" \ |
| 246 |
-labelfont *-helvetica*-bold-r-*-14-* -label "Strip Chart" |
| 247 |
|
| 248 |
.pw.swt.hier entry configure "Plotting.graph" -icon graph.img |
| 249 |
.pw.swt.hier entry configure "Plotting.barchart" -icon graph.img |
| 250 |
|
| 251 |
.pw add .pw.swt -sticky news |
| 252 |
.pw add .pw.swd -sticky news |
| 253 |
#pack .pw.swd.title -fill x |
| 254 |
pack .pw.swd.tab -fill both -expand y |
| 255 |
grid .pw.swt.hier .pw.swt.yscroll -sticky news |
| 256 |
grid .pw.swt.xscroll -sticky news |
| 257 |
grid rowconfigure .pw.swt 0 -weight 1 |
| 258 |
grid columnconfigure .pw.swt 0 -weight 1 |
| 259 |
|
| 260 |
|
| 261 |
proc DoExit { code } { |
| 262 |
global progStatus |
| 263 |
set progStatus 1 |
| 264 |
exit $code |
| 265 |
} |
| 266 |
|
| 267 |
container .pw.swd.tab.f1 -relief raised -bd 2 -takefocus 0 |
| 268 |
.pw.swd.tab tab configure Example -window .pw.swd.tab.f1 |
| 269 |
foreach {sfx desc} {f2 "See Code" f3 "Manual"} { |
| 270 |
set ff .pw.swd.tab.$sfx |
| 271 |
.pw.swd.tab tab configure $desc -window [frame $ff] -fill both |
| 272 |
pack [scrollbar $ff.sh -command "$ff.t xview" -orient horizontal] -side bottom -fill x |
| 273 |
pack [scrollbar $ff.sv -command "$ff.t yview" ] -side right -fill y |
| 274 |
pack [text $ff.t -width 40 -height 15 -wrap none -xscrollcommand "$ff.sh set" -yscrollcommand "$ff.sv set"] -side right -fill both -expand y |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
if {$pc(-bgexec)} { |
| 279 |
set cmd "xterm -fn fixed -geom +4000+4000" |
| 280 |
eval bgexec programInfo(xterm) $cmd & |
| 281 |
set programInfo(lastProgram) xterm |
| 282 |
.pw.swd.tab.f1 configure -command $cmd |
| 283 |
} else { |
| 284 |
RunDemo BLT |
| 285 |
} |
| 286 |
wm protocol . WM_DELETE_WINDOW { destroy . } |
| 287 |
|