/usr/share/plplot5.10.0/tcl/FileSelector.tcl is in plplot-tcl 5.10.0+dfsg2-0.4+b2.
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 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | # $Id: FileSelector.tcl 2351 2001-01-02 03:04:28Z mlebrun $
#
#
# FileSelect
# ----------------------------------------------------------------------
# Implements a version of the OSF/Motif standard file selection dialog
# box using primitive widgets as the building blocks.
#
#
# PUBLIC ATTRIBUTES:
#
# -filterlabel ... label for filter entry, default "Filter"
# -dirlabel ...... label for directory list, default "Directories"
# -filelabel ..... label for file list, default "Files"
# -selectlabel ... label for selection entry, default "Selection"
# -dispfilter .... display filter, yes or no, default yes
# -dispdir ....... display directory list, yes or no, default yes
# -dispfile ...... display file list, yes or no, default yes
# -dispselect .... display selection, yes or no, default yes
# -filter ........ file list filter, defaults to "*"
# -dir ........... initial directory, default to [pwd]
# -title ......... window title text, default "Select File"
# -full .......... display full file names, yes or no, default no
#
# -width ......... width of filter/selection entry widgets in chars
# -height ........ height of displayed list in lines
#
# METHODS:
#
# config ......... used to change public attributes
# get ............ return the selection
# activate ....... perform a grab, upon selection of ok(1) or cancel(0),
# return result.
#
# USAGE:
#
# FileSelect .fs -title "Test File Select" -full 0
#
# if {[.fs activate]} {
# puts stdout "OK >>==> [.fs get]"
# } else {
# puts stdout "Cancel"
# }
#
# .fs destroy
#
# X11 OPTION DATABASE ATTRIBUTES
#
# ...and the rest of the usual widget attributes
#
# ----------------------------------------------------------------------
# AUTHOR: Mark L. Ulferts Phone: (214) 519-3947
# DSC Communications Corp E-mail: mulferts@spd.dsccc.com
# ----------------------------------------------------------------------
itcl_class FileSelect {
# ------------------------------------------------------------------
# CONSTRUCTOR - create new scrolled text
# ------------------------------------------------------------------
constructor {config} {
set class [$this info class]
::rename $this $this-tmp-
::toplevel $this -class $class
::rename $this $this-win-
::rename $this-tmp- $this
#
# Set the minimum size to 0,0 to allow both shrinkage and expansion.
# Also, set the title if one has been given.
#
wm minsize $this 250 250
wm title $this "$title"
wm transient $this .
wm withdraw $this
#
# Create an overall frame and separate frames for the filter,
# lists, selection, and buttons.
#
set f [frame $this.fs]
set fs(filterf) [frame $f.filterf]
set fs(listf) [frame $f.listf]
set fs(self) [frame $f.self]
set fs(btnf) [frame $f.btnf -height 30]
#
# Create the label and entry widgets for the filter. Turn off
# the selection capability, at least from the visual aspect.
#
label $fs(filterf).label -text "$filterlabel"
set fs(filter) [entry $fs(filterf).entry -relief sunken]
$fs(filter) config -selectbackground \
[lindex [$fs(filter) config -bg] 4] -selectborderwidth 0
pack $fs(filterf).label -side top -anchor w
pack $fs(filterf).entry -side bottom -fill x -expand yes
#
# Create directory list, scrollbar, and label for the directory
# frame. Make the list single select.
#
set fs(dirf) [frame $fs(listf).dirf]
label $fs(dirf).label -text "$dirlabel"
set fs(dirs) [listbox $fs(dirf).list -relief sunken \
-yscroll "$fs(dirf).vscroll set" \
-exportselection no]
tk_listboxSingleSelect $fs(dirs)
scrollbar $fs(dirf).vscroll -orient vertical -relief sunken \
-command "$fs(dirf).list yview"
pack $fs(dirf).label -side top -anchor w
pack $fs(dirf).vscroll -side right -fill y
pack $fs(dirf).list -side left -expand yes -fill both
#
# Create file list, scrollbar, and label for the file frame.
# Again, make the list single select.
#
set fs(filef) [frame $fs(listf).filef]
label $fs(filef).label -text "$filelabel"
set fs(files) [listbox $fs(filef).list -relief sunken \
-yscroll "$fs(filef).vscroll set" \
-exportselection no]
tk_listboxSingleSelect $fs(files)
scrollbar $fs(filef).vscroll -orient vertical -relief sunken \
-command "$fs(filef).list yview"
pack $fs(filef).label -side top -anchor w
pack $fs(filef).vscroll -side right -fill y
pack $fs(filef).list -side left -expand yes -fill both
#
# Pack the directory and file lists based on the attributes
# for displaying each list. Add a filler frame between the
# lists if both list are displayed.
#
frame $fs(listf).buf -width $_margin -borderwidth 0
if {$dispdir} {pack $fs(dirf) -side left -fill both -expand yes}
if {$dispdir && $dispfile} {pack $fs(listf).buf -side left}
if {$dispfile} {pack $fs(filef) -side right -fill both -expand yes}
#
# Create the label and entry widgets for the selection frame. Turn
# off the selection capability, at least from the visual aspect
#
label $fs(self).label -text "$selectlabel"
set fs(select) [entry $fs(self).entry -relief sunken]
$fs(select) config -selectbackground \
[lindex [$fs(select) config -bg] 4] -selectborderwidth 0
config -_selection "$dir/"
pack $fs(self).label -side top -anchor w
pack $fs(self).entry -side bottom -fill x -expand yes
#
# Add the separator and create the buttons in the button frame.
# Each button is within a frame used to display as default.
# The placer is used to locate the three buttons at relative
# locations.
#
frame $f.line -height 2 -width 2 -borderwidth 1 -relief sunken
frame $fs(btnf).okf -borderwidth 1
set fs(okbtn) [button $fs(btnf).okf.ok -text OK -width 8]
pack $fs(btnf).okf.ok -padx 2 -pady 2
raise $fs(btnf).okf.ok
frame $fs(btnf).ff -borderwidth 1
set fs(filterbtn) [button $fs(btnf).ff.f -text Filter -width 8 \
-command "$this _filtercmd"]
pack $fs(btnf).ff.f -padx 2 -pady 2
raise $fs(btnf).ff.f
frame $fs(btnf).cf -borderwidth 1
set fs(cancelbtn) [button $fs(btnf).cf.c -text Cancel -width 8]
pack $fs(btnf).cf.c -padx 2 -pady 2
raise $fs(btnf).cf.c
place $fs(btnf).okf -relx 0 -rely 0.5 -anchor w
place $fs(btnf).ff -relx 0.5 -rely 0.5 -anchor center
place $fs(btnf).cf -relx 1 -rely 0.5 -anchor e
#
# Pack all the components of the file selection box. The filter
# and selection frames are packed based on the display attributes.
#
if {$dispfilter} {pack $fs(filterf) -fill x -padx $_margin -pady 5}
pack $fs(listf) -fill both -padx $_margin -pady 5 -expand yes
if {$dispselect} {pack $fs(self) -fill x -padx $_margin -pady 5}
pack $f.line -fill x -pady 5
pack $fs(btnf) -fill x -padx $_margin -pady 5
pack $f -fill both -expand yes
#
# Set up the bindings for the list widgets. Single click in either
# list executes a select method. Double click for the both lists
# selects the entry and then invokes the button callback. Focus
# events for the filter and select entry widgets control the default
# button display, and return is mapped to the default button as well.
#
bind $fs(dirs) <1> "$this _selectdir %y"
bind $fs(files) <1> "$this _selectfile %y"
bind $fs(dirs) <Double-1> "$this _selectdir %y; $fs(filterbtn) invoke"
bind $fs(files) <Double-1> "$this _selectfile %y; $fs(okbtn) invoke"
bind $fs(filter) <FocusIn> "$this _defaultbtn filter"
bind $fs(select) <FocusIn> "$this _defaultbtn ok"
bind $fs(filter) <Return> "$fs(filterbtn) invoke"
bind $fs(select) <Return> "$fs(okbtn) invoke"
#
# Explicitly handle configs that may have been ignored earlier.
# Also, check to see if the user has specified, width, or height.
# If not, use the default and config.
#
if {! [regexp {FileSelect::width} $config]} {
config -width $width
}
if {! [regexp {FileSelect::height} $config]} {
config -height $height
}
foreach attr $config {
config -$attr [set $attr]
}
#
# Construction is complete. Now set up the initial text for the
# filter, selection, and both lists. Finally, set the focus for
# either the filter or select widget based on the display attribute.
#
_setfilter $dir $filter
_setselection
_filldirlist
_fillfilelist
if {$dispfilter} {
focus $fs(filter)
} elseif {$dispselect} {
focus $fs(select)
}
}
# ------------------------------------------------------------------
# METHOD: config - used to change public attributes
# ------------------------------------------------------------------
method config {config} {}
# ------------------------------------------------------------------
# DESTRUCTOR - destroy window containing widget
# ------------------------------------------------------------------
destructor {
::rename $this-win- {}
tk_destroy $this
}
# ------------------------------------------------------------------
# METHOD: activate - Perform a grab operation, install the button
# callbacks, and wait for the result. Make sure
# to reset the working directory back to the
# original before returning the result.
# ------------------------------------------------------------------
method activate {} {
global result
set curwd "[pwd]"
wm deiconify $this
grab $this
$fs(okbtn) config -command "$this _okcmd"
$fs(cancelbtn) config -command "$this _cancelcmd"
tkwait variable result($this)
wm withdraw $this
cd $curwd
return $result($this)
}
# ------------------------------------------------------------------
# METHOD: get - Return the selection.
# ------------------------------------------------------------------
method get {} {
return $_selection
}
# ------------------------------------------------------------------
# METHOD: _selectdir - Select the directory, set the filter to
# the new directory. Set the selection to the
# new directory if the file list is not
# displayed. Mark the filter button as the
# default.
# ------------------------------------------------------------------
method _selectdir {y} {
$fs(dirs) select clear
$fs(dirs) select to [$fs(dirs) nearest $y]
set curwd "[pwd]"
set seldir [$fs(dirs) get [$fs(dirs) curselection]]
if {$seldir == "."} {
cd .
} elseif {$seldir == ".."} {
cd ..
} else {
cd $seldir
}
_setfilter "[pwd]"
if {! $dispfile} {
_setselection "[pwd]"
}
cd $curwd
_defaultbtn filter
}
# ------------------------------------------------------------------
# METHOD: _selectfile - Select the file, set the selection to
# the new file. Mark the ok button as the
# default.
# ------------------------------------------------------------------
method _selectfile {y} {
$fs(files) select clear
$fs(files) select to [$fs(files) nearest $y]
config -_selection $dir/[$fs(files) get [$fs(files) curselection]]
_setselection
_defaultbtn ok
}
# ------------------------------------------------------------------
# METHOD: _setfilter - Update the filter based on the parameters.
# If the directory 'd' parameter is null, use
# the 'dir' attribute. If the file 'f'
# parameter is null use the tail of the filter
# entry text.
# ------------------------------------------------------------------
method _setfilter {{d ""} {f ""}} {
if {$d == ""} {set d [file dirname [$fs(filter) get]]}
if {$f == ""} {set f [file tail [$fs(filter) get]]}
$fs(filter) delete 0 end
$fs(filter) insert 0 "$d/$f"
}
# ------------------------------------------------------------------
# METHOD: _setselection - Update the selection based on the
# parameter. If the file 'f' parameter is
# null, use the 'selection' attribute.
# ------------------------------------------------------------------
method _setselection {{f ""}} {
if {$f == ""} {set f $_selection}
$fs(select) delete 0 end
$fs(select) insert end "$f"
}
# ------------------------------------------------------------------
# METHOD: _okcmd - Ok button callback. Set the default button to
# OK, and set the selection attribute to the
# current entry widget text. Undo the callbacks
# for both the ok and cancel buttons. Release
# the grab and set the global result, which frees
# the wait.
# ------------------------------------------------------------------
method _okcmd {} {
global result
_defaultbtn ok
config -_selection [$fs(select) get]
$fs(okbtn) config -command {}
$fs(cancelbtn) config -command {}
grab release $this
set result($this) 1
}
# ------------------------------------------------------------------
# METHOD: _filtercmd - Filter button callback. Change directories
# as needed, and set the dir, filter, and
# selection attributes. Change the filter and
# selection text along with the list contents.
# Mark the default button as filter.
# ------------------------------------------------------------------
method _filtercmd {} {
set seldir [file dirname [$fs(filter) get]]
cd $seldir
config -dir "[pwd]"
config -filter "[file tail [$fs(filter) get]]"
config -_selection "$dir/"
_setfilter
_setselection
_filldirlist
_fillfilelist
_defaultbtn filter
}
# ------------------------------------------------------------------
# METHOD: _cancelcmd - Cancel button callback. Set the default
# button to cancel, undo the callbacks, and
# release the grab and wait via the global
# result variable.
# ------------------------------------------------------------------
method _cancelcmd {} {
global result
_defaultbtn cancel
$fs(okbtn) config -command {}
$fs(cancelbtn) config -command {}
grab release $this
set result($this) 0
}
# ------------------------------------------------------------------
# METHOD: _filldirlist - Clear the directory list filling with the
# results of an 'ls'. Use the full attribute
# to determine full file name insertion.
# Select the first element if it exists.
# ------------------------------------------------------------------
method _filldirlist {} {
$fs(dirs) delete 0 end
foreach i [exec /bin/ls -a $dir] {
if {[file isdirectory $i]} {
if {$full} {
$fs(dirs) insert end "$dir/$i"
} else {
$fs(dirs) insert end [file tail $i]
}
}
}
if {[$fs(dirs) size]} {
$fs(dirs) select clear
$fs(dirs) select to 0
}
}
# ------------------------------------------------------------------
# METHOD: _fillfilelist - Clear the file list filling with the
# results of an 'glob'. Use the full
# attribute to determine full file name
# insertion. Select the first element if
# it exists.
# ------------------------------------------------------------------
method _fillfilelist {} {
$fs(files) delete 0 end
foreach i [glob -nocomplain $dir/$filter] {
if {! [file isdirectory $i]} {
if {$full} {
$fs(files) insert end $i
} else {
$fs(files) insert end [file tail $i]
}
}
}
if {[$fs(files) size]} {
$fs(files) select clear
$fs(files) select to 0
}
}
# ------------------------------------------------------------------
# METHOD: _defaultbtn - Sets the default button, either ok, filter
# or cancel. The focus is also adjusted.
# ------------------------------------------------------------------
method _defaultbtn {btn} {
if {$btn == "ok"} {
$fs(btnf).okf config -relief sunken
$fs(btnf).ff config -relief flat
$fs(btnf).cf config -relief flat
focus $fs(select)
} elseif {$btn == "filter"} {
$fs(btnf).okf config -relief flat
$fs(btnf).ff config -relief sunken
$fs(btnf).cf config -relief flat
focus $fs(filter)
} elseif {$btn == "cancel"} {
$fs(btnf).okf config -relief flat
$fs(btnf).ff config -relief flat
$fs(btnf).cf config -relief sunken
focus none
}
}
# ------------------------------------------------------------------
# ATTRIBUTE title - Set the window title.
# ------------------------------------------------------------------
public title "Select File" {
if {[winfo exists $this]} {
wm title $this $title
}
}
# ------------------------------------------------------------------
# ATTRIBUTE filterlabel - The label string above the filter widget.
# ------------------------------------------------------------------
public filterlabel "Filter" {
if {[winfo exists $this]} {
$fs(filterf).label config -text $filterlabel
}
}
# ------------------------------------------------------------------
# ATTRIBUTE filter - File list filter, defaults to "*".
# ------------------------------------------------------------------
public filter "*" {}
# ------------------------------------------------------------------
# ATTRIBUTE dir - Initial directory, default to [pwd].
# ------------------------------------------------------------------
public dir "[pwd]" {
cd $dir
}
# ------------------------------------------------------------------
# ATTRIBUTE dirlabel - Label for directory list, default "Directories"
# ------------------------------------------------------------------
public dirlabel "Directories" {
if {[winfo exists $this]} {
$fs(dirf).label config -text $dirlabel
}
}
# ------------------------------------------------------------------
# ATTRIBUTE filelabel - Label for file list, default "Files".
# ------------------------------------------------------------------
public filelabel "Files" {
if {[winfo exists $this]} {
$fs(filef).label config -text $filelabel
}
}
# ------------------------------------------------------------------
# ATTRIBUTE selectlabel - Label for selection entry, default
# "Selection".
# ------------------------------------------------------------------
public selectlabel "Selection" {
if {[winfo exists $this]} {
$fs(self).label config -text $selectlabel
}
}
# ------------------------------------------------------------------
# ATTRIBUTE full - Display full file names, yes/no, default no.
# ------------------------------------------------------------------
public full 0 {}
# ------------------------------------------------------------------
# ATTRIBUTE dispfilter - Display filter, yes or no, default yes
# ------------------------------------------------------------------
public dispfilter 1 {}
# ------------------------------------------------------------------
# ATTRIBUTE dispdir - Display directory list, yes or no, default yes
# ------------------------------------------------------------------
public dispdir 1 {}
# ------------------------------------------------------------------
# ATTRIBUTE dispfile - Display file list, yes or no, default yes
# ------------------------------------------------------------------
public dispfile 1 {}
# ------------------------------------------------------------------
# ATTRIBUTE dispselect - Display selection, yes or no, default yes
# ------------------------------------------------------------------
public dispselect 1 {}
# ------------------------------------------------------------------
# ATTRIBUTE width - Set the width of the selection and filter entry
# widgets.
# ------------------------------------------------------------------
public width 50 {
if {[winfo exists $this]} {
$fs(filter) config -width $width
$fs(select) config -width $width
}
}
# ------------------------------------------------------------------
# ATTRIBUTE height - Set the height of the directory and file lists.
# ------------------------------------------------------------------
public height 10 {
if {[winfo exists $this]} {
$fs(dirs) config -geometry [expr $width / 2]x$height
$fs(files) config -geometry [expr $width / 2]x$height
}
}
# ------------------------------------------------------------------
# PRIVATE ATTRIBUTE _margin - Margin distance used in construction
# ------------------------------------------------------------------
public _margin 10 {}
# ------------------------------------------------------------------
# PRIVATE ATTRIBUTE _selection - Current selection.
# ------------------------------------------------------------------
public _selection "[pwd]/" {}
protected fs
}
|