--- capa/capa51/GUITools/common.tcl 1999/10/26 16:47:36 1.2 +++ capa/capa51/GUITools/common.tcl 2000/01/05 21:11:15 1.5 @@ -1135,7 +1135,7 @@ proc getOneStudent { window path idVar n ########################################################### ########################################################### ########################################################### -proc getString { window message } { +proc getString { window message {type "any"}} { global gPrompt set setWin [toplevel $window.getstring] @@ -1146,7 +1146,8 @@ proc getString { window message } { set gPrompt(val) "" - entry $valFrame.val -textvariable gPrompt(val) + entry $valFrame.val -textvariable gPrompt(val) -validate key \ + -validatecommand "limitEntry %W -1 $type %P" pack $valFrame.val message $msgFrame.msg -text $message -aspect 3000 @@ -1427,6 +1428,83 @@ proc pickSections { sectionsToPickFrom { } ########################################################### +# pickSets +########################################################### +########################################################### +########################################################### +proc pickSections { setsToPickFrom mode {title "Select Sets"} {window ""}} { + global gPromptPSets + + set dialog [toplevel $window.pickSets -borderwidth 10] + wm title $dialog "Which Sets" + + set infoFrame [frame $dialog.info ] + set setListFrame [frame $dialog.list -relief groove -borderwidth 5] + set buttonFrame [frame $dialog.buttons -bd 10] + pack $infoFrame $setListFrame $buttonFrame -side top -fill x + + message $infoFrame.msg -text $title -aspect 5000 + pack $infoFrame.msg + + set headerFrame [frame $setListFrame.head ] + set listboxFrame [frame $setListFrame.listboxframe] + pack $headerFrame $listboxFrame -side top + pack configure $headerFrame -anchor w + + message $headerFrame.msg -text "Set #" -aspect 5000 + pack $headerFrame.msg + + set setList [ listbox $listboxFrame.list \ + -yscrollcommand "$listboxFrame.scroll set" \ + -width 30 -height 10 -selectmode $mode ] + scrollbar $listboxFrame.scroll \ + -command "$listboxFrame.list yview" \ + -orient v + pack $setList $listboxFrame.scroll -side left + pack configure $listboxFrame.scroll -fill y + + foreach set $setsToPickFrom { + $setList insert end [format "%3d" $set + } + + button $buttonFrame.yes -text Continue -command {set gPromptPSets(yes) 1} \ + -underline 0 + frame $buttonFrame.spacer -width 10 + button $buttonFrame.selectall -text "SelectAll" -command \ + "$setList selection set 0 end" + button $buttonFrame.cancel -text Cancel -command { set gPromptPSets(yes) 0 } \ + -underline 0 + bind $dialog "set gPromptPSets(yes) 0" + + pack $buttonFrame.yes $buttonFrame.spacer \ + $buttonFrame.selectall $buttonFrame.cancel -side left + + bind $dialog break + + Centre_Dialog $dialog default + update + + focus $dialog + capaRaise $dialog + capaGrab $dialog + vwait gPromptPSets(yes) + capaGrab release $dialog + bind $dialog "" + if {$gPromptPSets(yes)} { + set selectionList [ $setList curselection ] + set setsToDo "" + foreach selection $selectionList { + append setsToDo "[lindex [$setList get $selection] 0] " + } + destroy $dialog + return $setsToDo + } else { + destroy $dialog + return Cancel + } +} + +########################################################### # getSet ########################################################### ########################################################### @@ -1441,7 +1519,7 @@ proc getSet { pid set followupCommand {s if { [array names gGetSet exit] == "" } { set gGetSet(exit) 0 } } if { [catch {set gCapaConfig(getSet.answers_command)}] } {parseCapaConfig getSet} - set command "$gCapaConfig(getSet.answers_command) $pid {} {} $set" + set command "$gCapaConfig(getSet.answers_command) $pid {} 1 $set" foreach var [array names gCapaConfig $num.*] { unset gCapaConfig($var) } set fileId [open "|$command" "r"] fileevent $fileId readable "getSetLine $num $fileId" @@ -1688,11 +1766,12 @@ proc winprintText { num } { ########################################################### proc limitEntry { window max type {newvalue ""}} { after idle "$window config -validate key" - if {[string length $newvalue] > $max } { return 0 } + if {($max != -1) && ([string length $newvalue] > $max)} { return 0 } switch $type { any {} number { if {(![regexp ^\[0-9\]+$ $newvalue])&&($newvalue!="")} { return 0 } } - letter {if {(![regexp ^\[A-Za-z\]+$ $newvalue])&& ($newvalue!="")} { return 0 }} + letter { if {(![regexp ^\[A-Za-z\]+$ $newvalue])&& ($newvalue!="")} { return 0 }} + nospace {if {(![regexp "^\[^ \]+$" $newvalue])&& ($newvalue!="")} { return 0 }} } return 1 }