Changeset 728


Ignore:
Timestamp:
Dec 4, 2009 5:11:01 PM (11 years ago)
Author:
toby
Message:

# on 2003/08/11 19:23:56, toby did:
significant revision for CIFTOOLS

cleanup for Mac OS X
improve error reporting
make variable for max line length (defaults to 80)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/browsecif.tcl

    • Property rcs:date changed from 2002/12/30 17:00:34 to 2003/08/11 19:23:56
    • Property rcs:lines changed from +76 -20 to +100 -41
    • Property rcs:rev changed from 1.5 to 1.6
    r664 r728  
    263263    }
    264264    wm geom $w +$x+$y
     265    update
    265266    wm deiconify $w
    266267
     
    315316    if {$y < 0} {set y 0}
    316317    wm geom .msg +$x+$y
     318    update
    317319    wm deiconify .msg
    318320    global makenew
     
    748750    eval $CIF(tree) delete [$CIF(tree) nodes root]
    749751    catch {unset CIFtreeindex}
    750     pack forget $CIF(AddtoLoopButton) \
    751             $CIF(LoopSpinBox) $CIF(DeleteLoopEntry)
     752    # remove the loop counter frame from window & edit buttons from that frame
     753    grid forget $CIF(LoopBar)
     754    pack forget $CIF(AddtoLoopButton) $CIF(DeleteLoopEntry)
    752755    # delete old contents of frame
    753756    set frame [$CIF(displayFrame) getframe]
     
    759762    $CIF(displayFrame) yview moveto 0
    760763
    761     set num 0
     764    # Bwidget seems to have problems with the name "1", so avoid it
     765    set num 100
    762766    foreach n $blocklist {
    763767        global block$n
     
    776780        # show errors, if any
    777781        foreach name [array names block$n errors] {
    778             $CIF(tree) insert end block$n [incr num] -text $name \
     782            $CIF(tree) insert end block$n [incr num] -text "Parse-errors" \
    779783                    -image [Bitmap::get undo] -data block$n
    780784        }
     
    815819    $CIF(tree) bindImage <1> showCIFbyTreeID
    816820    $CIF(tree) bindText <1>  showCIFbyTreeID
     821    set CIF(tree_lastindex) $num
    817822}
    818823
     
    831836    set pw    [PanedWindow $frame.pw -side top]
    832837    grid $pw -sticky news -column 0 -row 0
     838    set CIF(LoopBar) [frame $frame.f]
     839    #grid $CIF(LoopBar) -sticky es -column 0 -row 1
    833840    set width 900
    834841    if {$width > [winfo screenwidth .]} {set width [winfo screenwidth .]}
    835842    grid columnconfigure $frame 0 -weight 1 -minsize $width
    836     grid rowconfigure $frame 0 -minsize 250 -weight 1
     843    # shrink browser on small screens
     844    set h 250
     845    if {[winfo screenheight .] < 500} {set h 180}
     846    grid rowconfigure $frame 0 -minsize $h -weight 1
    837847
    838848    # create a left hand side pane for the hierarchical tree
     
    843853            -relief flat -borderwidth 0 -width 15 -highlightthickness 0 \
    844854            -redraw 1]
     855    # get the size of the font and adjust the line spacing accordingly
     856    catch {
     857        set font [option get $CIF(tree) font Canvas]
     858        $CIF(tree) configure -deltay [font metrics $font -linespace]
     859    }
    845860    bind $frame <KeyPress-Prior> "$CIF(tree) yview scroll -1 page"
    846861    bind $frame <KeyPress-Next> "$CIF(tree) yview scroll 1 page"
     
    862877    pack $sw -fill both -expand yes -side top
    863878
    864     pack [frame $pane.f] -fill x
    865     set CIF(AddtoLoopButton) [button $pane.f.l -text "Add to loop"]
    866     set CIF(DeleteLoopEntry) [button $pane.f.d -text "Delete loop entry" \
    867             -command DeleteCIFRow]
    868     set CIF(LoopSpinBox) [SpinBox $pane.f.sb -range "1 1 1" \
    869             -label "Loop\nelement #" -labelwidth 10 -width 10]
     879    set CIF(AddtoLoopButton) [button $CIF(LoopBar).l -text "Add to loop"]
     880    set CIF(DeleteLoopEntry) [button $CIF(LoopBar).d \
     881            -text "Delete loop entry" -command DeleteCIFRow]
     882    label $CIF(LoopBar).1 -text "Loop\nelement #"
     883    set CIF(LoopSpinBox) [SpinBox $CIF(LoopBar).2 -range "1 1 1"  -width 5]
     884    pack $CIF(LoopBar).2 $CIF(LoopBar).1 -side right
    870885    set CIF(displayFrame) $sw.lb
    871886    set lb [ScrollableFrame::create $CIF(displayFrame) -width 400]
     
    931946        }
    932947        set CIF(treeSelectedList) $name
     948        # for some reason, BWidget sometimes has problems doing this:
     949        # (but ignore the error)
    933950        catch {$CIF(tree) itemconfigure $name -fill red}
    934951        set CIF(lastShownTreeID) $name
     
    942959    global CIF CIFtreeindex
    943960    set CIF(lastShownItem) [list $pointer $dataname]
    944     pack forget $CIF(AddtoLoopButton) $CIF(LoopSpinBox) $CIF(DeleteLoopEntry)
     961    # remove the loop counter frame from window & edit buttons from that frame
     962    grid forget $CIF(LoopBar)
     963    pack forget $CIF(AddtoLoopButton) $CIF(DeleteLoopEntry)
    945964
    946965    # delete old contents of frame
     
    9881007                $CIF(LoopSpinBox) setvalue @$loopindex
    9891008            }
    990             pack $CIF(LoopSpinBox) -side right
     1009            # show the loop counter frame
     1010            grid $CIF(LoopBar) -sticky es -column 0 -row 1
    9911011            set row 0
    9921012            set i 0
     
    10111031            set frame0 [$frame.0 getframe]
    10121032            grid columnconfig $frame0 2 -weight 1
    1013             if {[set l [llength [set ${block}($dataname)]]] > 100} {
     1033            # maximum number of entries
     1034            set maxcols 100
     1035            catch {
     1036                set maxcols $CIF(maxRows)
     1037            }
     1038            if {[set l [llength [set ${block}($dataname)]]] > $maxcols} {
    10141039                grid [label $frame0.a$i -justify left \
    10151040                        -text "$dataname has $l entries, too many to display by column" \
     
    10341059                -column 0 -row 0 -sticky ew
    10351060        set row 0
    1036         if {$dataname == "errors"} {
    1037             set value [set ${block}($dataname)]
     1061        if {$dataname == "Parse-errors"} {
     1062            set value [set ${block}(errors)]
     1063        } elseif {$dataname == "Validation-errors"} {
     1064            set value [set ${block}(validate)]
    10381065        } else {
    10391066            set mark [set ${block}($dataname)]
     
    12311258# replace a CIF value in with a new value.
    12321259# add newlines as needed to make sure the new value does not
    1233 # exceed 80 characters/line
     1260# exceed CIF(maxlinelength) [defaults to 80] characters/line
    12341261proc ReplaceMarkedText {txt mark value} {
    12351262    $txt configure -state normal
     
    13721399            if {$fp != ""} break
    13731400        }
     1401        if {$fp == ""} return
     1402        fconfigure $fp -translation binary
    13741403        catch {
    13751404            seek $fp $loc
    13761405            set line [read $fp $len]
    13771406            close $fp
    1378             # remove superfluous spaces
    1379             regsub -all {  +} [StripQuotes $line] { } line
     1407            # remove line ends & superfluous spaces
     1408            regsub -all {\n} [StripQuotes $line] { } line
     1409            regsub -all {\r} $line { } line
     1410            regsub -all {  +} $line { } line
     1411#           regsub -all {  +} [StripQuotes $line] { } line
    13801412        }
    13811413    }
     
    13831415}
    13841416
    1385 # validates that a CIF value is valid for a specific dataname
    1386 proc ValidateCIFItem {dataname item} {
     1417proc ValidateCIFName {dataname} {
    13871418    global CIF_dataname_index
    13881419    if {[
    13891420        catch {
    1390             foreach {type range elist esd units category} [lindex $CIF_dataname_index($dataname) 1] {}
     1421            set CIF_dataname_index($dataname)
    13911422        }
    13921423    ]} {return "warning: dataname $dataname not defined"}
     1424}
     1425
     1426# validates that a CIF value is valid for a specific dataname
     1427proc ValidateCIFItem {dataname item} {
     1428    global CIF_dataname_index CIF
     1429    # maximum line length
     1430    set maxlinelength 80
     1431    catch {set maxlinelength $CIF(maxlinelength)}
     1432    if {[catch {
     1433        foreach {type range elist esd units category} [lindex $CIF_dataname_index($dataname) 1] {}
     1434    }]} {return}
    13931435    if {$type == "c"} {
     1436        # string type constant
     1437        set item [StripQuotes $item]
     1438        # is it enumerated?
    13941439        if {$elist != ""} {
    1395             foreach i $elist {
     1440            # check it against the list of values
     1441            foreach i [concat $elist . ?] {
    13961442                if {[string tolower $item] == [string tolower [lindex $i 0]]} {return}
    13971443            }
    1398             return "error: value $item is not an allowed option for $dataname"
     1444            return "error: value \"$item\" is not an allowed option for $dataname"
    13991445        } else {
     1446            # check it for line lengths
    14001447            set l 0
    14011448            set err {}
    14021449            foreach line [split $item \n] {
    14031450                incr l
    1404                 if {[string length $line] > 80} {lappend err $l}
     1451                if {[string length $line] > $maxlinelength} {lappend err $l}
    14051452            }
    14061453            if {$err != ""} {return "error: line(s) $err are too long"}
    1407             return
    1408         }
    1409     }
    1410     if {$type == ""} {return "error: dataname $dataname is not used for CIF data items"}
    1411     # validate numbers
    1412     if {$type == "n"} {
    1413         if {$item == "?" || $item == "."} return
     1454        }
     1455        return
     1456    } elseif {$type == ""} {
     1457        return "error: dataname $dataname is not used for CIF data items"
     1458    } elseif {$type == "n"} {
     1459        # validate numbers
     1460        set unquoted [StripQuotes $item]
     1461        if {$unquoted == "?" || $unquoted == "."} return
     1462        if {$unquoted != $item} {
     1463            set err "\nwarning: number $item is quoted for $dataname"
     1464            set item $unquoted
     1465        } else {
     1466            set err {}
     1467        }
    14141468        set v $item
    14151469        # remove s.u., if allowed & present
    14161470        set vals [ParseSU $item]
    14171471        if {[set v [lindex $vals 0]] == "."} {
    1418             return "error: value $item is not a valid number for $dataname"
     1472            return "error: value \"$item\" is not a valid number for $dataname$err"
    14191473        }
    14201474        if {$esd} {
    14211475            if {[lindex $vals 1] == "."} {
    1422                 return "error: value $item for $dataname has an invalid uncertainty (esd)"
     1476                return "error: value \"$item\" for $dataname has an invalid uncertainty (esd)$err"
    14231477            }
    14241478        } elseif {[llength $vals] == 2} {
    1425             return "error: $item is invalid for $dataname, an uncertainty (esd) is not allowed"
     1479            return "error: \"$item\" is invalid for $dataname, an uncertainty (esd) is not allowed$err"
    14261480        }
    14271481
     
    14341488            foreach {min max} [split $range :] {}
    14351489            if {$integer && int($v) != $v} {
    1436                 return "error: value $item must be an integer for $dataname"
     1490                return "warning: value \"$item\" is expected to be an integer for $dataname$err"
    14371491            }
    14381492            if {$min != ""} {
    14391493                if {$v < $min} {
    1440                     return "error: value $item is too small for $dataname (allowed range $range)"
     1494                    return "error: value \"$item\" is too small for $dataname (allowed range $range)$err"
    14411495                }
    14421496            }
    14431497            if {$max != ""} {
    14441498                if {$v > $max} {
    1445                     return "error: value $item is too big for $dataname(allowed range $range)"
     1499                    return "error: value \"$item\" is too big for $dataname(allowed range $range)$err"
    14461500                }
    14471501            }
    14481502        }
     1503        return $err
    14491504    }
    14501505    return {}
     
    15531608proc CheckChanges {widget "save 0"} {
    15541609    global CIFeditArr CIFinfoArr CIF
     1610    # maximum line length
     1611    set maxlinelength 80
     1612    catch {set maxlinelength $CIF(maxlinelength)}
    15551613
    15561614    set CIF(errormsg) {}
     
    15641622    # if this widget is a label, the info above will not be defined & checks are not needed
    15651623    if {$dataname == ""} {return 0}
    1566     if {$dataname == "errors"} {return 0}
     1624    if {$dataname == "Parse-errors"} {return 0}
     1625    if {$dataname == "Validation-errors"} {return 0}
    15671626
    15681627    global ${block}
     
    15801639            foreach line [set linelist [split $current \n]] {
    15811640                incr l
    1582                 if {[string length $line] > 80} {
     1641                if {[string length $line] > $maxlinelength} {
    15831642                    lappend err $l
    1584                     lappend error "Error: line $l for $dataname is >80 characters"
     1643                    lappend error "Error: line $l for $dataname is >$maxlinelength characters"
    15851644                }
    15861645            }
Note: See TracChangeset for help on using the changeset viewer.