Annotation of capa/capa51/GUITools/grader.tcl, revision 1.1.1.1

1.1       albertel    1: ###########################################################
                      2: # grader.tcl - 
                      3: # Copyright Guy Albertelli II 1996
                      4: ###########################################################
                      5: set gTclVer 2.0
                      6: 
                      7: ###########################################################
                      8: # createControlWindow
                      9: ###########################################################
                     10: # Creates the menu window 
                     11: ###########################################################
                     12: # Arguments: none
                     13: # Returns: nothing
                     14: # Globals: gWindowMenu - set to the name of Menu for the windows
                     15: #                        menu
                     16: ###########################################################
                     17: proc createControlWindow {} {
                     18:     global gWindowMenu gParseMode gParseModeButton gLprCommand gCapaConfig 
                     19: 
                     20:     after 500 { dateUpdate }
                     21:     after 1000 { cleanWindowList }
                     22: 
                     23:     set gCapaConfig(Printer_selected) "0"
                     24:     set gCapaConfig(lprOneSided_command) "lpr "
                     25:     set gCapaConfig(lprTwoSided_command) ""
                     26:     set gCapaConfig(printer_option) ""
                     27:     
                     28:     wm withdraw .
                     29: 
                     30:     set menuFrame [menu .main -tearoff 0 -type tearoff -font 8x13bold \
                     31: 	    -disabledforeground grey85 ]
                     32: 
                     33:     wm title $menuFrame "Grader"
                     34: 
                     35:     $menuFrame post 0 0
                     36: 
                     37:     wm geometry $menuFrame "+0+20"
                     38:     $menuFrame add command -label "Grader" -foreground grey85 -background \
                     39: 	    black -state disabled 
                     40:     $menuFrame add command -label "Info..." -command { createInfoWindow }
                     41:     $menuFrame add cascade -label "File" -menu $menuFrame.file
                     42:     $menuFrame add command -label "Excuse Problem" -command { \
                     43: 	    createExcuseWindow }
                     44:     $menuFrame add cascade -label "Windows" -menu $menuFrame.windows
                     45:     $menuFrame add cascade -label "Print" -menu $menuFrame.print
                     46:     $menuFrame add command -label "Remap..." -command { createRemapWindow }
                     47:     $menuFrame add command -label "Quit" -command { quit }
                     48: 
                     49:     set file  [menu $menuFrame.file -tearoff 1 -font 8x13bold ]
                     50:     set windows [menu $menuFrame.windows -tearoff 1 -font 8x13bold]
                     51:     set print    [menu $menuFrame.print -tearoff 1  -font 8x13bold]
                     52:     set gWindowMenu $windows
                     53:     
                     54:     $file add command -label "Specify Class" -command { specifyClass }
                     55:     $file add command -label "Create Class Report" -command { \
                     56: 	    createSummaryWindow }
                     57:     $file add command -label "Grade Subjective" -command { gradeSubjective }
                     58: 
                     59:     $print add command -label "Set Summary" -command { printSetSummary }
                     60:     $print add command -label "Term Summary" -command { printTermSummary }
                     61: 
                     62:     set gParseMode 2
                     63:     set gParseModeButton "Both, Questions Answers"    
                     64: }
                     65: 
                     66: ###########################################################
                     67: # createInfoWindow
                     68: ###########################################################
                     69: # creates the Information window
                     70: ###########################################################
                     71: # Arguments: None
                     72: # Returns: Nothing
                     73: # Globals: gDate - the variable containg the current date 
                     74: #          gWindowMenu - used to register the new window in the
                     75: #                        windows menu
                     76: #          gVer - Stores the current version of Grader (set in 
                     77: #                 C init code
                     78: ###########################################################
                     79: proc createInfoWindow {} {
                     80:     global gDate gWindowMenu gVer gTclVer gCmd gCompileDate
                     81: 
                     82:     if { [winfo exists .about] } {
                     83: 	capaRaise .about
                     84: 	return 
                     85:     }
                     86: 
                     87:     set about [toplevel .about]
                     88: 
                     89:     $gWindowMenu add command -label "About" -command "capaRaise $about"
                     90: 
                     91:     wm title $about "About" 
                     92:     
                     93:     label $about.l1 -font 12x24 -text "Grader $gVer" -pady 20
                     94:     label $about.l4 -font 8x13 -text "Grader.tcl Version $gTclVer" -pady 20
                     95:     label $about.l6  -font 8x13 -text "$gCompileDate" 
                     96:     message $about.l2 -font 8x13 -text "Code by: Y. Tsai, G. Albertelli II Copyright Michigan State University Board of Trustees, 1992-1999, No Unauthorized Commercial Use" \
                     97:        -pady 20 -aspect 300
                     98:     label $about.l3 -font 8x13 -textvariable gDate 
                     99:     label $about.l5  -font 8x13 -textvariable gCmd
                    100: 
                    101:     button $about.close -text "Close" -command "destroy $about
                    102:                                                 removeWindowEntry About"
                    103:     
                    104:     pack $about.l1 $about.l4 $about.l6 $about.l2 $about.l3 $about.l5 \
                    105: 	    $about.close -side top 
                    106: 
                    107:     Centre_Dialog $about default
                    108: }
                    109: 
                    110: ###########################################################
                    111: # quit
                    112: ###########################################################
                    113: # called when the quit option is selected on the menu, unmaps
                    114: # all keys.
                    115: ###########################################################
                    116: # Arguments: None
                    117: # Returns: Nothing
                    118: # Globals: None
                    119: ###########################################################
                    120: proc quit {} {
                    121:     if { [makeSure "Are you sure you wish to quit?"] == "Cancel" } {
                    122: 	return 
                    123:     }
                    124:     
                    125:     if { [winfo exists .gradesubjective] } { subjDone }
                    126:     catch { rm -f [file join / tmp gkc[pid]]}
                    127:     catch { rm -f [file join / tmp g[pid]]}
                    128: 
                    129:     unmapAllKeys
                    130:     exit
                    131: }
                    132: 
                    133: ###########################################################
                    134: # createExcuseWindow
                    135: ###########################################################
                    136: # runs capa_excuse for a set and section, creates a window to
                    137: # get the information from, requires that the user has already
                    138: # selected a class.
                    139: ###########################################################
                    140: # Arguments: None
                    141: # Returns: Nothing
                    142: # Globals: gPrompt - used to detect when to take the modal dialog away
                    143: #          gSetLoad - global var containg the current set being graded
                    144: #          gSectionLoad - global var containg the current section
                    145: #                         being graded
                    146: #          gExcuseSet - Contains the number of the set to be excused
                    147: #          gExcuseProblem - number of the problem to be excused
                    148: #          gExcuseSection - Section number to excuse the problem for
                    149: #          gExcuseWho - contains either : Section or All, and is
                    150: #                       whether to excuse an entire class or a specific
                    151: #                       section
                    152: ###########################################################
                    153: proc createExcuseWindow { } {
                    154:     global gPrompt gSetLoad gSectionLoad gExcuseSet gExcuseProblem \
                    155: 	    gExcuseSection gExcuseWho
                    156:     
                    157:     if {![winfo exists .grader]} {
                    158: 	displayError "You must first specify a class"
                    159: 	return 
                    160:     }
                    161: 
                    162:     if { $gSetLoad == "" } {
                    163: 	set gExcuseSet 1
                    164:     } else {
                    165: 	set gExcuseSet $gSetLoad
                    166:     }
                    167: 
                    168:     if { $gSectionLoad == "" } {
                    169: 	set gExcuseSection 1
                    170:     } else {
                    171: 	set gExcuseSection $gSectionLoad
                    172:     }
                    173: 
                    174:     set excuse [toplevel .excuse -borderwidth 10]
                    175: 
                    176:     set whichFrame [frame $excuse.whichFrame -borderwidth 4 -relief groove]
                    177:     set whoFrame [frame $excuse.whoFrame -borderwidth 10]
                    178:     set buttonFrame [frame $excuse.buttonFrame]
                    179:     pack $whichFrame $whoFrame $buttonFrame -side top -anchor w
                    180: 
                    181:     set setFrame [frame $whichFrame.setFrame]
                    182:     set problemFrame [frame $whichFrame.problemFrame]
                    183:     pack $setFrame $problemFrame -side top -anchor e
                    184: 
                    185:     label $setFrame.label -text Set
                    186:     entry $setFrame.entry -textvariable gExcuseSet -width 3
                    187:     pack $setFrame.label $setFrame.entry -side left
                    188: 
                    189:     set gExcuseProblem 1
                    190:     label $problemFrame.label -text "Problem Number"
                    191:     entry $problemFrame.entry -textvariable gExcuseProblem -width 3
                    192:     pack $problemFrame.label $problemFrame.entry -side left
                    193: 
                    194:     set sectionFrame [frame $whoFrame.sectionFrame]
                    195:     set allFrame [frame $whoFrame.allFrame]
                    196:     pack $sectionFrame $allFrame -side top -anchor w
                    197: 
                    198:     set gExcuseWho Section
                    199:     radiobutton $sectionFrame.radio -text "For students in section:" \
                    200: 	    -variable gExcuseWho -value Section    
                    201:     entry $sectionFrame.entry -textvariable gExcuseSection -width 3
                    202:     pack $sectionFrame.radio $sectionFrame.entry -side left
                    203: 
                    204:     radiobutton $allFrame.radio -text "For all students in the class." \
                    205: 	    -variable gExcuseWho -value All
                    206:     pack $allFrame.radio
                    207: 
                    208:     set gPrompt(result) ""
                    209:     button $buttonFrame.excuse -text Excuse -command { set gPrompt(yes) 1 } \
                    210: 	    -underline 0
                    211:     button $buttonFrame.cancel -text Cancel -command { set gPrompt(yes) 0 } \
                    212: 	    -underline 0
                    213:     pack $buttonFrame.excuse $buttonFrame.cancel -side left
                    214:     
                    215:     bind $excuse <Alt-Key> break
                    216:     
                    217:     Centre_Dialog $excuse default
                    218:     update
                    219:     
                    220:     focus $excuse
                    221:     raise $excuse
                    222:     capaGrab $excuse
                    223:     vwait gPrompt(yes)
                    224:     capaGrab release $excuse
                    225:     destroy $excuse
                    226:     if {$gPrompt(yes)} {
                    227: 	switch $gExcuseWho {
                    228: 	    All
                    229: 	    {
                    230: 		capaExcuse $gExcuseSet $gExcuseProblem 0
                    231: 	    }
                    232: 	    Section
                    233: 	    {
                    234: 		capaExcuse $gExcuseSet $gExcuseProblem $gExcuseSection
                    235: 	    }
                    236: 	}
                    237: 	loadScores
                    238:     } else {
                    239: 	return
                    240:     }
                    241: }    
                    242: 
                    243: ###########################################################
                    244: # createSummaryWindow
                    245: ###########################################################
                    246: # creates a dialog to craft a summary report with
                    247: ###########################################################
                    248: # Arguments: None
                    249: # Returns: Nothing
                    250: # Globals: gWindowMenu - name of the window menu widget, used to
                    251: #                        register the dialog box
                    252: #          gSetLoad - current set being graded
                    253: #          gSectionLoad - current section being graded
                    254: #          gSummaryFile - filename to save report to
                    255: #          gSummary - array with fields
                    256: #              (section) - section to create the summary for
                    257: #              (set) - set to creat the summary for
                    258: #              (who) - two possible values: section (create a section
                    259: #                       summary), all (create a class summary)
                    260: #              (which) - 2 possible values: specific (summary report
                    261: #                        for a specific set), upto (summary report upto
                    262: #                        and including a specific set)
                    263: #              (first) - first field to sort by, four values:name
                    264: #                        (student name), number (student number), 
                    265: #                        section (section), grade (grade on the sets)
                    266: #              (second) - second field to sort by, same four values as
                    267: #                         above
                    268: #              (filename) - either default, grader picks it or specified,
                    269: #                           user specified a name to be found in gSummaryFile
                    270: ###########################################################
                    271: proc createSummaryWindow {} {
                    272:     global gWindowMenu gSetLoad gSectionLoad gSummary gSummaryFile
                    273:     
                    274:     if { [winfo exists .summary] } {
                    275: 	raise .summary
                    276: 	return
                    277:     }
                    278: 
                    279:     if {![winfo exists .grader]} {
                    280: 	displayError "You must first specify a class"
                    281: 	return 
                    282:     }
                    283: 
                    284:     if { $gSetLoad == "" } {
                    285: 	set gSummary(set) 1
                    286:     } else {
                    287: 	set gSummary(set) $gSetLoad
                    288:     }
                    289: 
                    290:     if { $gSectionLoad == "" } {
                    291: 	set gSummary(section) 1
                    292:     } else {
                    293: 	set gSummary(section) $gSectionLoad
                    294:     }
                    295: 
                    296:     set summary [toplevel .summary]
                    297:     $gWindowMenu add command -label "Summary" -command "capaRaise $summary"
                    298: 
                    299:     set whoFrame [frame $summary.whoFrame -borderwidth 4 -relief groove]
                    300:     set whichFrame [frame $summary.whichFrame -borderwidth 4 -relief groove]
                    301:     set sortFrame [frame $summary.sortFrame]
                    302:     set file2Frame [frame $summary.file2Frame]
                    303:     set buttonFrame [frame $summary.buttonFrame]
                    304:     pack $whoFrame $whichFrame $sortFrame $file2Frame $buttonFrame -side top
                    305:     pack configure $whoFrame $whichFrame -padx 10 -pady 10
                    306: 
                    307:     set sectionFrame [frame $whoFrame.section]
                    308:     set allFrame [frame $whoFrame.all]
                    309:     pack $sectionFrame $allFrame -side top
                    310: 
                    311:     set gSummary(who) section
                    312: 
                    313:     radiobutton $sectionFrame.section -text \
                    314: 	    "For students in default section:" -variable gSummary(who) \
                    315: 	    -value section 
                    316:     entry $sectionFrame.entry -textvariable gSummary(section) -width 3 
                    317:     pack $sectionFrame.section $sectionFrame.entry -side left
                    318: 
                    319:     radiobutton $allFrame.all -text "For all students in the class" \
                    320: 	    -variable gSummary(who) -value all 
                    321:     pack $allFrame.all
                    322: 
                    323:     set sectionFrame [frame $whichFrame.section]
                    324:     set allFrame [frame $whichFrame.all]
                    325:     pack $sectionFrame $allFrame -side top
                    326: 
                    327:     set gSummary(which) specific
                    328: 
                    329:     radiobutton $sectionFrame.section -text "For set:" \
                    330: 	    -variable gSummary(which) -value specific 
                    331:     entry $sectionFrame.entry -textvariable gSummary(set) -width 3 
                    332:     pack $sectionFrame.section $sectionFrame.entry -side left
                    333: 
                    334:     radiobutton $allFrame.all -text "For all sets up to:" -variable \
                    335: 	    gSummary(which) -value upto 
                    336:     entry $allFrame.entry -textvariable gSummary(set) -width 3 
                    337:     pack $allFrame.all $allFrame.entry -side left
                    338: 
                    339:     set firstFrame [frame $sortFrame.firstFrame -borderwidth 4 -relief groove]
                    340:     set secondFrame [frame $sortFrame.secondFrame -borderwidth 4 \
                    341: 	    -relief groove]
                    342:     pack $firstFrame $secondFrame -side left
                    343: 
                    344:     set gSummary(first) name
                    345: 
                    346:     label $firstFrame.label -text "Sorting Order - Primary"
                    347:     radiobutton $firstFrame.name -text "Student Name" -variable \
                    348: 	    gSummary(first) -value name
                    349:     radiobutton $firstFrame.number -text "Student Number" -variable \
                    350: 	    gSummary(first) -value number
                    351:     radiobutton $firstFrame.section -text "Section" -variable \
                    352: 	    gSummary(first) -value section
                    353:     radiobutton $firstFrame.grade -text "Grade" -variable gSummary(first) \
                    354: 	    -value grade
                    355:     pack $firstFrame.label $firstFrame.name $firstFrame.number \
                    356: 	    $firstFrame.section $firstFrame.grade -side top -anchor w
                    357: 
                    358:     set gSummary(second) number
                    359: 
                    360:     label $secondFrame.label -text "Sorting Order - Secondary"
                    361:     radiobutton $secondFrame.name -text "Student Name" -variable \
                    362: 	    gSummary(second) -value name
                    363:     radiobutton $secondFrame.number -text "Student Number" -variable \
                    364: 	    gSummary(second) -value number
                    365:     radiobutton $secondFrame.section -text "Section" -variable \
                    366: 	    gSummary(second) -value section
                    367:     radiobutton $secondFrame.grade -text "Grade" -variable gSummary(second) \
                    368: 	    -value grade
                    369:     pack $secondFrame.label $secondFrame.name $secondFrame.number \
                    370: 	    $secondFrame.section $secondFrame.grade -side top -anchor w
                    371: 
                    372:     set defaultFrame [frame $file2Frame.defaultFrame]
                    373:     set fileFrame [frame $file2Frame.fileFrame]
                    374:     pack $defaultFrame $fileFrame -side top
                    375: 
                    376:     if {[catch {set gSummary(filename)}]} { set gSummary(filename) default }
                    377: 
                    378:     radiobutton $defaultFrame.default -text "Grader Chooses File Name" \
                    379: 	-variable gSummary(filename) -value default
                    380:     pack $defaultFrame.default
                    381: 
                    382:     radiobutton $fileFrame.label -text "Specified Output File:" \
                    383: 	-variable gSummary(filename) -value specified
                    384:     set entryFrame [frame $fileFrame.entryFrame]
                    385:     button $fileFrame.select -text "Select File" \
                    386: 	    -command "selectOutputFile"
                    387:     pack $fileFrame.label $entryFrame $fileFrame.select -side left
                    388:     entry $entryFrame.entry -textvariable gSummaryFile \
                    389: 	-xscrollcommand "$entryFrame.scroll set"
                    390:     scrollbar $entryFrame.scroll -orient h -command \
                    391: 	    "$entryFrame.entry xview"
                    392:     pack $entryFrame.entry $entryFrame.scroll
                    393:     pack configure $entryFrame.scroll -fill x
                    394: 
                    395:     button $buttonFrame.create -text "Create" -command \
                    396: 	    "removeWindowEntry Summary
                    397:              destroy $summary
                    398:              createSummaryReport"
                    399:     button $buttonFrame.cancel -text "Cancel" -command \
                    400: 	    "removeWindowEntry Summary
                    401:              destroy $summary"
                    402:     pack $buttonFrame.create $buttonFrame.cancel -side left
                    403: 
                    404:     Centre_Dialog $summary default
                    405: }
                    406: 
                    407: ###########################################################
                    408: # selectOutputFile
                    409: ###########################################################
                    410: ###########################################################
                    411: ###########################################################
                    412: proc selectOutputFile {} {
                    413:     global gSummaryFile gSummary
                    414:     set gSummary(filename) specified
                    415:     if { "" != [ set temp [tk_getSaveFile] ] } {set gSummaryFile $temp}
                    416: }    
                    417: 
                    418: ###########################################################
                    419: # createSummaryReport
                    420: ###########################################################
                    421: # creates the summary report
                    422: ###########################################################
                    423: # Argumnets: None
                    424: # Returns: Nothing
                    425: # Globals: gSummary - the report generation information is in here
                    426: #          gClassDir - the directory the class is in
                    427: # Files: gClassDir/ClassSet.rpt - summary report created if for the
                    428: #                                 entire class (created)
                    429: #       gClassDir/SecSet.rpt - summarry report created if for only a
                    430: #                              section (created)
                    431: ###########################################################
                    432: proc createSummaryReport {} {
                    433:     global gSummary gClassDir gUniqueNumber gSummaryFile
                    434: 
                    435:     displayStatus "Opening File" both
                    436: 
                    437:     switch $gSummary(who) {
                    438: 	all
                    439: 	{
                    440: 	    set file [file join $gClassDir ClassSet$gSummary(set).rpt ]
                    441: 	}
                    442: 	section
                    443: 	{
                    444: 	    set file [file join $gClassDir \
                    445: 		    Sec$gSummary(section)Set$gSummary(set).rpt ]
                    446: 	}
                    447: 	default
                    448: 	{
                    449: 	    displayError "An error has occured while creating a summary \
                    450: 		    report $gSummary(section)"
                    451: 	    return
                    452: 	}
                    453:     }
                    454: 
                    455:     if { $gSummary(filename) == "specified" } { set file $gSummaryFile }
                    456:     if { $file == "" } { 
                    457: 	removeStatus
                    458: 	displayError "Must specify a valid filename"
                    459: 	return
                    460:     }
                    461:     updateStatusMessage "Creating Summary"
                    462: 
                    463:     set error [ catch {createSummary $file} ]
                    464: 
                    465:     removeStatus
                    466: 
                    467:     if {!$error && "Yes" == [makeSure "Created summary file $file, would you like to see it?"]} {
                    468: 	set fileId [open $file r]
                    469: 	set num [incr gUniqueNumber] 
                    470: 	set num2 [incr gUniqueNumber] 
                    471: 	winputs $num [read $fileId]
                    472: 	winoutput $num2 $num {}
                    473:     }
                    474: }
                    475: 
                    476: ###########################################################
                    477: # specifyClass
                    478: ###########################################################
                    479: # runs tk_getOpenFile and creates the class window if a directory is chosen
                    480: ###########################################################
                    481: # Arguments: None
                    482: # Returns: Nothing
                    483: # Globals: gClassDir - remembers the directory the class is in
                    484: ###########################################################
                    485: proc specifyClass {} {
                    486:     global gClassDir
                    487: 
                    488:     if { [winfo exists .grader] } { return }
                    489:     set var [tk_getOpenFile -title "Please select a capa.config file" -filetypes \
                    490: 		 { { {Capa Config} {capa.config} } }]
                    491: 
                    492:     if { $var != "" } {
                    493: 	set gClassDir [file dirname $var]
                    494: 	cd $gClassDir
                    495:     } else {
                    496: 	return
                    497:     }
                    498:     
                    499:     createClassWindow
                    500: }
                    501: 
                    502: ###########################################################
                    503: # changeClass
                    504: ###########################################################
                    505: # called when the change class button is pressed, if another class
                    506: # is chosen the class window is updated
                    507: ###########################################################
                    508: # Arguments: None
                    509: # Returns: Nothing
                    510: # Globals: gClassDir - remembers the directory the class is in
                    511: #          gClass - just the name of the directory, and therefore 
                    512: #                   the class
                    513: #          gLoaded - reset to zero since we are unloading the class
                    514: ###########################################################
                    515: proc changeClass {} {
                    516:     global gClassDir gClass gLoaded
                    517: 
                    518:     set var [tk_getOpenFile -title "Please select a capa.config file" -filetypes \
                    519: 		 { { {Capa Config} {capa.config} } }]    
                    520: 
                    521:     if { $var != "" } {
                    522: 	removeWindowEntry $gClassDir
                    523: 	set gClassDir [file dirname $var]
                    524: 	cd $gClassDir
                    525: 	set gClass  [file tail $gClassDir]
                    526:     } else {
                    527: 	return
                    528:     }
                    529:     
                    530:     set gLoaded 0
                    531:     clearClassWindow
                    532:     parseCapaConfig
                    533: }
                    534: 
                    535: ###########################################################
                    536: # createClassWindow
                    537: ###########################################################
                    538: # creates the rather complicated class window
                    539: ###########################################################
                    540: # Arguments: None
                    541: # Returns: Nothing
                    542: # Globals: gClassDir - remembers the directory the class is in
                    543: #          gWindowMenu - the name of the window menu widget
                    544: #          gOpenDate - the label linked var the date the set opens is in
                    545: #          gOpenTime - the label linked var the time the set opens is in
                    546: #          gDueDate - the label linked var the due date for the set is in
                    547: #          gDueTime - the label linked var the due time for the set is in
                    548: #          gAnswerDate - the label linked var the date the set answer
                    549: #                        open date is in
                    550: #          gAnswerTime - the label linked var the time the set answer
                    551: #                        open time is in
                    552: #          gSectionLoad - the current section being graded
                    553: #          gSetLoad - the current set being graded
                    554: #          gFindNumber - linked var that stores the string to search
                    555: #                        through student numbers for
                    556: #          gFindName - linked var that stores the string to search
                    557: #                      through student names for
                    558: #          gButtonFrame - stores the widget name of the button frame, so 
                    559: #                         the buttons' state can be changed elsewhere
                    560: #          gNameFrame - stores the widget name of the name entry frame, so 
                    561: #                       the entry widget's state can be changed elsewhere
                    562: #          gNumberFrame - stores the widget name of the number entry 
                    563: #                         frame, so the entry widget' state can be 
                    564: #                         changed elsewhere
                    565: #          gStudentList - the widget name of the listbox containing the 
                    566: #                         list of students
                    567: #          gClass - the name of the class currently being graded
                    568: #          gLoaded - keeps track of whether a class has been loaded yet
                    569: #                    set to zero here
                    570: ###########################################################
                    571: proc createClassWindow {} {
                    572:     global gClassDir gWindowMenu gOpenDate gOpenTime gDueDate gDueTime \
                    573: 	    gAnswerDate gAnswerTime gSectionLoad gSetLoad gFindNumber \
                    574: 	    gFindName gButtonFrame gNameFrame gNumberFrame gStudentList \
                    575: 	    gClass gLoaded
                    576: 
                    577:     set gLoaded 0
                    578:     
                    579:     set grader [toplevel .grader]
                    580:     $gWindowMenu add command -label "$gClassDir" -command "capaRaise $grader"
                    581: 
                    582:     set labelFrame [frame $grader.labelFrame]
                    583:     set dataFrame [frame $grader.dataFrame]
                    584:     set columnFrame [frame $grader.columnFrame]
                    585:     set infoFrame [frame $grader.infoFrame]
                    586:     pack $labelFrame $dataFrame $columnFrame $infoFrame -side top -anchor w
                    587:     pack configure $infoFrame -expand 1 -fill both
                    588: 
                    589:     set gClass [file tail $gClassDir] 
                    590:     label $labelFrame.label -background black -foreground grey85 \
                    591: 	    -textvariable gClass -width 51
                    592:     button $labelFrame.button -text "Change Class" -command { changeClass }
                    593:     pack $labelFrame.label $labelFrame.button -side left
                    594: 
                    595:     set dateFrame [frame $dataFrame.date -relief sunken -borderwidth 2]
                    596:     set actionsFrame [frame $dataFrame.actions ]
                    597:     pack $dateFrame $actionsFrame -side left
                    598: 
                    599:     set openDateFrame [frame $dateFrame.openDate]
                    600:     set openTimeFrame [frame $dateFrame.openTime]
                    601:     set dueDateFrame [frame $dateFrame.dueDate]
                    602:     set dueTimeFrame [frame $dateFrame.dueTime]
                    603:     set answerDateFrame [frame $dateFrame.answerDate]
                    604:     set answerTimeFrame [frame $dateFrame.answerTime]
                    605:     pack $openDateFrame $openTimeFrame $dueDateFrame $dueTimeFrame \
                    606: 	    $answerDateFrame $answerTimeFrame -side top
                    607: 
                    608:     label $openDateFrame.text -text "Open Date:" -width 13
                    609:     label $openDateFrame.date -textvariable gOpenDate -width 10 -relief sunken \
                    610: 	    -background white 
                    611:     pack $openDateFrame.text $openDateFrame.date -side left
                    612: 
                    613:     label $openTimeFrame.text -text "Open Time:" -width 13
                    614:     label $openTimeFrame.time -textvariable gOpenTime -width 10 -relief sunken \
                    615: 	    -background white 
                    616:     pack $openTimeFrame.text $openTimeFrame.time -side left
                    617: 
                    618:     label $dueDateFrame.text -text "Due Date:" -width 13
                    619:     label $dueDateFrame.date -textvariable gDueDate -width 10 -relief sunken \
                    620: 	    -background white 
                    621:     pack $dueDateFrame.text $dueDateFrame.date -side left
                    622: 
                    623:     label $dueTimeFrame.text -text "Due Time:" -width 13
                    624:     label $dueTimeFrame.time -textvariable gDueTime -width 10 -relief sunken \
                    625: 	    -background white 
                    626:     pack $dueTimeFrame.text $dueTimeFrame.time -side left
                    627: 
                    628:     label $answerDateFrame.text -text "Answer Date:" -width 13
                    629:     label $answerDateFrame.date -textvariable gAnswerDate -width 10 -relief \
                    630: 	    sunken -background white 
                    631:     pack $answerDateFrame.text $answerDateFrame.date -side left
                    632: 
                    633:     label $answerTimeFrame.text -text "Answer Time:" -width 13
                    634:     label $answerTimeFrame.time -textvariable gAnswerTime -width 10 -relief \
                    635: 	    sunken -background white 
                    636:     pack $answerTimeFrame.text $answerTimeFrame.time -side left
                    637: 
                    638:     set loadFrame [frame $actionsFrame.load]
                    639:     set findFrame [frame $actionsFrame.find]
                    640:     set buttonFrame [frame $actionsFrame.buttons]
                    641:     set gButtonFrame $buttonFrame
                    642:     pack $loadFrame $findFrame $buttonFrame -side top
                    643:     pack configure $loadFrame -anchor e
                    644: 
                    645:     set sectionFrame [frame $loadFrame.section]
                    646:     set setFrame [frame $loadFrame.set]
                    647:     pack $sectionFrame $setFrame -side top -anchor w
                    648: 
                    649:     label $sectionFrame.label -text "    Section:"
                    650:     entry $sectionFrame.entry -textvariable gSectionLoad -width 3
                    651:     pack $sectionFrame.label $sectionFrame.entry -side left
                    652: 
                    653:     label $setFrame.label -text     "Problem Set:"
                    654:     entry $setFrame.entry -textvariable gSetLoad -width 3
                    655:     bind $setFrame.entry <KeyPress-Return> loadScores
                    656:     button $setFrame.button -text "Load Scores" -command loadScores
                    657:     pack $setFrame.label $setFrame.entry $setFrame.button -side left
                    658:     
                    659:     set nameFrame [frame $findFrame.name]
                    660:     set gNameFrame $nameFrame
                    661:     set numberFrame [frame $findFrame.number]
                    662:     set gNumberFrame $numberFrame
                    663:     pack $nameFrame $numberFrame -side top
                    664: 
                    665:     entry $nameFrame.name -textvariable gFindName
                    666:     button $nameFrame.button -text   "Find By Name         " -command findByName
                    667:     bind $nameFrame.name <KeyPress-Return> findByName
                    668:     pack $nameFrame.name $nameFrame.button -side left
                    669: 
                    670:     entry $numberFrame.name -textvariable gFindNumber
                    671:     button $numberFrame.button -text "Find By StudentNumber" -command findByNumber
                    672:     bind $numberFrame.name <KeyPress-Return> findByNumber
                    673:     pack $numberFrame.name $numberFrame.button -side left
                    674: 
                    675:     button $buttonFrame.report -text "Student Report" -command studentReport \
                    676: 	    -state disabled
                    677:     button $buttonFrame.grading -text "Grading" -command createGradingWindow \
                    678: 	    -state disabled
                    679:     pack $buttonFrame.report $buttonFrame.grading  -side left
                    680: 
                    681:     label $columnFrame.space -text "  "
                    682:     label $columnFrame.name -text "Student Name" -width 30
                    683:     label $columnFrame.number -text "Number" -width 11
                    684:     message $columnFrame.score -text "Current Set Score" -aspect 250
                    685:     message $columnFrame.pin -text "Current Pin" -aspect 200
                    686:     pack $columnFrame.space $columnFrame.name $columnFrame.number \
                    687: 	    $columnFrame.score $columnFrame.pin -side left
                    688: 
                    689:     scrollbar $infoFrame.scroll -orient vertical -command \
                    690: 	    "$infoFrame.listbox yview"
                    691:     set gStudentList [listbox $infoFrame.listbox -yscrollcommand \
                    692: 	    "$infoFrame.scroll set" -height 30]
                    693:     pack $infoFrame.scroll $infoFrame.listbox -side left
                    694:     pack configure $infoFrame.scroll -expand false -fill y
                    695:     pack configure $infoFrame.listbox -expand true -fill both
                    696: 
                    697:     Centre_Dialog $grader default
                    698:     parseCapaConfig
                    699: }
                    700: 
                    701: ###########################################################
                    702: # clearClassWindow
                    703: ###########################################################
                    704: # empties the class window of all data
                    705: ###########################################################
                    706: # Arguments: none
                    707: # Returns: Nothing
                    708: # Globals: gClassDir - remembers the directory the class is in
                    709: #          gWindowMenu - the name of the window menu widget
                    710: #          gOpenDate - the label linked var the date the set opens is in
                    711: #          gOpenTime - the label linked var the time the set opens is in
                    712: #          gDueDate - the label linked var the due date for the set is in
                    713: #          gDueTime - the label linked var the due time for the set is in
                    714: #          gAnswerDate - the label linked var the date the set answer
                    715: #                        open date is in
                    716: #          gAnswerTime - the label linked var the time the set answer
                    717: #                        open time is in
                    718: #          gSectionLoad - the current section being graded
                    719: #          gSetLoad - the current set being graded
                    720: #          gStudentList - the widget name of the listbox containing the 
                    721: #                         list of students
                    722: #          gClass - the name of the class currently being graded
                    723: ###########################################################
                    724: proc clearClassWindow {} {
                    725:     global gWindowMenu gOpenDate gOpenTime gDueDate gDueTime gAnswerDate \
                    726: 	    gAnswerTime gStudentList gSectionLoad gSetLoad gClassDir
                    727: 
                    728:     $gWindowMenu add command -label "$gClassDir" -command "capaRaise .grader"
                    729: 
                    730:     set gOpenDate ""
                    731:     set gOpenTime ""
                    732:     set gDueDate ""
                    733:     set gDueTime ""
                    734:     set gAnswerDate ""
                    735:     set gAnswerTime ""
                    736:     set gSectionLoad ""
                    737:     set gSetLoad ""
                    738: 
                    739:     $gStudentList delete 0 end
                    740: }
                    741: 
                    742: ###########################################################
                    743: # loadScores
                    744: ###########################################################
                    745: # load in a new set of scores
                    746: ###########################################################
                    747: # Arguments: None
                    748: # Returns: Nothing
                    749: # Globals: gSectionLoad - the current section being graded
                    750: #          gSetLoad - the current set being graded
                    751: #          gButtonFrame - stores the widget name of the button frame, so 
                    752: #                         the buttons' state can be changed elsewhere
                    753: #          gNameFrame - stores the widget name of the name entry frame, so 
                    754: #                       the entry widget's state can be changed elsewhere
                    755: #          gNumberFrame - stores the widget name of the number entry 
                    756: #                         frame, so the entry widget' state can be 
                    757: #                         changed elsewhere
                    758: #          gStudentList - the widget name of the listbox containing the 
                    759: #                         list of students
                    760: #          gLoaded - 1 if a section has been loaded
                    761: ###########################################################
                    762: proc loadScores {} {
                    763:     global gNumberFrame gNameFrame gButtonFrame gSectionLoad gSetLoad \
                    764: 	    gStudentList gLoaded
                    765: 
                    766:     $gStudentList delete 0 end
                    767: 
                    768:     if { $gSectionLoad == "" } {
                    769: 	displayError "The Section field must be completed before \
                    770: 		continuing."
                    771: 	return
                    772:     } elseif { $gSetLoad == "" } {
                    773: 	displayError "The Set field must be completed before \
                    774: 		continuing."
                    775: 	return
                    776:     }    
                    777: 
                    778:     set result [getHeader]
                    779:     switch -- $result {
                    780: 	0 { displayError "The Set and Section selected do not appear to exist"; return }
                    781: 	-1 { #displayMessage "No date information is available for this set" }
                    782: 	1 { #break } 
                    783:     }
                    784: 
                    785:     $gButtonFrame.report configure -state normal
                    786:     $gButtonFrame.grading configure -state normal
                    787: 
                    788: ##    $gButtonFrame.log configure -state normal
                    789: 
                    790:     getStudents gStudentList
                    791: 
                    792:     set gLoaded 1
                    793: }
                    794: 
                    795: ###########################################################
                    796: # findByName
                    797: ###########################################################
                    798: # preforms a search for a student by name, findSection returns
                    799: # the section the student is in, then the correct element in the
                    800: # Student ListBox is highlighted.
                    801: ###########################################################
                    802: # Arguments: None
                    803: # Returns: Nothing
                    804: # Globals: gSectionLoad - the current section being graded
                    805: #          gFindName - linked var that stores the string to search
                    806: #                      through student names for
                    807: #          gStudentList - the widget name of the listbox containing the 
                    808: #                         list of students
                    809: #          gLoaded - keeps track of whther scores have been loaded yet
                    810: ###########################################################
                    811: proc findByName {} {
                    812:     global gFindName gFindNumber gStudentList gSectionLoad gLoaded
                    813: 
                    814:     fillInStudent gFindName gFindNumber 1
                    815:     if { $gFindNumber == "" } { return }
                    816:     set section [findSection name $gFindName]
                    817: 
                    818:     if { $section == "0" } { 
                    819: 	displayError "Name not found in classl file"
                    820: 	return 
                    821:     }
                    822: 
                    823:     if { !(($gSectionLoad == $section) && $gLoaded) } {
                    824: 	set gSectionLoad $section
                    825: 	loadScores
                    826:     }
                    827: 
                    828:     set size [$gStudentList size]
                    829:     set search [string tolower $gFindName]
                    830:     while { $size != 0 } {
                    831: 	incr size -1
                    832: 	set tempString [string tolower [$gStudentList get $size]]
                    833: 	switch -- [string first $search $tempString] {
                    834: 	    0
                    835: 	    { 
                    836: 		$gStudentList selection set $size 
                    837: 		$gStudentList activate $size 
                    838: 		$gStudentList see $size
                    839: 	    }
                    840: 	}
                    841:     }
                    842: }
                    843: 
                    844: ###########################################################
                    845: # studentReport
                    846: ###########################################################
                    847: # creates a window containg a report for the current student
                    848: ###########################################################
                    849: # Arguments: None
                    850: # Returns: Nothing
                    851: # Globals: gSectionLoad - the current section being graded
                    852: #          gStudentList - the widget name of the listbox containing the 
                    853: #                         list of students
                    854: #          gWindoMenu - the name of the window menu widget
                    855: ###########################################################
                    856: proc studentReport {} {
                    857:     global gStudentList gSectionLoad gWindowMenu
                    858: 
                    859:     set string [$gStudentList get active]
                    860: 
                    861:     set studentNumber [string range $string 31 39]
                    862:     
                    863:     set text [getReportInfo $studentNumber]
                    864: 
                    865:     if {![winfo exists .a$studentNumber]} {
                    866: 	set report [toplevel .a$studentNumber]
                    867: 	$gWindowMenu add command -label "$studentNumber" -command \
                    868: 		"capaRaise $report"	
                    869: 	set labelFrame [frame $report.labelFrame]
                    870: 	set textFrame [frame $report.textFrame]
                    871: 	set buttonFrame [frame $report.buttonFrame]
                    872: 	pack $buttonFrame $labelFrame $textFrame -side top
                    873: 	pack configure $buttonFrame -anchor e
                    874: 
                    875: 	label $labelFrame.namel -text "Student Name: "
                    876: 	label $labelFrame.namet -text [string range $string 0 30]
                    877: 	label $labelFrame.numberl -text "Number: "
                    878: 	label $labelFrame.numbert -text [string range $string 31 39]
                    879: 	label $labelFrame.sectionl -text "Section: "
                    880: 	label $labelFrame.sectiont -text $gSectionLoad
                    881: 	pack $labelFrame.namel $labelFrame.namet $labelFrame.numberl \
                    882: 		$labelFrame.numbert $labelFrame.sectionl $labelFrame.sectiont \
                    883: 		-side left
                    884: 	
                    885: 	scrollbar $textFrame.scrollbar -orient vertical -command \
                    886: 		"$textFrame.text yview"
                    887: 	text $textFrame.text -yscrollcommand "$textFrame.scrollbar set" \
                    888: 		-height 30 -width 80
                    889: 	pack $textFrame.scrollbar $textFrame.text -side left
                    890: 	pack configure $textFrame.scrollbar -expand false -fill y
                    891: 	pack configure $textFrame.text -expand true -fill both
                    892: 	
                    893: 	button $buttonFrame.close -text "Close" -command \
                    894: 		"destroy $report
                    895: 	         removeWindowEntry $studentNumber"
                    896: 	pack $buttonFrame.close
                    897: 	Centre_Dialog $report default
                    898:     } else {
                    899: 	.a$studentNumber.textFrame.text delete 0.0 end 
                    900:     }
                    901: 
                    902:     .a$studentNumber.textFrame.text insert end $text
                    903:     .a$studentNumber.textFrame.text configure -state disabled
                    904:     
                    905: }
                    906: 
                    907: ###########################################################
                    908: # findByNumber
                    909: ###########################################################
                    910: # finds a student based on a complete student number, once again
                    911: # findSection finds the correct section and then it searches through the
                    912: # list box looking for the correct student
                    913: ###########################################################
                    914: # Arguments: None
                    915: # Returns: Nothing
                    916: # Globals: gSectionLoad - the current section being graded
                    917: #          gFindNumber - linked var that stores the string to search
                    918: #                        through student numbers for
                    919: #          gStudentList - the widget name of the listbox containing the 
                    920: #                         list of students
                    921: #          gLoaded - whether or not the data for the set/section has
                    922: #                    actually been loaded
                    923: ###########################################################
                    924: proc findByNumber {} {
                    925:     global gFindName gFindNumber gStudentList gSectionLoad gLoaded
                    926: 
                    927:     fillInStudent gFindName gFindNumber 0
                    928:     if { $gFindNumber == "" } { return }
                    929:     set section [findSection number $gFindNumber]
                    930: 
                    931:     if { $section == "0" } { 
                    932: 	displayError "Name not found in classl file"
                    933: 	return 
                    934:     }
                    935: 
                    936:     if { ! (($gSectionLoad == $section ) && $gLoaded) } {
                    937: 	set gSectionLoad $section
                    938: 	loadScores
                    939:     }
                    940: 
                    941:     set size [$gStudentList size]
                    942:     set search [string tolower $gFindNumber]
                    943:     while { $size != 0 } {
                    944: 	incr size -1
                    945: 	set tempString [string range [string tolower \
                    946: 		[$gStudentList get $size]] 31 39]
                    947: 	switch -- [string first $search $tempString] {
                    948: 	    0
                    949: 	    { 
                    950: 		$gStudentList selection set $size 
                    951: 		$gStudentList activate $size 
                    952: 		$gStudentList see $size
                    953: 	    }
                    954: 	}
                    955:     }
                    956: }
                    957: 
                    958: ###########################################################
                    959: # printBody
                    960: ###########################################################
                    961: # sends the file quiztemp.ps to the printer through lpr using
                    962: # the option foud in gLprCommand
                    963: ###########################################################
                    964: # Arguments: none
                    965: # Returns: Nothing
                    966: # Files: /tmp/g[pid] - file containg info to print (removed)
                    967: ###########################################################
                    968: proc printBody { lprCommand } {
                    969: 
                    970:     set errorMsg ""
                    971:     
                    972:     set error [catch {set returnMessage [eval "exec $lprCommand"] } errorMsg ]
                    973:     
                    974:     exec /bin/rm -f /tmp/g[pid]
                    975: 
                    976:     if { $error == 1 } {
                    977:         displayError "When attempting to print an error occured : $errorMsg"
                    978: 	return 1
                    979:     } else {
                    980: 	displayMessage "Print job sent to the printer.\n $returnMessage"
                    981:     }
                    982:     
                    983:     return 0
                    984: }
                    985: 
                    986: ###########################################################
                    987: # printSetSummary
                    988: ###########################################################
                    989: # prints a set summary for the currently grading set and section
                    990: ###########################################################
                    991: # Arguments: None
                    992: # Returns: Nothing
                    993: # Globals: gSetLoad - currently being graded set
                    994: #          gWindowMenu - the widget name of the window menu
                    995: #          gSectionLoad - currently being graded section
                    996: # Files: /tmp/g[pid] - file containg info to print (created)
                    997: ###########################################################
                    998: proc printSetSummary {} {
                    999:     global gSetLoad gWindowMenu gSectionLoad 
                   1000: 
                   1001:     if { $gSetLoad == "" } { 
                   1002: 	displayError "Please enter a Set number."
                   1003: 	return
                   1004:     }
                   1005: 
                   1006:     if { $gSectionLoad == "" } { 
                   1007: 	displayError "Please enter a Section number."
                   1008: 	return
                   1009:     }
                   1010: 
                   1011:     set lprCommand [getLprCommand [file join / tmp g[pid] ] ]
                   1012:     if { $lprCommand == "" } {
                   1013: 	displayError "Print command was empty, unable to print."
                   1014: 	return 1
                   1015:     }
                   1016:     if {$lprCommand == "Cancel" } {
                   1017: 	return 1
                   1018:     }
                   1019: 
                   1020:     getSetSummary [file join / tmp g[pid]]
                   1021: 
                   1022:     printBody  $lprCommand
                   1023: }
                   1024: 
                   1025: ###########################################################
                   1026: # printTermSummary
                   1027: ###########################################################
                   1028: # creates a termsummary file and send it to the printer
                   1029: ###########################################################
                   1030: # Arguments: None
                   1031: # Returns: Nothing
                   1032: # Globals: gSetLoad - currently being graded set
                   1033: #          gWindowMenu - the widget name of the window menu
                   1034: #          gSectionLoad - currently being graded section
                   1035: # Files: /tmp/g[pid] - file containg info to print (created)
                   1036: ###########################################################
                   1037: proc printTermSummary {} {
                   1038:     global gSetLoad gWindowMenu gSectionLoad 
                   1039: 
                   1040:     if { $gSetLoad == "" } { 
                   1041: 	displayError "Please enter a Set number."
                   1042: 	return
                   1043:     }
                   1044: 
                   1045:     if { $gSectionLoad == "" } { 
                   1046: 	displayError "Please enter a Section number."
                   1047: 	return
                   1048:     }
                   1049: 
                   1050:     set lprCommand [getLprCommand [file join / tmp g[pid] ] ]
                   1051:     if { $lprCommand == "" } {
                   1052: 	displayError "Print command was empty, unable to print."
                   1053: 	return 1
                   1054:     }
                   1055:     if {$lprCommand == "Cancel" } {
                   1056: 	return 1
                   1057:     }
                   1058: 
                   1059:     displayStatus "Getting Term Summary" bar
                   1060: 
                   1061:     getTermSummary [file join / tmp g[pid] ]
                   1062: 
                   1063:     removeStatus 
                   1064: 
                   1065:     printBody $lprCommand
                   1066: }
                   1067: 
                   1068: ###########################################################
                   1069: # createGradingWindow
                   1070: ###########################################################
                   1071: # create the window in which the user can change the grades in
                   1072: ###########################################################
                   1073: # Arguments: None
                   1074: # Returns: Nothing
                   1075: # Globals: gStudentList - the widget name of the list box the list
                   1076: #                         of students is in.
                   1077: #          gSectionLoad - currently being graded section
                   1078: #          gWindowMenu - widget name of the window menu
                   1079: #          gProblemText - stores the results of the parse of the set
                   1080: #          gParseMode - stores either 1 (Both, Questions Answers) or
                   1081: #                       2 (Answer Only)
                   1082: #          gSetLoad - currently being graded set
                   1083: #          gGrading - an array containg
                   1084: #               (name) - Name of the student
                   1085: #               (number) - student number 
                   1086: #          gGradeCanvas - widget name of the canvas used to contain all
                   1087: #                         of the radiobuttons when grading
                   1088: #          gAnswer - an array containg the score for the student
                   1089: #                ($i) - i contains the current problem number and the entry
                   1090: #                       has one of Y, N, E, or -
                   1091: #                (max$i) - i is the problem number, these entries exist only
                   1092: #                          for handgraded questions, and is the maximum
                   1093: #                          score for that question
                   1094: #          gQuestionType - stores whether a quetion is handgraded or not
                   1095: #                ($i) - i contains the current problem number and the entry
                   1096: #                       has one of handGrade, or autoGrade
                   1097: #          gParseModeButton - the text that will be displayed on
                   1098: #                             the button that switches parse modes, 
                   1099: #                             either "Answer Only" or 
                   1100: #                             "Both, Questions Answers"
                   1101: ###########################################################
                   1102: proc createGradingWindow {} {
                   1103:     global gStudentList gSectionLoad gWindowMenu gProblemText gParseMode \
                   1104: 	    gSetLoad gGrading gGradeCanvas gAnswer gQuestionType \
                   1105: 	    gParseModeButton
                   1106: 
                   1107:     if { [winfo exists .grading] } { 
                   1108: 	capaRaise .grading
                   1109: 	return 
                   1110:     }
                   1111:     catch {unset gAnswer}
                   1112:     set grading [toplevel .grading]
                   1113:     $gWindowMenu add command -label "Grading" -command "capaRaise $grading"
                   1114: 
                   1115:     set labelFrame [frame $grading.labelFrame]
                   1116:     set buttonFrame [frame $grading.buttonFrame]
                   1117:     set winFrame [frame $grading.winFrame]
                   1118:     pack $labelFrame $buttonFrame $winFrame -side top
                   1119:     pack configure $buttonFrame -anchor e
                   1120: 
                   1121:     set string [$gStudentList get active]
                   1122:     set gGrading(name) [string range $string 0 30]
                   1123:     set gGrading(number) [string range $string 31 39]
                   1124:     set gGrading(parsenum) $gGrading(number)
                   1125:     label $labelFrame.namel -text "Student Name: "
                   1126:     label $labelFrame.namet -text $gGrading(name)
                   1127:     label $labelFrame.numberl -text "Number: "
                   1128:     entry $labelFrame.numbert -width 9 -textvariable gGrading(parsenum)
                   1129:     button $labelFrame.reparse -text "Parse" -command "updateGradingWindow 0"
                   1130:     label $labelFrame.sectionl -text "Section: "
                   1131:     label $labelFrame.sectiont -text $gSectionLoad
                   1132:     pack $labelFrame.namel $labelFrame.namet $labelFrame.numberl \
                   1133: 	$labelFrame.numbert $labelFrame.reparse $labelFrame.sectionl \
                   1134: 	$labelFrame.sectiont -side left
                   1135: 
                   1136:     button $buttonFrame.button -textvariable gParseModeButton \
                   1137: 	    -command updateGradingWindow
                   1138:     button $buttonFrame.save -text SAVE 
                   1139:     button $buttonFrame.close -text Close -command "removeWindowEntry Grading
                   1140:                                                    destroy $grading"
                   1141:     pack $buttonFrame.button $buttonFrame.save $buttonFrame.close \
                   1142: 	    -side left
                   1143: 
                   1144:     set assignmentFrame [frame $winFrame.assignmentFrame]
                   1145:     set gradingFrame [frame $winFrame.gradingFrame]
                   1146:     pack $gradingFrame $assignmentFrame -side left
                   1147: 
                   1148:     scrollbar $assignmentFrame.scroll -orient vertical -command \
                   1149: 	    "$assignmentFrame.text yview"
                   1150:     set gProblemText [text $assignmentFrame.text -yscrollcommand \
                   1151: 	    "$assignmentFrame.scroll set" -height 44 -width 80]
                   1152:     pack $assignmentFrame.scroll $assignmentFrame.text -side left
                   1153:     pack configure $assignmentFrame.scroll -expand false -fill y
                   1154:     pack configure $assignmentFrame.text -expand true -fill both
                   1155: 
                   1156:     set numQuestions [enscriptParse $gParseMode $gSetLoad Specific 0 \
                   1157: 	    $gGrading(parsenum) $gGrading(name) gProblemText]
                   1158:     
                   1159:     $buttonFrame.save configure -command " saveGrading $numQuestions $grading "
                   1160:     set setAllFrame [frame $gradingFrame.setallFrame ]
                   1161:     set gradeFrame [frame $gradingFrame.gradeFrame ]
                   1162:     pack $gradingFrame.setallFrame  $gradeFrame -side top
                   1163: 
                   1164:     frame $setAllFrame.space0 -width 55
                   1165:     button $setAllFrame.dash -text "-" -padx -1 \
                   1166: 	    -command "gradeSetAll - $numQuestions"
                   1167:     frame $setAllFrame.space1 -width 8
                   1168:     button $setAllFrame.y -text "y" -padx -1 \
                   1169: 	    -command "gradeSetAll y $numQuestions"
                   1170:     frame $setAllFrame.space2 -width 8
                   1171:     button $setAllFrame.n -text "n" -padx -1 \
                   1172: 	    -command "gradeSetAll n $numQuestions"
                   1173:     frame $setAllFrame.space3 -width 8
                   1174:     button $setAllFrame.e -text "E" -padx -1 \
                   1175: 	    -command "gradeSetAll E $numQuestions"
                   1176:     frame $setAllFrame.space4 -width 8
                   1177:     label $setAllFrame.state -text "stat"
                   1178:     label $setAllFrame.tries -text "tries"
                   1179:     pack $setAllFrame.space0 $setAllFrame.dash \
                   1180: 	    $setAllFrame.space1 $setAllFrame.y \
                   1181: 	    $setAllFrame.space2 $setAllFrame.n \
                   1182: 	    $setAllFrame.space3 $setAllFrame.e \
                   1183: 	    $setAllFrame.space4 $setAllFrame.state \
                   1184: 	    $setAllFrame.tries -side left
                   1185: 
                   1186:     scrollbar $gradeFrame.scroll -orient vertical -command \
                   1187: 	    "$gradeFrame.canvas yview"
                   1188:     set gGradeCanvas [canvas $gradeFrame.canvas -yscrollcommand \
                   1189: 	    "$gradeFrame.scroll set" -height 600 -width 200]
                   1190:     pack $gradeFrame.scroll $gGradeCanvas -side left
                   1191:     pack configure $gradeFrame.scroll -expand false -fill y
                   1192:     pack configure $gGradeCanvas -expand true -fill both
                   1193: 
                   1194:     Centre_Dialog $grading default
                   1195: 
                   1196:     catch {unset gAnswer}
                   1197:     catch {unset gQuestionType}
                   1198: 
                   1199:     getQuestionTypes $numQuestions 
                   1200: 
                   1201:     set vSize 26
                   1202:     set offset 9
                   1203:     set todo ""
                   1204:     for { set i 1 } { $i <= $numQuestions } { incr i } {
                   1205: 	label $gGradeCanvas.prob$i -text "$i"
                   1206: 	$gGradeCanvas create window 10 [expr $offset + $vSize * ($i-1)] \
                   1207: 	    -window $gGradeCanvas.prob$i
                   1208: 	switch $gQuestionType($i) {
                   1209: 	    autoGrade
                   1210: 	    {
                   1211: 		radiobutton $gGradeCanvas.dash$i -variable gAnswer($i) \
                   1212: 			-value -
                   1213: 		$gGradeCanvas create window 40 [expr $offset+ $vSize * ($i-1)] -window \
                   1214: 			$gGradeCanvas.dash$i
                   1215: 		radiobutton $gGradeCanvas.y$i -variable gAnswer($i) -value y
                   1216: 		$gGradeCanvas create window 64 [expr $offset+ $vSize * ($i-1)] -window \
                   1217: 			$gGradeCanvas.y$i
                   1218: 		radiobutton $gGradeCanvas.n$i -variable gAnswer($i) -value n
                   1219: 		$gGradeCanvas create window 88 [expr $offset+ $vSize * ($i-1)] -window \
                   1220: 			$gGradeCanvas.n$i
                   1221: 		radiobutton $gGradeCanvas.e$i -variable gAnswer($i) -value E
                   1222: 		$gGradeCanvas create window 112 [expr $offset+ $vSize * ($i-1)] -window \
                   1223: 			$gGradeCanvas.e$i
                   1224: 		label $gGradeCanvas.state$i -textvariable gAnswer($i)
                   1225: 		$gGradeCanvas create window 136 [expr $offset+ $vSize * ($i-1)] -window \
                   1226: 			$gGradeCanvas.state$i
                   1227: 	    }
                   1228: 	    handGrade
                   1229: 	    {	
                   1230: 		radiobutton $gGradeCanvas.e$i -variable gAnswer($i) -value E
                   1231: 		$gGradeCanvas create window 112 [expr $offset+ $vSize * ($i-1)] -window \
                   1232: 			$gGradeCanvas.e$i
                   1233: 		scale $gGradeCanvas.hand$i -from 0 -to $gAnswer(max$i) -orient h \
                   1234: 		    -variable gAnswer(hand$i) -showvalue 0 -length 80
                   1235: 		$gGradeCanvas create window 60 [expr $offset+ $vSize * ($i-1)] -window \
                   1236: 			$gGradeCanvas.hand$i
                   1237: 		label $gGradeCanvas.current$i -textvariable gAnswer($i)
                   1238: 		$gGradeCanvas create window 136 [expr $offset+ $vSize * ($i-1)] -window \
                   1239: 			$gGradeCanvas.current$i
                   1240: #		label $gGradeCanvas.max$i -textvariable gAnswer(max$i)
                   1241: #		$gGradeCanvas create window 112 [expr $offset+ $vSize * ($i-1)] -window \
                   1242: 		    $gGradeCanvas.max$i
                   1243: 		trace variable gAnswer(hand$i) w handGradeExcuse
                   1244: 		lappend todo $i
                   1245: 	    }
                   1246: 	}
                   1247: 	entry $gGradeCanvas.tries$i -textvariable gAnswer($i.tries) -width 2
                   1248: 	$gGradeCanvas create window 170 [expr $offset+ $vSize * ($i - 1)] \
                   1249: 	    -window $gGradeCanvas.tries$i
                   1250:     }
                   1251:     $gGradeCanvas configure -scrollregion "0 0 150 \
                   1252:                   [ expr ( $vSize * $numQuestions ) + $vSize ]"
                   1253:     setupGAnswer $numQuestions
                   1254: 
                   1255:     foreach item $todo {
                   1256: 	if { $gAnswer($item) != "E" && $gAnswer($item) != "-" } { 
                   1257: 	    set gAnswer(hand$item) $gAnswer($item) 
                   1258: 	}
                   1259:     }
                   1260: }
                   1261: 
                   1262: ###########################################################
                   1263: # handGradeExcuse
                   1264: ###########################################################
                   1265: ###########################################################
                   1266: ###########################################################
                   1267: proc handGradeExcuse { name1 name2 op } {
                   1268:     global gAnswer
                   1269:     scan $name2 "hand%d" num
                   1270:     if { $gAnswer($name2) != "E" && $gAnswer($name2) != "-" } { 
                   1271: 	set gAnswer($num) $gAnswer($name2) 
                   1272:     }
                   1273: }
                   1274: ###########################################################
                   1275: # gradeSetAll
                   1276: ###########################################################
                   1277: ###########################################################
                   1278: ###########################################################
                   1279: proc gradeSetAll { type numQuestions } {
                   1280:     global gAnswer gQuestionType
                   1281:     
                   1282:     for { set i 1 } { $i <= $numQuestions } { incr i } {
                   1283: 	switch $gQuestionType($i) {
                   1284: 	    autoGrade
                   1285: 	    {
                   1286: 		if { $gAnswer($i) != "Y" } { set gAnswer($i) $type }
                   1287: 	    }
                   1288: 	    handGrade
                   1289: 	    {
                   1290: 		switch -- $type {
                   1291: 		    y
                   1292: 		    { set gAnswer($i) $gAnswer(max$i) }
                   1293: 		    n
                   1294: 		    { set gAnswer($i) "0" }
                   1295: 		    E
                   1296: 		    -
                   1297: 		    -
                   1298: 		    { set gAnswer($i) $type }
                   1299: 		}
                   1300: 	    }
                   1301: 	}
                   1302:     }
                   1303: }
                   1304: 
                   1305: ###########################################################
                   1306: # saveGrading
                   1307: ###########################################################
                   1308: # saves all changes, and updates the main window
                   1309: ###########################################################
                   1310: # Arguments: the number of questions, and the name of the grading 
                   1311: #            window
                   1312: # Returns: None
                   1313: # Globals: None
                   1314: ###########################################################
                   1315: proc saveGrading { numQuestions grading } {
                   1316:     if { [makeSure "You have pressed the SAVE button, Please confirm."] != \
                   1317: 	    "Cancel" } {
                   1318: 	saveGAnswer $numQuestions
                   1319: 	removeWindowEntry Grading
                   1320: 	destroy $grading
                   1321: 	loadScores
                   1322:     }
                   1323: }
                   1324: 
                   1325: ###########################################################
                   1326: # updateGradingWindow
                   1327: ###########################################################
                   1328: # reparses the file and updates the parsemode button
                   1329: ###########################################################
                   1330: # Arguments: None
                   1331: # Returns: Nothing
                   1332: # Globals: gProblemText - stores the results of the parse of the set
                   1333: #          gParseMode - stores either 1 (Both, Questions Answers) or
                   1334: #                       2 (Answer Only)
                   1335: #          gSetLoad - currently being graded set
                   1336: #          gGrading - an array containg
                   1337: #               (name) - Name of the student
                   1338: #               (number) - student number 
                   1339: #          gParseModeButton - the text that will be displayed on
                   1340: #                             the button that switches parse modes, 
                   1341: #                             either "Answer Only" or 
                   1342: #                             "Both, Questions Answers"
                   1343: ###########################################################
                   1344: proc updateGradingWindow { { changeMode 1 } } {
                   1345:     global gParseMode gSetLoad gGrading gProblemText gParseModeButton
                   1346: 
                   1347:     $gProblemText delete 0.0 end
                   1348: 
                   1349:     displayStatus "Updating Window . . ." message
                   1350: 
                   1351:     if { $changeMode } {
                   1352: 	switch $gParseMode {
                   1353: 	    1 { 
                   1354: 		set gParseModeButton "Both, Questions Answers" 
                   1355: 		set gParseMode 2
                   1356: 	    }
                   1357: 	    2 { 
                   1358: 		set gParseModeButton "Answer Only" 
                   1359: 		set gParseMode 1
                   1360: 	    }
                   1361: 	}
                   1362:     }
                   1363:     enscriptParse $gParseMode $gSetLoad Specific 0 $gGrading(parsenum) \
                   1364: 	    $gGrading(name) gProblemText
                   1365:     removeStatus
                   1366: }
                   1367: 
                   1368: ###########################################################
                   1369: # handGrade
                   1370: ###########################################################
                   1371: # creates a dialog to get the new score for a problem from the
                   1372: # user for a hand graded question
                   1373: ###########################################################
                   1374: # Arguments: the number of the problem
                   1375: # Returns: nothing
                   1376: # Globals: gGradeCanvas - the name of the canvas widget that has all
                   1377: #                         of the radio buttons for grading on
                   1378: #          gNewHandGrade - the variable the new grade will be in
                   1379: #          gAnswer - an array containg the score for the student
                   1380: #                ($i) - i contains the current problem number and the entry
                   1381: #                       has one of Y, N, E, or -
                   1382: #                (max$i) - i is the problem number, these entries exist only
                   1383: #                          for handgraded questions, and is the maximum
                   1384: #                          score for that question
                   1385: ###########################################################
                   1386: proc handGrade { problemNumber } {
                   1387:     global gGradeCanvas gNewHandGrade gAnswer
                   1388: 
                   1389:     set handGrade [toplevel .handGrade]
                   1390:     
                   1391:     set gradeFrame [frame $handGrade.gradeFrame]
                   1392:     set buttonFrame [frame $handGrade.buttonFrame]
                   1393:     pack $gradeFrame $buttonFrame -side top
                   1394:     
                   1395:     label $gradeFrame.grade -text "Grade: "
                   1396:     entry $gradeFrame.entry -textvariable gNewHandGrade
                   1397:     # set gNewHandGrade $gAnswer($problemNumber)
                   1398:     
                   1399:     set gNewHandGrade $gAnswer(max$problemNumber)
                   1400:     
                   1401:     label $gradeFrame.maxGrade -textvariable gAnswer(max$problemNumber)
                   1402:     pack $gradeFrame.grade $gradeFrame.entry $gradeFrame.maxGrade -side left
                   1403: 
                   1404:     button $buttonFrame.cancel -text Cancel -command "set gPrompt(ok) 0"
                   1405:     button $buttonFrame.ok -text Ok -command \
                   1406: 	"setHandGrade $problemNumber;set gPrompt(ok) 1"
                   1407:     pack $buttonFrame.cancel $buttonFrame.ok -side left
                   1408:     
                   1409:     Centre_Dialog $handGrade default
                   1410:     capaRaise $handGrade
                   1411:     capaGrab $handGrade
                   1412:     vwait gPrompt(ok)
                   1413:     capaGrab release $handGrade
                   1414:     destroy $handGrade
                   1415:     $gGradeCanvas.hand$problemNumber deselect
                   1416: }
                   1417: 
                   1418: ###########################################################
                   1419: # main
                   1420: ###########################################################
                   1421: # sets up the auto_path variable, some globals and adds some
                   1422: # options then calls createControlWindow to give the user something
                   1423: # to do
                   1424: ###########################################################
                   1425: # Arguments: None
                   1426: # Returns: Nothing
                   1427: # Globals: None
                   1428: ###########################################################
                   1429: if { [lindex $auto_path 0] == "./lib/tcl7.5" } {
                   1430:     set auto_path ""
                   1431:     lappend auto_path [pwd]/lib/tcl7.5
                   1432:     lappend auto_path [pwd]/lib/tk4.1
                   1433: }
                   1434: 
                   1435: lappend auto_path /usr/local/lib/CAPA45/Grader
                   1436: lappend auto_path [pwd]
                   1437: source gradesubjective.tcl
                   1438: option add *font 8x13bold
                   1439: set gUniqueNumber 1
                   1440: createControlWindow

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>