source: trunk/instedit.tcl @ 741

Last change on this file since 741 was 741, checked in by toby, 14 years ago

# on 2003/11/05 22:14:46, toby did:
prepare for OSX - remove puts

  • Property rcs:author set to toby
  • Property rcs:date set to 2003/11/05 22:14:46
  • Property rcs:lines set to +1 -4
  • Property rcs:rev set to 1.3
  • Property rcs:state set to Exp
  • Property svn:keywords set to Author Date Revision Id
File size: 21.2 KB
Line 
1# $Id: instedit.tcl 741 2009-12-04 23:11:14Z toby $
2
3# stuff to do
4#   might want to show error location for error in instSaveAs
5#   (need to save rather than pass $box)
6
7source [file join $expgui(scriptdir) readinst.tcl]
8
9proc instMakeBankSel {box} {
10    global instdat instparms
11    eval destroy [winfo children [set topfr $box.a]]
12    pack [label $topfr.l1 -text "Select bank: "] -side left
13    pack [frame $topfr.fr] -side left
14    set col 0
15    set row 0
16    for {set i 1} {$i <= $instdat(lastbank)} {incr i} {
17        grid [radiobutton $topfr.fr.$i -text $i -value $i \
18                -command "instShowBank $box"\
19                -variable instparms(bank)] -row $row -column $col
20        if {[incr col] > 10} {set col 0; incr row}
21    }
22    pack [button $topfr.n -text "Add bank" -command "instNewBank $box"] -side left
23    pack [label $topfr.l2 -text "Data type: "] -side left   
24    set menu [tk_optionMenu $topfr.w instparms(banklabel) "     "]
25    set instparms(banklabel) {}
26    pack $topfr.w -side left
27    pack [button $topfr.quit -text "Close" \
28            -command instConfirmQuit] -side right
29    pack [button $topfr.sa -text "Save as" -command instSaveAs] -side right
30    pack [button $topfr.s -text "Save" -state disabled \
31            -command {instSaveAs $instparms(filename)}] -side right
32    set instparms(savebutton) $topfr.s
33    $menu delete 0 end
34    foreach lbl {TOF   "CW neutron" "CW X-ray" "ED X-ray"} \
35            val {PNTR  PNCR         PXCR       PXER} {
36        $menu add radiobutton -value $val -label $lbl \
37                -variable instdat(banktype) \
38                -command "instShowBank $box"
39    }
40}
41
42proc instLoadAllBanks {} {
43    global instdat instparms
44    set instdat(lastbank) [instinfo bank]
45    set instdat(banktype) [instinfo type]
46    # loop over banks
47    for {set i 1} {$i <= $instdat(lastbank)} {incr i} {
48        set instdat(rad$i) [instbankinfo rad $i]
49        if {$instdat(rad$i) == ""} {set instdat(rad$i) 0}
50        set instdat(head$i) [instbankinfo head $i]
51        set instdat(name$i) [instbankinfo name $i]
52        foreach var {difc difa zero pola ipola kratio} \
53                val [instbankinfo icons $i] {
54            if {$val == ""} {set val 0}
55            set instdat(${var}$i) $val
56        }
57        # loop over the profile terms
58        set j 1
59        while {[set proflist [instprofinfo $i $j]] != ""} {
60            set instdat(proftype${i}_$j) [lindex $proflist 0]
61            set instdat(profcut${i}_$j) [lindex $proflist 1]
62            set k 0
63            foreach v [lindex $proflist 2] {
64                incr k
65                set instdat(prof${i}_${j}_$k) $v
66            }
67            set instparms(profterms${i}_${j}) $k
68            set instparms(proftypes${i}) $j
69            incr j
70        }
71    }
72    set instparms(changes) 0
73}
74
75proc instSaveAs {"filename {}"} {
76    global instdat instparms
77    instinfo type set $instdat(banktype)
78    # loop over banks
79    set msg {}
80    for {set i 1} {$i <= $instdat(lastbank)} {incr i} {
81        instbankinfo rad $i set $instdat(rad$i) 
82        instbankinfo head $i set $instdat(head$i) 
83        if {[string trim $instdat(name$i)] == ""} {
84            append msg "\n  The instrument name may not be blank"
85        }
86        instbankinfo name $i set $instdat(name$i)
87        set l {}
88        foreach var {difc difa zero pola ipola kratio} {
89            lappend l $instdat(${var}$i)
90        }
91        if {[instbankinfo icons $i set $l] != 1} {
92            append msg "\n  There is an error in values for:\n    the wavelength, zero or polarization"
93        }
94        # loop over the profile terms
95
96        for {set j 1} {$j <= $instparms(proftypes${i})} {incr j} {
97            set l {}
98            for {set k 1} {$k <= $instparms(profterms${i}_$j)} {incr k} {
99                lappend l $instdat(prof${i}_${j}_$k)
100            }
101            if {[instprofinfo $i $j set [list \
102                    $instdat(proftype${i}_$j) $instdat(profcut${i}_$j) $l]\
103                    ] != 1} {
104                append msg "\n  There is an error in the values for profile set $j."
105            }
106        }
107        if {$msg != ""} {
108            MyMessageBox -parent . -title "No save" \
109                    -message "Error in input for bank $i:$msg" -icon warning \
110                    -type Sorry -default sorry
111            return
112        }
113    }
114    if {$filename == ""} {
115        set instparms(filename) [tk_getSaveFile \
116                -title "Enter a file name for the instrument parameter file" \
117                -parent . -defaultextension .ins \
118                -filetypes {{"Instrument parameters file" ".ins .inst .prm"} {All *.*}}]
119    }
120    if {$instparms(filename) == ""} return
121    instwrite $instparms(filename)
122    MyMessageBox -parent . -title "File written" \
123                -message "File $instparms(filename) written." -type OK -default ok
124    global instparms
125    set instparms(changes) 0
126    $instparms(savebutton) config -state disabled
127    wm title . "Editing instrument parameter file $instparms(filename)"
128}
129
130
131proc instNewBank {box} {
132    global instdat instparms
133    set i [incr instdat(lastbank)]
134    instMakeBankSel $box
135    set instparms(bank) $i
136    # initialize the bank values
137    set instdat(rad$i) ""
138    set instdat(name$i) ""
139    foreach var {difc difa zero pola ipola kratio} {
140        set instdat(${var}$i) ""
141    }
142    set instparms(proftypes$i) 0
143    instShowBank $box
144    AddInstProfile $box $i
145    instShowBank $box
146}
147
148proc instShowBank {box} {
149    global instdat instparms
150    if {$instparms(bank) == 0} return
151    switch [string range $instdat(banktype) 0 2] {
152        PNT  {set instparms(banklabel) TOF}
153        PNC  {set instparms(banklabel) "CW neutron"}
154        PXC  {set instparms(banklabel) "CW X-ray"}
155        PXE  {set instparms(banklabel) "ED X-ray"}
156    }
157    eval destroy [winfo children [set bnkfr $box.b]]
158    set b $instparms(bank)
159    grid [label $bnkfr.l1 -text "Bank #$b" -relief raised -bd 2 \
160            -anchor w -justify left] \
161            -column 0 -row 0 -columnspan 99 -sticky ew
162    grid [label $bnkfr.l2 -text "Title: "] -column 0 -row 1 -sticky e
163    grid [entry $bnkfr.e2 -textvariable instdat(head$b) -width 60] \
164            -column 1 -row 1 -sticky w -columnspan 99
165
166    grid [label $bnkfr.l3 -text "Instrument\nname: " -anchor e -justify r] \
167            -column 0 -row 2 -sticky e
168    grid [entry $bnkfr.e3 -textvariable instdat(name$b) -width 30] \
169            -column 1 -row 2 -sticky w -columnspan 99
170
171    if {$instparms(banklabel) == "TOF"} return
172    if {$instparms(banklabel) == "ED X-ray"} return
173
174    set col 0
175    grid [label $bnkfr.l4a -text "Radiation\ntype:" -anchor e -justify r] \
176            -column $col -row 4 -sticky e -rowspan 2
177    set menu [tk_optionMenu $bnkfr.rad instparms(irad) "     "]
178    $bnkfr.rad config -width 6
179   
180    grid $bnkfr.rad -column [incr col] -row 4 -sticky w -rowspan 2
181    grid [radiobutton $bnkfr.c4a -text Monochromatic \
182            -command "disableWaveBoxes $bnkfr $b" \
183            -variable instparms(wavemode) -value 1] \
184            -column [incr col] -row 4 -sticky w
185    grid [radiobutton $bnkfr.c4b -text Dual \
186            -command "disableWaveBoxes $bnkfr $b" \
187            -variable instparms(wavemode) -value 2] \
188            -column $col -row 5 -sticky w
189
190           
191    grid [label $bnkfr.l4 -text "Wavelength: "] \
192            -column [incr col] -row 4 -sticky e -rowspan 2
193    grid [entry $bnkfr.e4d -textvariable instdat(difc$b) -width 10] \
194            -column [incr col] -row 5 -sticky ew
195    grid [label $bnkfr.l4d -text Primary] -column $col -row 4 -sticky ew
196    grid [entry $bnkfr.e4e -textvariable instdat(difa$b) -width 10] \
197            -column [incr col] -row 5 -sticky ew
198    grid [label $bnkfr.l4e -text Secondary] -column $col -row 4 -sticky ew
199    grid [entry $bnkfr.e4f -textvariable instdat(kratio$b) -width 10] \
200            -column [incr col] -row 5 -sticky ew
201    grid [label $bnkfr.l4f -text ratio] -column $col -row 4 -sticky ew
202
203    set col 0
204    grid [label $bnkfr.l6 -text "Zero\nCorrection:" \
205            -anchor e -justify r] \
206            -column $col -row 6 -sticky e
207    grid [entry $bnkfr.e6 -textvariable instdat(zero$b) -width 10] \
208            -column [incr col] -row 6 -sticky ew
209
210    set col 0
211    grid [label $bnkfr.l7 -text "Polarization\nCorrection:" \
212            -anchor e -justify r] \
213            -column $col -row 7 -sticky e
214    grid [radiobutton $bnkfr.c7a -text "Diffracted Beam" \
215            -variable instdat(ipola$b) -value 0] \
216            -column [incr col] -row 7 -sticky w
217    grid [radiobutton $bnkfr.c7b -text "Incident Beam" \
218            -variable instdat(ipola$b) -value 1] \
219            -column [incr col] -row 7 -sticky w
220    grid [radiobutton $bnkfr.c7c -text "None" \
221            -variable instdatr(ipola$b) -value 2] \
222            -column [incr col] -row 7 -sticky w
223    grid [label $bnkfr.l7a -text "Polarization\nFraction:" \
224            -anchor e -justify r] \
225            -column [incr col] -row 7 -sticky e
226    grid [entry $bnkfr.e7 -textvariable instdat(pola$b) -width 10] \
227            -column [incr col] -row 7 -sticky ew
228
229    grid [frame [set prfrm $bnkfr.prof] -bd 2 -relief groove] \
230            -column 0 -columnspan 99 -row 8
231    grid [label $prfrm.l1 -text "Select profile: "] -column 0 -row 0
232    grid [frame $prfrm.fr] -column 1 -columnspan 99 -row 0 -sticky w
233    grid [frame $prfrm.fr1] -column 0 -columnspan 99 -row 2
234    set instparms(profileframe) $prfrm.fr1
235    for {set j 1} {$j <= $instparms(proftypes${b})} {incr j} {
236        grid [radiobutton $prfrm.fr.$j -text $j -value $j \
237                -command "ShowInstProfile $b" \
238                -variable instparms(profilenum)] -row 1 -column $j
239    }
240    grid [button $prfrm.fr.a -text "Add profile" \
241            -command "AddInstProfile $box $b"] -row 1 -column 98
242    grid [button $prfrm.fr.n -text "Import profile" \
243            -command "ImportInstProfile $box $prfrm.fr1 $b"] -row 1 -column 99
244    $menu delete 0 end
245    foreach lbl {Cr Fe Cu Mo Ag Other} \
246            val { 1  2  3  4  5     0} {
247        $menu add radiobutton -value $val -label $lbl \
248                -command "setRadLabel $b" \
249                -variable instdat(rad$b)
250    }
251    if {$instdat(difa$b) == 0.0} {
252        set instparms(wavemode) 1
253    } else {
254        set instparms(wavemode) 2
255    }
256    switch $instdat(rad$b) {
257        0 {set instparms(irad) Other}
258        1 {set instparms(irad) Cr}
259        2 {set instparms(irad) Fe}
260        3 {set instparms(irad) Cu}
261        4 {set instparms(irad) Mo}
262        5 {set instparms(irad) Ag}
263    }
264    setRadLabel $b
265    disableWaveBoxes $bnkfr $b
266    set instparms(profilenum) 1
267    ShowInstProfile $b
268}
269
270proc ImportInstProfile {box frame b} {
271    global instparms instdat
272    set j $instparms(profilenum)
273
274    set filename [tk_getOpenFile \
275            -title "Select GSAS Experiment file\nor press Cancel." \
276            -parent . -defaultextension EXP \
277            -filetypes {{"GSAS Experiment file" ".EXP"}}]
278    if {$filename == ""} {return}
279    global wishshell expgui
280    set result {}
281    catch {
282        set result [exec $wishshell \
283                [file join $expgui(scriptdir) dumpprof.tcl] $filename]
284    }
285    if {[set nhist [llength $result]] == 0} {
286        set msg "No profile information was read from file $filename"
287        MyMessageBox -parent . -title "No histograms read" \
288                -message $msg -icon warning -type Sorry -default sorry
289                #-helplink "expguierr.html Customizewarning"
290        return
291    }
292    set i -1
293    set hlist {}
294    set prlist {}
295    foreach histrec $result {
296        incr i
297        set h [lindex $histrec 0]
298        set type [lindex $histrec 1]
299        if {[string range $type 0 2] == \
300                [string range $instdat(banktype) 0 2]} {
301            lappend hlist $h
302            lappend prlist [lrange $histrec 2 end]
303        }
304    }
305    if {[llength $hlist] == 0} {
306        set msg "No histograms of type \"$instparms(banklabel)\" were found"
307        MyMessageBox -parent . -title "No matching histograms" \
308                -message $msg -icon warning -type Sorry -default sorry
309                #-helplink "expguierr.html Customizewarning"
310        return
311    }
312
313    catch {destroy $instparms(top).sel}
314    toplevel [set top $instparms(top).sel]
315    wm title $top "Select histogram and phase to select"
316    grid [label $top.l1 -text "Histogram: "] -column 1 -row 1
317    set menu [tk_optionMenu $top.w instparms(histimport) ""]
318    $menu delete 0 end
319    if {[llength $hlist] > 10} {
320        set h [lrange $hlist 0 9]
321        set pr [lrange $prlist 0 9]
322        set hlist [lrange $hlist 10 end]
323        set prlist [lrange $prlist 10 end]
324        set j 0
325        while {[llength $h] > 0} {
326            set label "[lindex $h 0]-[lindex $h end]"
327            $menu add cascade -label $label -menu $menu.$j
328            menu $menu.$j
329            foreach val $h pl $pr {
330                $menu.$j add radiobutton -value $val -label $val \
331                        -command "instSetPhaseList [list $pl]" \
332                        -variable instparms(histimport)
333            }
334            set h [lrange $hlist 0 9]
335            set pr [lrange $prlist 0 9]
336            set hlist [lrange $hlist 10 end]
337            set prlist [lrange $prlist 10 end]
338            incr j
339        }
340    } else {
341        foreach val $hlist ph $prlist {
342            $menu add radiobutton -value $val -label $val \
343                    -command "instSetPhaseList [list $ph]" \
344                    -variable instparms(histimport)
345        }
346    }
347    grid $top.w -column 2 -row 1 -columnspan 2 -sticky w
348    set instparms(histimport) [lindex $hlist 0]
349    grid [label $top.l2 -text "Phase: "] -column 1 -row 2
350    set col 1
351    foreach h {1 2 3 4 5 6 7 8 9} {
352        grid [radiobutton $top.r$h \
353                -variable instparms(phaseimport) -value $h -text $h \
354                ] -column [incr col] -row 2
355    }
356    grid [frame $top.prof] -column 0 -columnspan 99 -row 3
357    grid [button $top.b1 -text Import -command "" -state disabled] \
358            -column 0 -columnspan 2 -row 4
359    grid [button $top.b2 -text Cancel -command "destroy $top"] \
360            -column 2 -columnspan 2 -row 4
361
362    # there a single histogram, select it
363    if {[llength $hlist] == 1} {
364        set instparms(histimport) $hlist
365        instSetPhaseList [lindex $prlist 0]
366    } else {
367        set instparms(histimport) {}
368    }
369    putontop $top
370    tkwait window $top
371    afterputontop 
372}
373
374proc instSetPhaseList {proflist} {
375    global instparms
376    set top $instparms(top).sel
377    set instparms(phaseimport) {}
378    $top.b1 config -state disabled -command ""
379    foreach h {1 2 3 4 5 6 7 8 9} {
380        $top.r$h config -state disabled -command ""
381    }
382    foreach item $proflist {
383        set h [lindex $item 0]
384        $top.r$h config -state normal \
385                -command "instSelectPhase [list $item]"
386    }
387    eval destroy [winfo children [set frame $top.prof]]
388    if {[llength $proflist] == 1} {$top.r$h invoke}
389}
390
391proc instSelectPhase {proflist} {
392    global instparms instdat
393    set top $instparms(top).sel
394    eval destroy [winfo children [set frame $top.prof]]
395    set row 0
396    set col 0
397    set num [lindex $proflist 1]
398    set lbl [lindex \
399            {"" "1: Gaussian only" "2: Pseudo-Voigt" \
400            "3: Pseudo-Voigt/FCJ Asym" "4: P-V/FCJ/Stephens Aniso Brdg"} $num]
401    grid [label $frame.${col}_$row -justify left -anchor w \
402            -text "Profile type $lbl"] \
403            -column $col -row $row -columnspan 99 -sticky w
404    incr row
405    set col 0
406    grid [label $frame.${col}_$row -text "Peak cutoff"  -padx 4] \
407            -column $col -row $row -sticky e
408    incr col
409    grid [label $frame.${col}_$row -text "[lindex $proflist 2]" \
410            -relief groove -bd 2 -padx 2] \
411            -column $col -row $row -sticky ew
412    incr col
413    set N $num
414    set T [string range $instdat(banktype) 2 2]
415    set lbllist ""
416    global expgui
417    catch {set lbllist $expgui(prof-${T}-$N)}
418    set i 0
419    foreach lbl $lbllist val [lrange $proflist 3 end] {
420        incr i
421        if {$col > 6} {set col 0; incr row}
422        grid [label $frame.${col}_$row -text $lbl -padx 4] \
423                -column $col -row $row -sticky e
424        incr col
425        grid [label $frame.${col}_$row -text $val \
426                -bd 2 -padx 2 -relief groove] \
427                -column $col -row $row -sticky ew
428        incr col
429    }
430    $top.b1 config -state normal \
431            -command "instSetProfile [list $proflist]; destroy $top"
432}
433
434proc instSetProfile {proflist} {
435    global instparms instdat expgui
436    set b $instparms(bank)
437    set j $instparms(profilenum)
438    set N [set instdat(proftype${b}_$j) [lindex $proflist 1]]
439    set T [string range $instdat(banktype) 2 2]
440    set lbllist ""
441    catch {set lbllist $expgui(prof-${T}-$N)}
442    set instdat(profcut${b}_$j) [lindex $proflist 2]
443    set i 0
444    foreach lbl $lbllist val [lrange $proflist 3 end] {
445        incr i
446        if {$val == ""} {set val "0.0"}
447        set instdat(prof${b}_${j}_$i) $val
448    }
449    ShowInstProfile $b
450}
451
452proc AddInstProfile {box b} {
453    global instparms instdat
454    set frame $instparms(profileframe)
455    incr instparms(proftypes${b})
456    instShowBank $box
457    set instparms(profilenum) $instparms(proftypes${b})
458    set instdat(proftype${b}_$instparms(profilenum)) " "
459    ShowInstProfile $b
460}
461
462proc ShowInstProfile {b} {
463    global instparms instdat
464    set frame $instparms(profileframe)
465    set j $instparms(profilenum)
466    eval destroy [winfo children $frame]
467    set row 0
468    set col 0
469    grid [label $frame.${col}_$row -text "Profile\ntype"] \
470            -column $col -row $row
471    incr col
472    set menu [tk_optionMenu $frame.${col}_$row instdat(proftype${b}_$j) " "]
473    grid $frame.${col}_$row -column $col -row $row -sticky ew
474    $menu delete 0 end
475    foreach val { 1  2  3  4} \
476            lbl {"1) Gaussian only" "2) Pseudo-Voigt" \
477            "3) Pseudo-Voigt/FCJ Asym" "4) P-V/FCJ/Stephens Aniso Brdg"} {
478        $menu add radiobutton -value $val -label $lbl \
479                -command "instInitProf; ShowInstProfile $b" \
480                -variable instdat(proftype${b}_$j)
481    }
482    if {$instdat(proftype${b}_$j) == " "} return
483
484    incr col
485    grid [label $frame.${col}_$row -text "Peak\ncutoff"] \
486            -column $col -row $row
487    incr col
488    if [catch {set instdat(profcut${b}_$j)}] {
489        set instdat(profcut${b}_$j) 0.01
490    }
491    grid [entry $frame.${col}_$row -width 10 \
492            -textvariable instdat(profcut${b}_$j)] \
493            -column $col -row $row
494    incr row
495    set col 0
496    set N $instdat(proftype${b}_$j)
497    set T [string range $instdat(banktype) 2 2]
498    set lbllist ""
499    global expgui
500    catch {set lbllist $expgui(prof-${T}-$N)}
501    set i 0
502    foreach lbl $lbllist {
503        incr i
504        if {$col > 6} {set col 0; incr row}
505        grid [label $frame.${col}_$row -text $lbl] \
506                -column $col -row $row
507        incr col
508        if [catch {set instdat(prof${b}_${j}_$i)}] {
509            set instdat(prof${b}_${j}_$i) 0.0
510        }
511        grid [entry $frame.${col}_$row -width 14 \
512                -textvariable instdat(prof${b}_${j}_$i)] \
513                -column $col -row $row
514        incr col
515    }
516    # reset the number of terms to match the # of labels
517    set instparms(profterms${b}_${j}) $i
518}
519
520proc instInitProf {} {
521    global instparms instdat
522    set b $instparms(bank)
523    set j $instparms(profilenum)
524    set N $instdat(proftype${b}_$j)
525    set T [string range $instdat(banktype) 2 2]
526    global expgui
527    set i 0
528    set lbllist ""
529    catch {set lblist $expgui(prof-${T}-$N)}
530    foreach lbl $lbllist {
531        incr i
532        set instdat(prof${b}_${j}_$i) 0.0
533    }
534    # reset the number of terms to match the # of labels
535    set instparms(profterms${b}_${j}) $i
536}
537
538proc disableWaveBoxes {frame b} {
539    global instparms instdat
540    if {$instparms(banklabel) == "CW neutron"} {
541        set instparms(wavemode) 1
542        set mode disabled
543        set color gray
544    } else {
545        set mode normal
546        set color black
547    }
548    $frame.rad config -state $mode
549    foreach v {c4b c7a c7b c7c e7} {
550        $frame.$v config -state $mode -fg $color
551    }
552    foreach v {l7 l7a} {
553        $frame.$v config -fg $color
554    }
555
556    if {$instparms(wavemode) == 1} {
557        set mode disabled
558        set color gray
559        if {$instdat(difa$b) != 0} {set instdat(difa$b) 0.0}
560    } else {
561        set mode normal
562        set color black
563    }
564    foreach w {e4e e4f} {
565        $frame.$w config -state $mode -fg $color
566    }
567    foreach w {l4e l4f} {
568        $frame.$w config -fg $color
569    }
570}
571
572proc setRadLabel {b} {
573    global instparms instdat
574    switch $instdat(rad$b) {
575        0 {set instparms(irad) Other}
576        1 {
577            set instparms(irad) Cr
578            set instdat(difc$b) 2.28970
579            set instdat(difa$b) 2.29361
580        }
581        2 {
582            set instparms(irad) Fe
583            set instdat(difc$b) 1.93604
584            set instdat(difa$b) 1.93998
585        }
586        3 {
587            set instparms(irad) Cu
588            set instdat(difc$b) 1.54056
589            set instdat(difa$b) 1.54439
590        }
591        4 {
592            set instparms(irad) Mo
593            set instdat(difc$b) 0.70930
594            set instdat(difa$b) 0.71359
595        }
596        5 {
597            set instparms(irad) Ag
598            set instdat(difc$b) 0.55941
599            set instdat(difa$b) 0.56380
600        }
601    }
602    if {$instparms(wavemode) == 1} {
603        if {$instdat(difa$b) != 0} {set instdat(difa$b) 0.0}
604    } else {
605        if {$instdat(kratio$b) != 0.5} {set instdat(kratio$b) 0.5}
606    }
607}
608
609proc traceinstdat {args} {
610    global instparms
611    incr instparms(changes)
612    if {$instparms(filename) != ""} {
613        $instparms(savebutton) config -state normal
614    }
615}
616
617proc instConfirmQuit {} {
618    global instparms
619    if {$instparms(changes) == 0} {
620        destroy $instparms(top)
621        return
622    }
623    set ans [MyMessageBox -parent . -title "Unsaved Changes" \
624            -message "You have made changes. Are you sure you want to exit?" \
625            -icon question -type "Exit Cancel" -default cancel]
626    if {$ans == "exit"} {
627        destroy $instparms(top)
628        return
629    }
630}
631
632proc instMakeWindow {"filename {}"} {
633    global instparms instdat
634
635    set instparms(top) .instedit
636    catch {toplevel $instparms(top)}
637    eval destroy [winfo children $instparms(top)]
638
639    if {$filename == ""} {
640        set instparms(filename) [tk_getOpenFile \
641                -title "Select Instrument parameter file\nor press Cancel to create a new file." \
642                -parent $instparms(top) -defaultextension ins \
643                -filetypes {{"Instrument parameters file" ".ins .inst .prm"} {All *.*}}]
644    } else {
645        set instparms(filename) $filename
646    }
647
648    grid [frame $instparms(top).b1 -bd 2 -relief groove] -column 1 -row 1
649    grid [frame $instparms(top).b1.a] -column 0 -row 0 -sticky ew
650    grid [frame $instparms(top).b1.b] -column 0 -row 1 -sticky ew
651
652    instInit
653    if {[file exists $instparms(filename)]} {
654        instload $instparms(filename)
655        instLoadAllBanks
656        instMakeBankSel $instparms(top).b1
657        set instparms(bank) 1
658        instShowBank $instparms(top).b1
659    } else {
660        set instdat(lastbank) 0
661        instMakeBankSel $instparms(top).b1
662        instNewBank $instparms(top).b1
663    }
664    set instparms(changes) 0
665    wm protocol $instparms(top) WM_DELETE_WINDOW instConfirmQuit
666    if {$instparms(filename) == ""} {
667        wm title $instparms(top) "Editing unnamed instrument parameter file"
668    } else {
669        wm title $instparms(top) "Editing instrument parameter file $instparms(filename)"
670    }
671    bind $instparms(top) <Control-KeyPress-c> instConfirmQuit
672    set instparms(changes) 0
673    # set up a trace
674    trace variable instdat w traceinstdat
675    putontop $instparms(top)
676    tkwait window $instparms(top)
677    afterputontop
678    # delete the trace
679    foreach v [trace vinfo instdat] {eval trace vdelete instdat $v}
680}
681
Note: See TracBrowser for help on using the repository browser.