source: trunk/lstview @ 658

Last change on this file since 658 was 658, checked in by toby, 11 years ago

# on 2002/10/31 17:26:56, toby did:
trap gsas_config errors
prevent infinite loop in readsum

  • Property rcs:author set to toby
  • Property rcs:date set to 2002/10/31 17:26:56
  • Property rcs:lines set to +28 -17
  • Property rcs:rev set to 1.11
  • Property rcs:state set to Exp
  • Property svn:keywords set to Author Date Revision Id
File size: 21.2 KB
RevLine 
[5]1#!/usr/local/bin/wish
[77]2# $Id: lstview 658 2009-12-04 23:09:51Z toby $
[6]3set Revision {$Revision: 658 $ $Date: 2009-12-04 23:09:51 +0000 (Fri, 04 Dec 2009) $}
[5]4# display a .LST file in a text box
5# updates 8/26 add bindings for page-up, -down, uparrow, downarrow
6# read from gzip .LST.gz files using gunzip and then append the .LST file
7# start work on plotting variables change next line to use
[535]8set txtvw(plotvars) 1
[77]9set txtvw(font) "Courier"
[5]10set txtvw(menulength) 25
11set txtvw(stringcount) 0
12set txtvw(string) {}
13set txtvw(sum) 0
[535]14set txtvw(hideplot) 0
[5]15# maximum characters to read initially from a .LST file
16set txtvw(maxchars) 1000000
17if {$tcl_platform(platform) == "windows"} {
18   # windows is slow!
19   set txtvw(maxchars) 200000
20}
21if {[set expnam [lindex $argv 0]] == ""} {
22    tk_dialog .warn Notify "No filename specified" error 0 OK
23    destroy .
24}
25set filename $expnam.LST
26set zfil {}
[535]27set lstfp {}
[5]28# is there a compressed version of the file?
29if {[file exists $filename.gz] && $tcl_platform(platform) != "windows"} {
30    set zfil [open "|gunzip < $filename.gz" r]
31}
32set box {}
[6]33set txtvw(followcycle) 1
[5]34
35proc waitmsg {message} {
36    set w .wait
37    # kill any window/frame with this name
38    catch {destroy $w}
39    pack [frame $w]
40    frame $w.bot -relief raised -bd 1
41    pack $w.bot -side bottom -fill both
42    frame $w.top -relief raised -bd 1
43    pack $w.top -side top -fill both -expand 1
44    label $w.msg -justify left -text $message -wrap 3i
45    catch {$w.msg configure -font \
46                -Adobe-Times-Medium-R-Normal--*-180-*-*-*-*-*-*
47    }
48    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
49    label $w.bitmap -bitmap info
50    pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
51    update
52}
53
[135]54proc donewaitmsg {} {
[5]55    catch {destroy .wait}
56}
57waitmsg "Reading $expnam.LST, Please wait"
58
59set txtvw(runnumber) 0
60
61proc findcyc {win menu {pos 0.0}} {
[535]62    global txtvw
63    global trackinglist
[5]64    set i 0
[6]65    set lastpos {}
[5]66    # loop over cycles
67    set startpos $pos
68    # get current cycle number
69    set pos [$win search -regexp -count chars \
70            {Cycle *[0-9]+ +There} $pos+1line end]
71    while {$pos != ""} {
72        # add the current cycle number to the menu
73        set line [lindex [split $pos .] 0]
74        $win tag add cycle $line.1 $line.10
75        incr i
[6]76        set cycle {}
77        regexp {Cycle *([0-9]+) +There} [$win get $pos $line.end] x cycle
78        if {$cycle != ""} {
79            set lastpos $pos
80            set txtvw(lastcycle) "Cycle $cycle"
81            .a.goto.menu entryconfigure 1 -state normal
82            $menu insert 1 command \
83                    -font 6x12 \
84                    -label "Cycle $cycle" \
85                    -command "$win see $pos"
86            if {[$menu index end] > $txtvw(menulength)} {$menu delete end}
87        }
[5]88        # get next cycle number
89        set nextpos [$win search -regexp -count chars \
90                {Cycle *[0-9]+ +There} $pos+1line end]
91        if {$nextpos == ""} {
92            set epos end
93        } else {
94            set epos $nextpos
95        }
96
97        # loop to highlight all Rwp & Rp values
98        set npos $startpos
99        set npos [$win search -regexp -count chars \
100                {Hstgm *[0-9]+} $npos+1line $pos]
101        while {$npos != ""} {
102            set line [lindex [split $npos .] 0]
103            set x [$win get $line.0 $line.end]
104            scan $x %s%d%s%d%d%f%f%f a hst c d e f rwp rp
[535]105            foreach d {Rwp Rp} value "$rwp $rp" {
106                set v ${d}_$hst
107                set var tracklist_$v
108                set trackinglist($v) "$d hist $hst"
109                global $var
110                set ${var}($cycle) $value
111            }
[5]112            $win tag add rval $npos $line.end
113            set npos [$win search -regexp -count chars \
114                {Hstgm *[0-9]+} $npos+1line $pos]
115        }
116        # get the CHI**2 value
117        set chipos [$win search {Reduced CHI**2 =} $pos $epos]
118        if {$chipos != ""} {
119            $win tag add chi $chipos+8chars $chipos+23chars
120            set chi [string trim [$win get $chipos+16chars $chipos+23chars]]
121            set txtvw(lastchi) "Chi**2 $chi"
[535]122            set var tracklist_chi2
123            set trackinglist(chi2) "red. Chi squared"
124            global $var
125            set ${var}($cycle) $chi
[5]126        }
[535]127        set sumpos [$win search {Final variable sum} $pos $epos]
[5]128        if {$sumpos != ""} {
[535]129            set line [$win get $sumpos "$sumpos lineend"]
130            regexp {: *([0-9\.]+) } $line a finalshift
131            set txtvw(finalshift) "Shift/SU $finalshift"
132            set var tracklist_fshft2
133            set trackinglist(fshft2) "Sum((shft/su)**2)"
134            global $var
135            set ${var}($cycle) $finalshift
[5]136        }
137        # loop to highlight all R(F**2) values
138        set npos $pos
139        set npos [$win search -regexp -count chars \
140                {Histogram *[0-9]+} $npos+1line $epos]
141        while {$npos != ""} {
142            set line [lindex [split $npos .] 0]
143            set x [$win get $line.0 $line.end]
[88]144            catch {
145                regexp {gram *([0-9]+).*\) =(.*)} $x a hst rf2
[535]146                set var tracklist_Rbragg_$hst
147                set trackinglist(Rbragg_$hst) "R(Bragg) hist $hst"
148                global $var
149                set ${var}($cycle) $rf2
[88]150            }
[5]151            $win tag add rval $npos $line.end
152            set npos [$win search -regexp -count chars \
153                    {Histogram *[0-9]+} $npos+1line $epos]
154        }
155        # get ready to loop again
156        set startpos $pos
157        set pos $nextpos
158    }
[6]159    if {$txtvw(followcycle) && $lastpos != ""} {$win see $lastpos}
[5]160}
161
162proc findrun {win {menu ""} {pos 0.0}} {
163    global txtvw
164    while {$pos != ""} {
165        set pos [$win search "Program GENLES" $pos+1line end]
166        if {$menu != "" && $pos != ""} {
167            incr txtvw(runnumber)
168            .a.goto.menu entryconfigure 2 -state normal
169            $menu insert 1 command \
170                    -font 6x12 \
171                    -label "Run $txtvw(runnumber)" \
172                    -command "$win see $pos"
173            if {[$menu index end] > $txtvw(menulength)} {$menu delete end}
174        }
175    }
176}
177
178
179proc findsum {win menu {pos 0.0}} {
180    global txtvw
[535]181    global trackinglist
182    set pos [$win search {Summary table} $pos+1line end]
183    # found a summary, now search back for the cycle number
[5]184    while {$pos != ""} {
[535]185        # add it to the menu
[5]186        incr txtvw(sum)
187        .a.goto.menu entryconfigure 3 -state normal
188        $menu insert 1 command \
189                -font 6x12 \
190                -label "Summary $txtvw(sum)" \
191                -command "$win see $pos"
192        if {[$menu index end] > $txtvw(menulength)} {$menu delete end}
[535]193       
194        set npos [$win index "$pos+1line linestart"]
195        set fpos [$win index $pos-1line]
196       
197        if {!$txtvw(plotvars)} continue
198
199        # parse outs the last listed cycle number
200        set lstcyc {}
[658]201        set fpos [$win search -backwards -nocase -regexp {cycle *[0-9]+ } $pos]
202        if {$fpos != ""} {
203            set end [$win index "$fpos lineend"]
204            set lstcyc [lindex [$win get $fpos $end] 1]
205        }
[535]206        # get the cycle offset
207        set ncyc [lindex [$win get $npos "$npos lineend"] end]
208        set npos [$win index "$npos+1line linestart"]
209       
210        set end [$win index end]
211        # now read through the summary table
212        while {![string match *Fraction* \
213                [set line [$win get $npos "$npos lineend"]] \
214                ]} {
215            set v1 [string range $line 1 9]
216            # make a name without spaces
217            set v "zz$v1"
218            regsub -all " " $v "_" v
219            set var tracklist_$v
220            catch {
221                # are there any invalid numbers in the list?
222                foreach value [string range $line 10 end] {
223                    expr [string trim $value]
[5]224                }
[535]225
226                # passed syntax check, add to list
227                set trackinglist($v) "shift/SU $v1"
228                global $var
229               
230                set i 0
231                foreach value [string range $line 10 end] {
232                    incr i
233                    set cycle [expr {$lstcyc - $ncyc + $i}]
234                    set ${var}($cycle) $value
235                }
[5]236            }
[535]237            set npos [$win index "$npos+1line linestart"]
238            if {$npos == $end} break
[5]239        }
[658]240        set pos [$win search {Summary table} $npos+1line end]
[5]241    }
242}
243
244proc findsetstring {win string {menu ""} {pos 0.0}} {
245    global txtvw
246    while {$pos != ""} {
247        set pos [$win search -regexp -count chars \
248                $string $pos+1line end]
249        if {$menu != "" && $pos != ""} {
250            $win tag add found $pos "$pos + $chars chars"
251            incr txtvw(stringcount)
252            $menu insert 1 command \
253                    -font 6x12 \
254                    -label "loc #$txtvw(stringcount)" \
255                    -command "$win see $pos"
256            if {[$menu index end] > $txtvw(menulength)} {$menu delete end}
257        }
258    }
259}
260
261proc setsearchstring { } {
262    global txtvw
263    set txtvw(stringcount) 0
264    .a.goto.menu entryconfigure 5 -state disabled -label ""
265    .a.goto.menu.str delete 1 end
266    catch {.txt tag delete found}
267    .txt tag config found -foreground red
268    if {[string trim $txtvw(entry)] == ""} {
269        set txtvw(string) {}
270        return
271    } else {
272        set txtvw(string) [string trim $txtvw(entry)]
273    }
274    findsetstring .txt $txtvw(string) .a.goto.menu.str
275    if {$txtvw(stringcount) > 0} {
276        .a.goto.menu entryconfigure 5 -state normal -label "$txtvw(string)..."
277    }
278}
279
[535]280proc updatetext {"fil {}"} {
281    global txtvw filename tcl_platform lstfp
[560]282    set repeat 0
[535]283    if {$fil == ""} {
[560]284        set repeat 1
[535]285        after 5000 updatetext
286        set fil $lstfp
287    }
288    set txt {}
289    catch {set txt [read $fil]}
[5]290    if {$txt == ""} return
291    .txt config -state normal
292    set oldend [.txt index end]
293    # truncate the text if too long
294    if {[string length $txt] > $txtvw(maxchars) && $repeat == 0} {
295        set beg [expr [string length $txt] - $txtvw(maxchars)]
296        .txt insert end "(first $beg characters in file skipped)\n"
297        .txt insert end [string range $txt $beg end]
298    } else {
299        .txt insert end $txt
300    }
[77]301    # don't disable in Win as this prevents the highlighting of selected text
302    if {$tcl_platform(platform) != "windows"} {
303        .txt config -state disabled
304    }
[5]305    update idletasks
306    findrun .txt .a.goto.menu.run $oldend
307    update
308    findcyc .txt .a.goto.menu.cyc $oldend
309    update
310    findsum .txt .a.goto.menu.sum $oldend
311    update
312   
313    if {$txtvw(string) != ""} {
314        findsetstring .txt $txtvw(string) .a.goto.menu.str $oldend
315        if {$txtvw(stringcount) > 0} {
316            .a.goto.menu entryconfigure 5 -state normal -label "$txtvw(string)..."
317        }
318    }
319}
[535]320
321proc GetSearchString {} {
[5]322    catch {destroy .str}
323    toplevel .str
324    grab .str
325    pack [frame .str.1] -side top
326    pack [frame .str.2] -side top
327    pack [label .str.1.l -text "Search String"] -side left
328    pack [entry .str.1.e -textvariable txtvw(entry) -width 12] -side left
329    pack [label .str.1.2 -text "(regexp)"] -side left
330    pack [button .str.2.ok -text "Search" -command \
331            "setsearchstring; destroy .str" ] -side left
332    pack [button .str.2.q -text "Quit" -command \
333            "destroy .str" ] -side left
334# bind to RETURN here   
335#    bind .str
336}
337
338proc findstring {win str1 {str2 ""}} {
339    set pos [$win search -backwards $str1 end]
340    if {$pos == "" && $str2 != ""} {
341        set pos [$win search -backwards $str2 end]
342    }
343    if {$pos == ""} return
344    $win see $pos
345}
346
[44]347proc SaveOptions {} {
348    global txtvw
349    set fp [open [file join ~ .gsas_config] a]
[658]350    puts $fp "set txtvw(followcycle) [list $txtvw(followcycle)]"
[77]351    puts $fp "set txtvw(font) [list $txtvw(font)]"
[44]352    close $fp
353}
354
[5]355proc aboutgsas {} {
[7]356    global Revision
[6]357    tk_dialog .warn About "
358GSAS\n\
359A. C. Larson and\n R. B. Von Dreele,\n LANSCE, Los Alamos\n\n\
[7]360LSTVIEW\nB. Toby, NIST\nNot subject to copyright\n\n\
[6]361$Revision\n\
362" {} 0 OK
[5]363}
364
[44]365#----------------------------------------------------------------
366# where are we?
367set expgui(script) [info script]
368# translate links -- go six levels deep
369foreach i {1 2 3 4 5 6} {
370    if {[file type $expgui(script)] == "link"} {
371        set link [file readlink $expgui(script)]
372        if { [file  pathtype  $link] == "absolute" } {
373h           set expgui(script) $link
374        } {
375            set expgui(script) [file dirname $expgui(script)]/$link
376        }
377    } else {
378        break
379    }
380}
[5]381
[44]382# fixup relative paths
383if {[file pathtype $expgui(script)] == "relative"} {
384    set expgui(script) [file join [pwd] $expgui(script)]
385}
386set expgui(scriptdir) [file dirname $expgui(script) ]
[658]387set expgui(docdir) [file join $expgui(scriptdir) doc]
388# location for web pages, if not found locally
389set expgui(website) www.ncnr.nist.gov/xtal/software/expgui
[535]390
391source [file join $expgui(scriptdir) gsascmds.tcl]
392source [file join $expgui(scriptdir) opts.tcl]
393
[44]394# override options with locally defined values
[658]395if {[catch {
396    foreach file [list \
397                      [file join $expgui(scriptdir) localconfig] \
398                      [file join ~ .gsas_config]] {
399        if [file exists $file] {source $file}
400    }
401} errmsg]} {
402    set msg "Error reading file $file (aka [file nativename $file]): $errmsg"
403    MyMessageBox -parent . -title "Customize warning" \
404        -message $msg -icon warning -type Ignore -default ignore \
405        -helplink "expguierr.html Customizewarning"
[44]406}
407
[5]408set txtvw(lastchi) {}
409set txtvw(lastcycle) {}
410set txtvw(finalshift) {}
411text .txt -width 100 -wrap none \
412        -yscrollcommand ".yscroll set" \
413        -xscrollcommand ".xscroll set"
[77]414if {$tcl_version >= 8.0} {.txt config -font $txtvw(font)}
[5]415scrollbar .yscroll -command ".txt yview"
416scrollbar .xscroll -command ".txt xview" -orient horizontal
417grid .xscroll -column 0 -row 2 -sticky ew
418grid .txt -column 0 -row 1 -sticky nsew
419grid .yscroll -column 1 -row 1 -sticky ns
420grid columnconfigure . 0 -weight 1
421grid rowconfigure . 1 -weight 1
422wm title . "View $filename"
423wm iconname . $filename
424grid [frame .a -bd 2 -relief raised] -column 0 -row 0 -columnspan 2 -sticky ew
425pack [menubutton .a.file -text File -underline 0 -menu .a.file.menu] \
426            -side left
427menu .a.file.menu
[535]428.a.file.menu add command -label "Delete $filename" -command KillLSTfile
429.a.file.menu add command -label "Trim $filename" -command TrimLSTfile
[5]430.a.file.menu add command -label Exit -command "destroy ."
431
[77]432# windows copy command. Should not be needed in X windows
433if {$tcl_platform(platform) == "windows"} {
434    pack [menubutton .a.edit -text Edit -underline 0 -menu .a.edit.menu] \
435            -side left
436    menu .a.edit.menu
437    .a.edit.menu add command -label copy \
438            -command {catch {clipboard append [selection get]}}
439}
440
[5]441pack [menubutton .a.goto -text "Go To" -underline 0 -menu .a.goto.menu] \
[77]442        -side left
[5]443menu .a.goto.menu
444.a.goto.menu add cascade -label "Cycle #"  -menu .a.goto.menu.cyc \
445        -state disabled
446menu .a.goto.menu.cyc
447.a.goto.menu add cascade -label "Refinement Run #"  -menu .a.goto.menu.run \
448        -state disabled
449menu .a.goto.menu.run
450.a.goto.menu add cascade -label "Summary #"  -menu .a.goto.menu.sum \
451        -state disabled
452menu .a.goto.menu.sum
[535]453.a.goto.menu add command -label "Set Search String" -command GetSearchString
[5]454.a.goto.menu add cascade -label ""  -menu .a.goto.menu.str -state disabled
455menu .a.goto.menu.str
456
[44]457pack [menubutton .a.options -text "Options" -underline 0 \
458        -menu .a.options.menu] \
459            -side left
460menu .a.options.menu
461.a.options.menu  add checkbutton -label "Auto Advance" -variable txtvw(followcycle)
[77]462
463if {$tcl_version >= 8.0} {
[371]464    pack [label .a.fontl -text "  Font:"] -side left
465    set fontbut [tk_optionMenu .a.fontb txtvw(font) ""]
466    pack .a.fontb -side left
467    $fontbut delete 0 end
468    foreach f {5 6 7 8 9 10 11 12 13 14 15 16} {
469        $fontbut add command -label "Courier $f" -font "Courier $f"\
470                -command "set txtvw(font) \"Courier $f\"; \
[77]471                .txt config -font \$txtvw(font)"
472    }
473}
474
[44]475.a.options.menu add command -label "Save Options" -underline 1 \
476        -command "SaveOptions"
477
[535]478proc postingvars {} {
479    global trackinglist
480    eval destroy [winfo children .plot.c.f]
481    set i 0
482    foreach var [lsort [array names trackinglist]] {
483        grid [checkbutton .plot.c.f.$i -text $trackinglist($var) \
484                -pady 0 -command plotvars -variable plotlist($var)] \
485                -column 0 -row [incr i] -sticky w
486    }
[5]487}
488
[535]489proc makeplot {} {
490    # handle Tcl/Tk v8+ where BLT is in a namespace
491    #  use the command so that it is loaded
492    catch {blt::graph}
493    catch {
494        namespace import blt::graph
[5]495    }
[535]496    toplevel .plot
497    grid [graph .plot.g] -col 0 -row 0 -sticky news
498    canvas .plot.c \
499            -scrollregion {0 0 5000 1000} -width 40 -height 250 \
500            -yscrollcommand ".plot.s set"
501    scrollbar .plot.s -command ".plot.c yview"
502    grid .plot.c -col 1 -row 0 -sticky news
503        frame .plot.c.f -class SmallFont
504    .plot.c create window 0 0 -anchor nw -window .plot.c.f
505    grid columnconfigure .plot 0 -weight 1
506    grid rowconfigure .plot 0 -weight 1
507    Blt_ZoomStack .plot.g
508    Blt_ActiveLegend .plot.g
509    .plot.g config -title ""
510    .plot.g xaxis config -title "cycle"
511    .plot.g yaxis config -title ""
512    wm iconify .plot
[5]513}
[535]514
[5]515proc plotvars {} {
516    raise .plot
[535]517    eval .plot.g element delete [.plot.g element names]
518    global trackinglist
519    global plotlist
[5]520    set num 0
[535]521    foreach v [lsort [array names trackinglist]] {
522        set datalist {}
523        if $plotlist($v) {
[5]524            incr num
[535]525            set var tracklist_$v
526            global $var
527            set color [lindex {red green blue magenta cyan yellow} \
528                    [expr $num % 6]]
529            foreach n [lsort -integer [array names $var]] {
530                lappend datalist $n [set ${var}($n)]
531            }
532            .plot.g element create "$var" -data $datalist -color $color \
533                    -label $trackinglist($v)
[5]534        }
535    }
536}
537
[535]538proc hideplot {} {
539    global txtvw
540    if {![winfo exists .plot]} {
541        makeplot
542        postingvars
543    }
544    # hide or show the plot
545    if {$txtvw(hideplot) != 1} {
546        wm iconify .plot
547    } else {
548        wm deiconify .plot
549        update idletasks
550        # size the box width & scrollregion height
551        set sizes [grid bbox .plot.c.f]
552        .plot.c config -scrollregion $sizes -width [lindex $sizes 2]
553        # is the scroll bar needed?
554        if {[winfo height .plot.c] >= [lindex $sizes 3]} {
555            grid forget .plot.s
556        } else {
557            grid .plot.s -col 2 -row 0 -sticky news
558        }
559    }
560}
561
562
563proc KillLSTfile {} {
564    global filename lstfp tcl_platform
565    # confirm the delete
566    set ans [tk_dialog .warn Notify \
567            "OK to delete the contents of $filename?" "" 0 Yes No]
568    if {$ans != 0} return
569    # stop the updates
570    after cancel updatetext
571    # zero out the file
572    close $lstfp
573    set lstfp [open $filename w+]
574    .txt config -state normal
575    .txt delete 0.0 end
576    ClearMenus
577    updatetext
578}
579
580proc TrimLSTfile {} {
581    global filename lstfp tcl_platform txtvw
582   
583    # get the last refinement run position
584    set loc {}
585    # get the starting location
586    catch {
587        set loc [lindex [.a.goto.menu.run entrycget 1 -command] end]
588        set loc [.txt index "$loc - 2lines"]
589        set txtvw(delete) [expr {100.*$loc/[.txt index end]}]
590        .txt see $loc
591
592    }
593    if {$loc == ""} {
594        set txtvw(delete) [expr {50.* \
595                ([lindex [.txt yview] 0] + [lindex [.txt yview] 1])}]
596        set loc [expr {int(0.5+ $txtvw(delete) * [.txt index end]/100.)}].0
597    }
598
599    catch {toplevel .trim}
600    eval destroy [winfo children .trim]
601    wm title .trim "Trim $filename"
602    pack [label .trim.0 -text "File $filename has [expr {int([.txt index end])}] lines total."] -side top
603    pack [label .trim.1 -text "Select percentage of file to delete."] \
604            -anchor w -side top
605   
606    # set the slider resolution so that 1 division is on the
607    # order of 1-2 lines
608    set res .5
609    while {$res > 200./[.txt index end] && $res > 0.01} {
610        if {[string match *5* $res]} {
611            set res [expr $res/2.5]
612        } else {
613            set res [expr $res/2.]
614        }
615    }
616    pack [scale .trim.2 -command HighlightText -orient horizontal \
617            -variable txtvw(delete) \
618            -resolution $res] -expand yes -fill x
619    pack [frame .trim.3]
620    pack [button .trim.3.a -text Trim \
621            -command {DeleteSelectedText; destroy .trim} \
622            ] -side left
623    pack [button .trim.3.b -text Cancel -command {destroy .trim} ] -side left
624    # create a binding so that we can click on the text box
625    .txt tag delete b
626    .txt tag add b 0.0 end
627    .txt tag bind b <1> "ClickHighlightText %x %y"
628    # show the region pending delete
629    .txt tag delete pend
630    .txt tag add pend 0.0 $loc
631    .txt tag config pend -foreground grey
632}
633
634proc ClickHighlightText {x y} {
635    global txtvw
636    if {![winfo exists .trim]} return
637    set loc [.txt index "@$x,$y linestart"]
638    set txtvw(delete) [expr {100.*$loc/[.txt index end]}]
639    .txt tag delete pend
640    .txt tag add pend 0.0 $loc
641    .txt tag config pend -foreground grey
642}
643
644proc DeleteSelectedText {} {
645    global filename lstfp
646    .txt config -state normal
647    eval .txt delete [.txt tag nextrange pend 0.0]
648    # stop the updates
649    after cancel updatetext
650    # zero out the file
651    close $lstfp
652    set lstfp [open $filename w+]
653    puts $lstfp [.txt get 0.0 end]
654    .txt delete 0.0 end
655    ClearMenus
656    seek $lstfp 0
657    updatetext
658}
659
660proc ClearMenus {} {
661    foreach m {str run cyc sum} {
662        .a.goto.menu.$m delete 1 end
663    }
664    foreach num {1 2 3 5} {
665        .a.goto.menu entryconfigure $num -state disabled
666    }
667    global txtvw
668    set txtvw(runnumber) 0
669    set txtvw(sum) 0
670}
671
672proc HighlightText {args} {
673    global txtvw
674    set loc [expr {int(0.5+ $txtvw(delete) * [.txt index end]/100.)}].0
675    .txt tag delete pend
676    .txt tag add pend 0.0 $loc
677    .txt tag config pend -foreground grey
678    .txt see $loc
679}
680
[5]681pack [menubutton .a.help -text Help -underline 0 -menu .a.help.menu] -side right
682menu .a.help.menu
683.a.help.menu add command -command aboutgsas -label "About"
684
685grid [frame .but ] -column 0 -row 3 -columnspan 2 -sticky ew
[535]686pack [label .but.lbl2 -textvariable txtvw(lastcycle) \
687        -relief sunken -bd 2] -side left
688pack [label .but.lbl3 -textvariable txtvw(lastchi) \
689        -relief sunken -bd 2] -side left
690pack [label .but.lbl4 -textvariable txtvw(finalshift) \
691        -relief sunken -bd 2] -side left
[5]692bind all <Control-KeyPress-c> {destroy .}
693bind . <KeyPress-Prior> ".txt yview scroll -1 page"
694bind . <KeyPress-Next> ".txt yview scroll 1 page"
695bind . <KeyPress-Up> ".txt yview scroll -1 unit"
696bind . <KeyPress-Down> ".txt yview scroll 1 unit"
697bind . <KeyPress-Home> ".txt yview 0"
698bind . <KeyPress-End> ".txt yview end"
699#pack [button .but.q -text close -command "destroy ." ] -side right
700.txt tag config cycle -background yellow
701.txt tag config rval -background  green
702.txt tag config chi -background  green
703if [file exists $filename] {
[535]704    set lstfp [open $filename r]
[5]705} else {
706    # create a file if it does not exist
[535]707    set lstfp [open $filename w+]
[5]708}
[135]709donewaitmsg
[658]710# read a file compressed file, if present
711if {$zfil != ""} {
712    updatetext $zfil
713    close $zfil
714}
[5]715# read the initial file
[535]716updatetext $lstfp
[5]717# now start reading with updates
[535]718updatetext
719
720if {$txtvw(plotvars) && ![catch {package require BLT}]} {
721    .a.options.menu add checkbutton -label "Show Plot" -command hideplot \
722            -variable txtvw(hideplot)
723}
Note: See TracBrowser for help on using the repository browser.