/usr/share/tcltk/tklib0.5/plotchart/plotpack.tcl is in tklib 0.5-3.
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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | # plotpack.tcl --
# Implement a pack-like geometry manager for Plotchart
#
# Note:
# The canvas:* procedures are taken directly from the Wiki,
# these procedures were written by Maurice (ulis) Bredelet
# I have not changed the formatting or the naming convention,
# as a small token of my appreciation for his Tcl work
# - he died in February 2008.
#
namespace eval ::Plotchart {
variable packing
}
# GetCanvas --
# Destill the name of the canvas from the plot command
#
# Arguments:
# cmd Plot command
#
# Result:
# Name of the widget
#
proc ::Plotchart::GetCanvas {cmd} {
regsub {^[^_]+_} $cmd "" w
return $w
}
# plotpack --
# Copy an existing plot/chart into another canvas widget
#
# Arguments:
# w Canvas widget to copy to
# dir Direction to attach the new plot to the existing contents
# args List of plots/charts to be copied
#
# Result:
# None
#
proc ::Plotchart::plotpack {w dir args} {
variable packing
if { ![info exists packing($w,top)] } {
set packing($w,top) 0
set packing($w,left) 0
set packing($w,right) [WidthCanvas $w]
set packing($w,bottom) [HeightCanvas $w]
}
set top $packing($w,top)
set left $packing($w,left)
set right $packing($w,right)
set bottom $packing($w,bottom)
foreach p $args {
set save [canvas:save [GetCanvas $p]]
switch -- $dir {
"top" {
set xmove 0
set ymove $top
canvas:restore $w $save
$w move __NEW__ $xmove $ymove
$w dtag all __NEW__
set cwidth [WidthCanvas [GetCanvas $p]]
if { $left < $cwidth } {
set left $cwidth
}
set top [expr {$top+[HeightCanvas [GetCanvas $p]]}]
}
"bottom" {
set xmove 0
set ymove [expr {$bottom-[HeightCanvas [GetCanvas $p]]}]
canvas:restore $w $save
$w move __NEW__ $xmove $ymove
$w dtag all __NEW__
set cwidth [WidthCanvas [GetCanvas $p]]
if { $left < $cwidth } {
set left $cwidth
}
set bottom $ymove
}
"left" {
set xmove $left
set ymove 0
canvas:restore $w $save
$w move __NEW__ $xmove $ymove
$w dtag all __NEW__
set left [expr {$left+[WidthCanvas [GetCanvas $p]]}]
set cheight [HeightCanvas [GetCanvas $p]]
if { $top < $cheight } {
set top $cheight
}
}
"right" {
set xmove [expr {$right-[WidthCanvas [GetCanvas $p]]}]
set ymove 0
canvas:restore $w $save
$w move __NEW__ $xmove $ymove
$w dtag all __NEW__
set right $xmove
if { $top < $cheight } {
set top $cheight
}
}
}
}
set packing($w,top) $top
set packing($w,left) $left
set packing($w,right) $right
set packing($w,bottom) $bottom
}
# canvas:* --
# Procedures for copying the contents of a canvas widget - by "ulis"
#
namespace eval ::Plotchart {
# ==============================
#
# clone a canvas widget
#
# ==============================
# ----------
# canvas:clone proc
# ----------
# parm1: canvas widget
# parm2: clone canvas widget
# ----------
proc canvas:clone {canvas clone} { canvas:restore $clone [canvas:save $canvas] }
# ----------
# options proc
#
# return non empty options
# ----------
# parm: options list
# ----------
# return: non empty options list
# ----------
proc options {options} \
{
set res {}
foreach option $options \
{
set key [lindex $option 0]
set value [lindex $option 4]
if {$value != ""} { lappend res [list $key $value] }
}
return $res
}
# ----------
# canvas:save proc
#
# serialize a canvas widget
# ----------
# parm1: canvas widget path
# ----------
# return: serialized widget
# ----------
proc canvas:save {w} \
{
# canvas name
lappend save $w
# canvas option
lappend save [options [$w configure]]
# canvas focus
lappend save [$w focus]
# canvas items
foreach id [$w find all] \
{
set item {}
# type & id
set type [$w type $id]
lappend item [list $type $id]
# coords
lappend item [$w coords $id]
# tags
set tags [concat __NEW__ [$w gettags $id]] ;# AM: My change
lappend item $tags
# binds
set binds {}
# id binds
set events [$w bind $id]
foreach event $events \
{ lappend binds [list $id $event [$w bind $id $event]] }
# tags binds
foreach tag $tags \
{
set events [$w bind $tag]
foreach event $events \
{ lappend binds [list $tag $event [$w bind $tag $event]] }
}
lappend item $binds
# options
lappend item [options [$w itemconfigure $id]]
# type specifics
set specifics {}
switch $type \
{
arc {}
bitmap {}
image \
{
# image name
set iname [$w itemcget $id -image]
lappend specifics $iname
# image type
lappend specifics [image type $iname]
# image options
lappend specifics [options [$iname configure]]
}
line {}
oval {}
polygon {}
rectangle {}
text \
{
foreach index {insert sel.first sel.last} \
{
# text indexes
catch \
{ lappend specifics [$w index $id $index] }
}
}
window \
{
# window name
set wname [$w itemcget $id -window]
lappend specifics $wname
# window type
lappend specifics [string tolower [winfo class $wname]]
# window options
lappend specifics [options [$wname configure]]
}
}
lappend item $specifics
lappend save $item
}
# return serialized canvas
return $save
}
# ----------
# canvas:restore proc
#
# restore a serialized canvas widget
# ----------
# parm1: canvas widget path
# parm2: serialized widget to restore
# ----------
proc canvas:restore {w save} \
{
# create canvas options
# eval canvas $w [join [lindex $save 1]] ;# AM: My change
# items
foreach item [lrange $save 3 end] \
{
foreach {typeid coords tags binds options specifics} $item \
{
# get type
set type [lindex $typeid 0]
# create bitmap or window
switch $type \
{
image \
{
foreach {iname itype ioptions} $specifics break
if {![image inuse $iname]} \
{ eval image create $itype $iname [join $ioptions] }
}
window \
{
foreach {wname wtype woptions} $specifics break
if {![winfo exists $wname]} \
{ eval $wtype $wname [join $woptions] }
raise $wname
}
}
# create item
set id [eval $w create $type $coords [join $options]]
$w itemconfigure $id -tags $tags ;# AM: "options" may contain the old list of tags
# item bindings
foreach bind $binds \
{
foreach {id event script} $bind { $w bind $id $event $script }
}
# item specifics
if {$specifics != ""} \
{
switch $type \
{
text \
{
foreach {insert sel.first sel.last} $specifics break
$w icursor $id $insert
if {${sel.first} != ""} \
{
$w select from $id ${sel.first}
$w select to $id ${sel.last}
}
}
}
}
}
}
# focused item
set focus [lindex $save 2]
if {$focus != ""} \
{
$w focus [lindex $save 2]
focus -force $w
}
# return path
return $w
}
# ----------
# canvas:dump proc
#
# dump a canvas widget
# ----------
# parm: canvas widget path
# ----------
# return: widget dump
# ----------
proc canvas:dump {w} \
{
# canvas name
lappend res [lindex $w 0]
# canvas options
foreach option [lindex $w 1] { lappend res [join $option \t] }
# focused item
lappend res [join [lindex $w 2] \t]
# items
foreach item [lrange $w 3 end] \
{
foreach {type coords tags binds options specifics} $item \
{
# item type
lappend res [join $type \t]
# item coords
lappend res \tcoords\t$coords
# item tags
lappend res \ttags\t$tags
# item bindings
lappend res \tbinds
foreach bind $binds { lappend res \t\t$bind }
# item options
lappend res \toptions
foreach option $options \
{
set key [lindex $option 0]
set value [lindex $option 1]
lappend res \t\t$key\t$value
}
# item specifics
if {$specifics != ""} \
{
lappend res \tspecifics
foreach specific $specifics \
{
if {[llength $specific] == 1} { lappend res \t\t$specific } \
else { foreach token $specific { lappend res \t\t$token } }
}
}
}
}
# return dump
return [join $res \n]
}
}
|