Changeset 728
- Timestamp:
- Dec 4, 2009 5:11:01 PM (14 years ago)
- 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 263 263 } 264 264 wm geom $w +$x+$y 265 update 265 266 wm deiconify $w 266 267 … … 315 316 if {$y < 0} {set y 0} 316 317 wm geom .msg +$x+$y 318 update 317 319 wm deiconify .msg 318 320 global makenew … … 748 750 eval $CIF(tree) delete [$CIF(tree) nodes root] 749 751 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) 752 755 # delete old contents of frame 753 756 set frame [$CIF(displayFrame) getframe] … … 759 762 $CIF(displayFrame) yview moveto 0 760 763 761 set num 0 764 # Bwidget seems to have problems with the name "1", so avoid it 765 set num 100 762 766 foreach n $blocklist { 763 767 global block$n … … 776 780 # show errors, if any 777 781 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" \ 779 783 -image [Bitmap::get undo] -data block$n 780 784 } … … 815 819 $CIF(tree) bindImage <1> showCIFbyTreeID 816 820 $CIF(tree) bindText <1> showCIFbyTreeID 821 set CIF(tree_lastindex) $num 817 822 } 818 823 … … 831 836 set pw [PanedWindow $frame.pw -side top] 832 837 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 833 840 set width 900 834 841 if {$width > [winfo screenwidth .]} {set width [winfo screenwidth .]} 835 842 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 837 847 838 848 # create a left hand side pane for the hierarchical tree … … 843 853 -relief flat -borderwidth 0 -width 15 -highlightthickness 0 \ 844 854 -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 } 845 860 bind $frame <KeyPress-Prior> "$CIF(tree) yview scroll -1 page" 846 861 bind $frame <KeyPress-Next> "$CIF(tree) yview scroll 1 page" … … 862 877 pack $sw -fill both -expand yes -side top 863 878 864 pack [frame $pane.f] -fill x865 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 870 885 set CIF(displayFrame) $sw.lb 871 886 set lb [ScrollableFrame::create $CIF(displayFrame) -width 400] … … 931 946 } 932 947 set CIF(treeSelectedList) $name 948 # for some reason, BWidget sometimes has problems doing this: 949 # (but ignore the error) 933 950 catch {$CIF(tree) itemconfigure $name -fill red} 934 951 set CIF(lastShownTreeID) $name … … 942 959 global CIF CIFtreeindex 943 960 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) 945 964 946 965 # delete old contents of frame … … 988 1007 $CIF(LoopSpinBox) setvalue @$loopindex 989 1008 } 990 pack $CIF(LoopSpinBox) -side right 1009 # show the loop counter frame 1010 grid $CIF(LoopBar) -sticky es -column 0 -row 1 991 1011 set row 0 992 1012 set i 0 … … 1011 1031 set frame0 [$frame.0 getframe] 1012 1032 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} { 1014 1039 grid [label $frame0.a$i -justify left \ 1015 1040 -text "$dataname has $l entries, too many to display by column" \ … … 1034 1059 -column 0 -row 0 -sticky ew 1035 1060 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)] 1038 1065 } else { 1039 1066 set mark [set ${block}($dataname)] … … 1231 1258 # replace a CIF value in with a new value. 1232 1259 # add newlines as needed to make sure the new value does not 1233 # exceed 80characters/line1260 # exceed CIF(maxlinelength) [defaults to 80] characters/line 1234 1261 proc ReplaceMarkedText {txt mark value} { 1235 1262 $txt configure -state normal … … 1372 1399 if {$fp != ""} break 1373 1400 } 1401 if {$fp == ""} return 1402 fconfigure $fp -translation binary 1374 1403 catch { 1375 1404 seek $fp $loc 1376 1405 set line [read $fp $len] 1377 1406 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 1380 1412 } 1381 1413 } … … 1383 1415 } 1384 1416 1385 # validates that a CIF value is valid for a specific dataname 1386 proc ValidateCIFItem {dataname item} { 1417 proc ValidateCIFName {dataname} { 1387 1418 global CIF_dataname_index 1388 1419 if {[ 1389 1420 catch { 1390 foreach {type range elist esd units category} [lindex $CIF_dataname_index($dataname) 1] {}1421 set CIF_dataname_index($dataname) 1391 1422 } 1392 1423 ]} {return "warning: dataname $dataname not defined"} 1424 } 1425 1426 # validates that a CIF value is valid for a specific dataname 1427 proc 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} 1393 1435 if {$type == "c"} { 1436 # string type constant 1437 set item [StripQuotes $item] 1438 # is it enumerated? 1394 1439 if {$elist != ""} { 1395 foreach i $elist { 1440 # check it against the list of values 1441 foreach i [concat $elist . ?] { 1396 1442 if {[string tolower $item] == [string tolower [lindex $i 0]]} {return} 1397 1443 } 1398 return "error: value $itemis not an allowed option for $dataname"1444 return "error: value \"$item\" is not an allowed option for $dataname" 1399 1445 } else { 1446 # check it for line lengths 1400 1447 set l 0 1401 1448 set err {} 1402 1449 foreach line [split $item \n] { 1403 1450 incr l 1404 if {[string length $line] > 80} {lappend err $l}1451 if {[string length $line] > $maxlinelength} {lappend err $l} 1405 1452 } 1406 1453 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 } 1414 1468 set v $item 1415 1469 # remove s.u., if allowed & present 1416 1470 set vals [ParseSU $item] 1417 1471 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" 1419 1473 } 1420 1474 if {$esd} { 1421 1475 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" 1423 1477 } 1424 1478 } 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" 1426 1480 } 1427 1481 … … 1434 1488 foreach {min max} [split $range :] {} 1435 1489 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" 1437 1491 } 1438 1492 if {$min != ""} { 1439 1493 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" 1441 1495 } 1442 1496 } 1443 1497 if {$max != ""} { 1444 1498 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" 1446 1500 } 1447 1501 } 1448 1502 } 1503 return $err 1449 1504 } 1450 1505 return {} … … 1553 1608 proc CheckChanges {widget "save 0"} { 1554 1609 global CIFeditArr CIFinfoArr CIF 1610 # maximum line length 1611 set maxlinelength 80 1612 catch {set maxlinelength $CIF(maxlinelength)} 1555 1613 1556 1614 set CIF(errormsg) {} … … 1564 1622 # if this widget is a label, the info above will not be defined & checks are not needed 1565 1623 if {$dataname == ""} {return 0} 1566 if {$dataname == "errors"} {return 0} 1624 if {$dataname == "Parse-errors"} {return 0} 1625 if {$dataname == "Validation-errors"} {return 0} 1567 1626 1568 1627 global ${block} … … 1580 1639 foreach line [set linelist [split $current \n]] { 1581 1640 incr l 1582 if {[string length $line] > 80} {1641 if {[string length $line] > $maxlinelength} { 1583 1642 lappend err $l 1584 lappend error "Error: line $l for $dataname is > 80characters"1643 lappend error "Error: line $l for $dataname is >$maxlinelength characters" 1585 1644 } 1586 1645 }
Note: See TracChangeset
for help on using the changeset viewer.