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

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

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