Changeset 384 for trunk/gsascmds.tcl


Ignore:
Timestamp:
Dec 4, 2009 5:05:16 PM (13 years ago)
Author:
toby
Message:

# on 2001/04/17 22:49:47, toby did:
revise tk_dialog to MyMessage? box
Use CR/LF format files on all platforms
remove unix file conversion

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsascmds.tcl

    • Property rcs:date changed from 2001/04/16 21:27:22 to 2001/04/17 22:49:47
    • Property rcs:lines changed from +3 -3 to +20 -223
    • Property rcs:rev changed from 1.30 to 1.31
    r380 r384  
    861861                }
    862862            } else {
    863                 tk_dialog .warn "No Browser" \
    864                         "Could not find a browser. Netscape is not in path. Define environment variable BROWSER to be full path name of browser." \
    865                         warn 0 OK
     863                MyMessageBox -parent . -title "No Browser" \
     864                        -message "Could not find a browser. Netscape is not in path. Define environment variable BROWSER to be full path name of browser." \
     865                        -icon warn
    866866            }
    867867        }
     
    11331133    }
    11341134    if {$errmsg != ""} {
    1135         tk_dialog .errorMsg "Export error" $errmsg warning 0 "OK"
     1135        MyMessageBox -parent . -title "Export error" \
     1136                -message "Export error: $errmsg" -icon warning
    11361137        return
    11371138    }
     
    11801181    } errmsg] {
    11811182        catch {close $fp}
    1182         tk_dialog .errorMsg "Export error" $errmsg warning 0 "OK"
     1183        MyMessageBox -parent . -title "Export error" \
     1184                -message "Export error: $errmsg" -icon warning
    11831185    } else {
    11841186        catch {close $fp}
     
    13871389
    13881390#------------------------------------------------------------------------------
    1389 # file conversion for UNIX
     1391# file conversions
    13901392#------------------------------------------------------------------------------
    1391 # convert a file
    13921393proc convfile {} {
    1393     global tcl_platform
    1394     if {$tcl_platform(platform) == "windows"} {
    1395         convwin
    1396     } else {
    1397         convunix
    1398     }
    1399 }
    1400 
    1401 # file conversions for UNIX (convstod convdtos)
    1402 proc convunix {} {
    1403     global expgui infile outfile
    1404     set frm .file
    1405     catch {destroy $frm}
    1406     toplevel $frm
    1407     wm title $frm "Convert File"
    1408     bind $frm <Key-F1> "MakeWWWHelp expgui.html ConvertUnix"
    1409 
    1410     pack [frame [set frm0 $frm.0] -bd 2 -relief groove] \
    1411             -padx 3 -pady 3 -side top -fill x
    1412     pack [frame $frm.mid] -side top
    1413     pack [frame [set frmA $frm.mid.1] -bd 2 -relief groove] \
    1414             -padx 3 -pady 3 -side left
    1415     pack [label $frmA.0 -text "Select an input file"] -side top -anchor center
    1416     pack [frame [set frmB $frm.mid.2] -bd 2 -relief groove] \
    1417             -padx 3 -pady 3 -side left
    1418     pack [label $frmB.0 -text "Enter an output file"] -side top -anchor center
    1419     pack [frame [set frmC $frm.3] ] -padx 3 -pady 3 -side top -fill x -expand y
    1420 
    1421     pack [label $frm0.1 -text "Convert to:"] -side top -anchor center
    1422     pack [frame $frm0.2] -side top -anchor center
    1423     pack [radiobutton $frm0.2.d -text "direct access" -value convstod \
    1424             -command setoutfile \
    1425             -variable outfile(type)] -side left -anchor center
    1426     pack [radiobutton $frm0.2.s -text "sequential" -value convdtos \
    1427             -command setoutfile \
    1428             -variable outfile(type)] -side right -anchor center
    1429     set outfile(type) ""
    1430 
    1431     pack [button $frmC.b -text Convert -command "valid_conv_unix"] -side left
    1432     pack [button $frmC.q -text Quit -command "set infile(done) 1"] -side left
    1433     pack [button $frmC.help -text Help -bg yellow \
    1434             -command "MakeWWWHelp expgui.html ConvertUnix"] \
    1435             -side right
    1436    
    1437     unixcnvbox $frmA infile 1
    1438     unixcnvbox $frmB outfile 0
    1439     set infile(done) 0
    1440     bind $frm <Return> "valid_conv_unix"
    1441     # force the window to stay on top
    1442     putontop $frm
    1443     focus $frmC.q
    1444     update
    1445     tkwait variable infile(done)
    1446     destroy $frm
    1447     afterputontop
    1448 }
    1449 
    1450 # validate the files and make the conversion -- unix
    1451 proc valid_conv_unix {} {
    1452     global infile outfile expgui
    1453     set error {}
    1454     if {$outfile(type) == "convstod" || $outfile(type) == "convdtos"} {
    1455         set convtype $outfile(type)
    1456     } else {
    1457         append error "You must specify a conversion method: to direct access or to sequential.\n"
    1458     }
    1459     if {$infile(name) == ""} {
    1460         append error "You must specify an input file to convert.\n"
    1461     }
    1462     if {$outfile(name) == ""} {
    1463         append error "You must specify an output file name for the converted file.\n"
    1464     }
    1465     if {$error != ""} {
    1466         tk_dialog .warn Notify $error warning 0 OK
    1467         return
    1468     }
    1469 
    1470     if {$infile(name) == $outfile(name)} {
    1471         MyMessageBox -parent . -title Notify \
    1472                 -message "Sorry, filenames must differ" \
    1473                 -icon warning -helplink "expguierr.html ConvSameName"
    1474         tk_dialog .warn Notify "Sorry, filenames must differ" warning 0 OK
    1475         return
    1476     }
    1477     if ![file exists [file join $infile(dir) $infile(name)]] {
    1478         MyMessageBox -parent . -title Notify \
    1479                 -message "Sorry, file $infile(name) not found in $infile(dir)" \
    1480                 -icon warning -helplink "expguierr.html ConvNotFound"
    1481         return
    1482     }
    1483     if [file exists [file join $outfile(dir) $outfile(name)]] {
    1484         set ans [MyMessageBox -parent . -title "Overwrite?" \
    1485                 -message "Warning: file $outfile(name) exists in $outfile(dir). OK to overwrite?" \
    1486                 -icon warning -type {Overwrite Cancel} -default Overwrite \
    1487                 -helplink "expguierr.html OverwriteCnv"]
    1488         if {[string tolower $ans] == "cancel"} return
    1489     }
    1490     if [catch {
    1491         exec [file join $expgui(gsasexe) $convtype] < \
    1492                 [file join $infile(dir) $infile(name)] > \
    1493                 [file join $outfile(dir) $outfile(name)]
    1494     } errmsg] {
    1495         tk_dialog .warn Notify "Error in conversion:\n$errmsg" warning 0 OK
    1496     } else {
    1497         if [tk_dialog .converted Notify \
    1498                 "File converted. Convert more files?" \
    1499                 ""  0 Yes No] {set infile(done) 1}
    1500     }
    1501 }
    1502 
    1503 # create a file box for UNIX conversions
    1504 proc unixcnvbox {bx filvar diropt} {
    1505     global ${filvar} expgui
    1506     pack [frame $bx.top] -side top
    1507     pack [label $bx.top.a -text "Directory" ] -side left
    1508     set ${filvar}(FileDirButtonMenu) [tk_optionMenu $bx.top.d ${filvar}(dir) [pwd] ]
    1509     pack $bx.top.d -side left
    1510     set ${filvar}(dir) [pwd]
    1511 
    1512 #    pack [label $bx.d -textvariable ${filvar}(dir) -bd 2 -relief raised ] -side top
    1513 #    set ${filvar}(dir) [pwd]
    1514 
    1515     pack [frame $bx.a -width 200 -height 75] -side top -expand yes -fill both
    1516     listbox $bx.a.files -relief raised -bd 2 \
    1517             -yscrollcommand "$bx.a.scroll set" \
    1518             -height 15 -width 0 -exportselection 0
    1519     scrollbar $bx.a.scroll -command "$bx.a.files yview"
    1520     unixFilChoose $bx $bx.a.files $filvar $diropt
    1521     if {$filvar == "infile"} {
    1522         bind $bx.a.files <ButtonRelease-1> \
    1523                 "unixFilChoose $bx $bx.a.files $filvar $diropt; setoutfile"
    1524     } else {
    1525         bind $bx.a.files <ButtonRelease-1> \
    1526                 "unixFilChoose $bx $bx.a.files $filvar $diropt"
    1527     }
    1528     pack $bx.a.scroll -side left -fill y
    1529     pack $bx.a.files -side left -fill both -expand yes
    1530     pack [entry $bx.c -textvariable ${filvar}(name)] -side top
    1531 }
    1532 
    1533 # select a file or directory, also called when box is created to fill it
    1534 proc unixFilChoose {frm box filvar {dironly 1}} {
    1535     global $filvar
    1536     set select [$box curselection]
    1537     if {$select == ""} {
    1538         set file .
    1539     } else {
    1540         set file [string trim [$box get $select]]
    1541     }
    1542     if [file isdirectory [file join [set ${filvar}(dir)] $file]] {
    1543         if {$file == ".."} {
    1544             set ${filvar}(dir) [file dirname [set ${filvar}(dir)] ]
    1545         } elseif {$file != "."} {
    1546             set ${filvar}(dir) [file join [set ${filvar}(dir)] $file]
    1547         }
    1548         [set ${filvar}(FileDirButtonMenu)] delete 0 end
    1549         set list ""
    1550         set dir ""
    1551         foreach subdir [file split [set ${filvar}(dir)]] {
    1552             set dir [file join $dir $subdir]
    1553             lappend list $dir
    1554         }
    1555         foreach path $list {
    1556             [set ${filvar}(FileDirButtonMenu)] add command -label $path \
    1557                 -command "[list set ${filvar}(dir) $path]; \
    1558                 unixFilChoose $frm $box $filvar $dironly"
    1559         }
    1560         set ${filvar}(name) {}
    1561         $box delete 0 end
    1562         $box insert end {..   }
    1563         foreach file [lsort -dictionary [glob -nocomplain \
    1564                 [file join [set ${filvar}(dir)] *] ] ] {
    1565             if {[file isdirectory $file]} {
    1566                 # is this / needed here? Does it cause a problem in MacGSAS?
    1567                 $box insert end [file tail $file]/
    1568             } elseif {$dironly == 1} {
    1569                 $box insert end [file tail $file]
    1570             } elseif {$dironly == 2 && [file extension $file] == ".EXP"} {
    1571                 $box insert end [file tail $file]
    1572             }
    1573         }
    1574         return
    1575     }
    1576     set ${filvar}(name) [file tail $file]
    1577 }
    1578 
    1579 # set new file name from old -- used for convunix
    1580 proc setoutfile {} {
    1581     global infile outfile
    1582     if {$outfile(type) == "convstod"} {
    1583         set lfile [string toupper $infile(name)]
    1584     } elseif {$outfile(type) == "convdtos"} {
    1585         set lfile [string tolower $infile(name)]
    1586     } else {
    1587         set lfile ""
    1588     }
    1589     if {$infile(name) == $lfile} {
    1590         set outfile(name) {}
    1591     } else {
    1592         set outfile(name) $lfile
    1593     }
    1594 }
    1595 
    1596 #------------------------------------------------------------------------------
    1597 # file conversions for Windows
    1598 #------------------------------------------------------------------------------
    1599 proc convwin {} {
    16001394    global expgui
    16011395    set frm .file
     
    16491443    set file [file join $expgui(FileMenuDir) $expgui(FileMenuCnvName)]
    16501444    if ![file exists $file] {
    1651         tk_dialog .warn "Convert Error" \
    1652                 "File $file does not exist" question 0 "OK"
     1445        MyMessageBox -parent $frm -title "Convert Error" \
     1446                -message "File $file does not exist" -icon error
    16531447        return
    16541448    }
     
    16681462        set in [open $file r]
    16691463        set out [open $tmpname w]
     1464        fconfigure $out -translation crlf
    16701465        set len [gets $in line]
    16711466        if {$len > 160} {
     
    16921487        file rename -force $tmpname $file
    16931488    } errmsg] {
    1694         tk_dialog .warn Notify "Error in conversion:\n$errmsg" warning 0 OK
     1489        MyMessageBox -parent $frm -title "Conversion error" \
     1490                -message "Error in conversion:\n$errmsg" -icon warning
    16951491    } else {
    1696         if [tk_dialog .converted Notify \
    1697                 "File [file tail $file] converted. (Original saved as [file tail $oldname]).\n\n Convert more files?" \
    1698                 ""  0 Yes No] {destroy $frm}
     1492        set ans [MyMessageBox -parent $frm -title "More?" \
     1493                -message "File [file tail $file] converted.\n(Original saved as [file tail $oldname]).\n\n Convert more files?" \
     1494                -type yesno -default no]
     1495        if {$ans == "no"} {destroy $frm}
    16991496    }
    17001497}
     
    19461743    # flag files that end in something other than .EXP .exp or .Exp...
    19471744    if {[string toupper [file extension $expgui(FileMenuEXPNAM)]] != ".EXP"} {
    1948         tk_dialog .expFileErrorMsg "File Open Error" \
    1949             "File [file tail $expgui(FileMenuEXPNAM)] is not a valid name. Experiment files must end in \".EXP\"" \
    1950             error 0 OK
     1745        MyMessageBox -parent . -title "File Open Error" \
     1746                -message "File [file tail $expgui(FileMenuEXPNAM)] is not a valid name. Experiment files must end in \".EXP\"" \
     1747                -icon error
    19511748        return
    19521749    }
Note: See TracChangeset for help on using the changeset viewer.