File: viewfile

package info (click to toggle)
itcl3.0 3.0.1-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 10,128 kB
  • ctags: 3,519
  • sloc: tcl: 32,416; ansic: 12,683; sh: 3,917; makefile: 692; awk: 273; perl: 265
file content (44 lines) | stat: -rw-r--r-- 1,467 bytes parent folder | download | duplicates (32)
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
#!/bin/sh
#\
exec itkwish $0
# ----------------------------------------------------------------------
#  EXAMPLE: show "TextInfo" and "MessageInfo" widgets in action
# ----------------------------------------------------------------------
#  COURSE:  Object-Oriented Programming with [incr Tcl]
#  AUTHOR:  Michael J. McLennan, Bell Labs Innovations
# ======================================================================
#               Copyright (c) 1996  Lucent Technologies
# ======================================================================
lappend auto_path .

if {[string match *color [winfo screenvisual .]]} {
    option add *textBackground ivory startupFile
    option add *MessageInfo.background DarkSeaGreen startupFile
    option add *TextInfo.background DarkSeaGreen startupFile
    option add *activeBackground ForestGreen startupFile
    option add *activeForeground white startupFile
    option add *selectForeground white startupFile
    option add *selectBackground ForestGreen startupFile
}

label .label -text "View File:"
pack .label -anchor w

entry .file
pack .file -fill x

bind .file <KeyPress-Return> {show_file [.file get]}

proc show_file {file} {
    set cmd {
        set fid [open $file r]
        set info [read $fid]
        close $fid
    }
    if {[catch $cmd] == 0} {
        set win [TextInfo .#auto -wrap none]
        $win display $info
    } else {
        MessageInfo .#auto -message "Cannot read file:\n$file"
    }
}