Annotation of capa/capa51/GUITools/classl.tcl, revision 1.2

1.1       albertel    1: ###########################################################
                      2: # createClasslEditor
                      3: ###########################################################
                      4: ###########################################################
                      5: ###########################################################
                      6: proc createClasslEditor { classlFile } {
                      7:     global gUniqueNumber gWindowMenu gWindow gTitle gClassl gFile \
                      8: 	    gClosed
                      9: 
                     10:     set error [ catch {set fileId [open $classlFile "r"]}]
                     11:     if { $error } { 
                     12: 	displayError "Unable to open a $classlFile."
                     13: 	return
                     14:     }
                     15:     close $fileId
                     16: 
                     17:     set num [incr gUniqueNumber]
                     18: 
                     19:     set gFile($num) $classlFile
                     20: 
                     21:     set classlWin [toplevel .classlwindow$num]
                     22:     $gWindowMenu add command -label "Classl $classlFile" \
                     23: 	    -command "capaRaise $classlWin"
                     24:     wm title $classlWin  "Classl $classlFile"
                     25: 
                     26:     set menuFrame [frame $classlWin.menu -borderwidth 3 -relief raised]
                     27:     set infoFrame [frame $classlWin.infoFrame]
                     28:     set actionFrame [frame $classlWin.actionFrame]
                     29:     set windowFrame [frame $classlWin.windowFrame]
                     30:     pack $menuFrame $infoFrame $actionFrame $windowFrame
                     31:     pack configure $windowFrame -expand 1 -fill both
                     32:     pack configure $menuFrame -fill x -anchor w
                     33: 
                     34: #menu
                     35:     menubutton $menuFrame.file -text File -menu $menuFrame.file.m
                     36:     menubutton $menuFrame.edit -text Copy -menu $menuFrame.edit.m
                     37:     pack $menuFrame.file  $menuFrame.edit -side left
                     38:     
                     39:     set fileMenu [ menu $menuFrame.file.m ]
                     40:     set editMenu [ menu $menuFrame.edit.m ]
                     41: 
                     42:     $fileMenu add command -label Open -accelerator "Alt+o" \
                     43: 	    -command "specifyClass createClasslEditor"
                     44:     bind $classlWin <Alt-o> "specifyClass createClasslEditor"
                     45:     $fileMenu add command -label Save -command "saveClassl $num 0" \
                     46: 	    -accelerator "Alt+s"
                     47:     bind $classlWin <Alt-s> "saveClassl $num 0"
                     48:     $fileMenu add command -label "Save As" -command "saveClassl $num 1" \
                     49: 	    -accelerator "Alt+S"
                     50:     bind $classlWin <Alt-Shift-s> "saveClassl $num 1" 
                     51:     $fileMenu add command -label Print -command "printClassl $num"
                     52:     $fileMenu add command -label Close -command "closeClassl $num" \
                     53: 	    -accelerator "Alt+w"
                     54:     bind $classlWin <Alt-w> "closeClassl $num"
                     55:     
                     56:     $editMenu add command -label "Copy StudentNum" -command "classlCopy $num stunum" \
                     57: 	-accelerator "Alt+c"
                     58:     bind $classlWin <Alt-c> "classlCopy $num stunum"
                     59:     $editMenu add command -label "Copy Name" -command "classlCopy $num name" \
                     60: 	-accelerator "Alt+n"
                     61:     bind $classlWin <Alt-n> "classlCopy $num name"
                     62:     $editMenu add command -label "Copy Email" -command "classlCopy $num email" \
                     63: 	-accelerator "Alt+e"
                     64:     bind $classlWin <Alt-e> "classlCopy $num email"
                     65: 
                     66: #info
                     67: #action
                     68:     button $actionFrame.add -text "Add" -command "classlAdd $num"
                     69:     button $actionFrame.edit -text "Edit" -command "classlEdit $num"
                     70:     button $actionFrame.delete -text "Delete" -command "classlDelete $num"
                     71:     button $actionFrame.section -text "Change Section" -command "classlSectionChange $num"
                     72:     button $actionFrame.sort -text "Sort" -command "classlSort $num"
                     73:     button $actionFrame.print -text "Print" -command "classlPrint $num"
                     74:     button $actionFrame.find -text "Find" -command "classlFind $num"
1.2     ! albertel   75:     button $actionFrame.merge -text "Merge" -command "classlMerge $num"
1.1       albertel   76:     pack $actionFrame.add $actionFrame.edit $actionFrame.delete $actionFrame.section \
1.2     ! albertel   77: 	$actionFrame.sort $actionFrame.print $actionFrame.find $actionFrame.merge\
        !            78: 	-side left
1.1       albertel   79: 
                     80: #window
                     81:     set leftFrame [frame $windowFrame.left]
                     82:     set rightFrame [frame $windowFrame.right]
                     83:     pack $leftFrame $rightFrame -side left
                     84:     pack configure $leftFrame -expand 1 -fill both
                     85:     pack configure $rightFrame -fill y 
                     86: 
                     87: #FIXME need to set the title width based on the widest occuring element in
                     88: #the listbox
                     89:     scrollbar $rightFrame.scroll -orient v -command "$leftFrame.classl yview"
                     90:     pack $rightFrame.scroll -fill y -expand 1 -pady 20
                     91: 
                     92:     set gTitle($num) [format "%-100s" "Class  Section  StuNum  Name                                E-mail"]
                     93:     entry $leftFrame.title -textvariable gTitle($num) -width 80 \
                     94: 	    -state disabled -xscrollcommand "$leftFrame.scroll set"
                     95:     set gClassl($num) [ listbox $leftFrame.classl -width 80 -height 30 \
                     96: 	    -xscrollcommand "$leftFrame.scroll set" \
                     97: 	    -yscrollcommand "$rightFrame.scroll set" \
                     98:             -exportselection 0]
                     99:     scrollbar $leftFrame.scroll -orient h -command \
                    100: 	    "scrolltwo {$leftFrame.classl xview} {$leftFrame.title  xview}"
                    101:     pack $leftFrame.title $leftFrame.classl $leftFrame.scroll -side top
                    102:     pack configure $leftFrame.title $leftFrame.scroll -fill x
                    103:     pack configure $leftFrame.classl -fill both -expand 1
                    104: 
                    105:     set fileId [open $classlFile "r"]
                    106:     while { 1 } {
                    107: 	set aline [gets $fileId]
                    108: 	if { [eof $fileId ] } { break }
                    109: 	$gClassl($num) insert end [format "%-100s" $aline]
                    110:     }
                    111:     set gClassl($num.changed) 0
                    112:     set gClassl($num.changedlast) 0
                    113:     set gClosed($num) 0
                    114:     Centre_Dialog $classlWin default
                    115:     trace variable gClassl($num.changed) w updateClasslStatus
                    116: }
                    117: 
                    118: ###########################################################
                    119: # closeClassl
                    120: ###########################################################
                    121: ###########################################################
                    122: ###########################################################
                    123: proc closeClassl { num { mustClose 0 } } {
                    124:     global gWindowMenu gWindow gTitle gClassl gFile gClosed
                    125: 
                    126:     if { ![winfo exists $gClassl($num)] } { return }
                    127: 
                    128:     if { $gClosed($num) } { return }
                    129:     if { $gClassl($num.changed) == 1 } {
                    130:         if { [askToSave "Do you wish to save $gFile($num)?" "saveClassl $num" ] == "Cancel" && ( ! $mustClose ) } { return }
                    131:     }
                    132: 
                    133:     if { ( ! $mustClose ) && ( [makeSure "Are you sure you wish to stop editing
                    134: $gFile($num)?"] == "Cancel" ) } {
                    135:         return
                    136:     }
                    137:     set gClosed($num) 1
                    138:     destroy [winfo toplevel $gClassl($num)]
                    139:     removeWindowEntry "Classl $gFile($num)"
                    140: }
                    141: 
                    142: ###########################################################
                    143: # saveClassl
                    144: ###########################################################
                    145: ###########################################################
                    146: ###########################################################
                    147: proc saveClassl { num {saveAs 0}} {
                    148:     global gFile gClassl
                    149: 
                    150:     if { ![winfo exists $gClassl($num)] } { return }
                    151:     if { $saveAs } {
                    152: 	set file [tk_getSaveFile -title "Enter name to Save As" \
                    153: 		      -initialdir [file dirname "$gFile($num)"]]
                    154: 	if {$file == "" } { return }
                    155: 	set gFile($num) $file
                    156:     }
                    157:     set fileId [open "$gFile($num)" "w"]
                    158:     foreach line [$gClassl($num) get 0 end] { puts $fileId $line }
                    159:     close $fileId
                    160:     set gClassl($num.changed) 0
                    161: }
                    162: 
                    163: ###########################################################
                    164: # classlSectionChange
                    165: ###########################################################
                    166: ###########################################################
                    167: ###########################################################
                    168: proc classlSectionChange { num } {
                    169:     global gFile gClassl gWindowMenu
                    170:     
                    171:     if { [set which [$gClassl($num) curselection]] == "" } {
                    172: 	displayMessage "Select a student first"
                    173: 	return
                    174:     }
                    175:     if { [winfo exists .classlsection$num] } {
                    176: 	capaRaise .classlsection$num
                    177: 	return
                    178:     }
                    179:     set sectionChange [toplevel .classlsection$num]
                    180:     $gWindowMenu add command -label "Section Change" \
                    181: 	    -command "capaRaise $sectionChange"
                    182:     wm title $sectionChange [file dirname $sectionChange]
                    183: 
                    184:     set infoFrame [frame $sectionChange.info]
                    185:     set entryFrame [frame $sectionChange.entry]
                    186:     set buttonFrame [frame $sectionChange.button]
                    187:     pack $infoFrame $entryFrame $buttonFrame -side top
                    188:     
                    189:     label $infoFrame.label -text "Enter New Section Number"
                    190:     pack $infoFrame.label
                    191: 
                    192:     label $entryFrame.label -text "Section:"
                    193:     entry $entryFrame.section -textvariable gClassl($num.section) -width 3 \
                    194: 	-validate key -validatecommand "limitEntry %W 3 number %P"
                    195:     pack $entryFrame.label $entryFrame.section -side left
                    196: 
                    197:     set gClassl($num.done) 0
                    198:     button $buttonFrame.change -text "Change" -command "set gClassl($num.done) 1"
                    199:     button $buttonFrame.cancel -text "Cancel" -command "set gClassl($num.done) 0"
                    200:     pack $buttonFrame.change $buttonFrame.cancel -side left
                    201: 
                    202:     Centre_Dialog $sectionChange default
                    203:     update
                    204: 
                    205:     focus $sectionChange
                    206:     capaGrab $sectionChange
                    207:     vwait gClassl($num.done)
                    208:     capaGrab release $sectionChange
                    209:     
                    210:     if { $gClassl($num.done) } {
                    211: 	set record [$gClassl($num) get $which]
                    212: 	set record "[string range $record 0 9][format %03d $gClassl($num.section)][string range $record 13 end]"
                    213: 	$gClassl($num) delete $which
                    214: 	$gClassl($num) insert $which $record
                    215: 	set gClassl($num.changed) 1
                    216:     }
                    217: 
                    218:     destroy $sectionChange
                    219: }
                    220: 
                    221: ###########################################################
                    222: # classlSort
                    223: ###########################################################
                    224: ###########################################################
                    225: ###########################################################
                    226: proc classlSort { num } {
                    227:     global gFile gClassl gWindowMenu
                    228:     if { [winfo exists .classlsort$num] } {
                    229: 	capaRaise .classlsort$num
                    230: 	return
                    231:     }
                    232: 
                    233:     set sortClassl [toplevel .classlsort$num]
                    234:     $gWindowMenu add command -label "Sort Classl" \
                    235: 	    -command "capaRaise $sortClassl"
                    236:     wm title $sortClassl [file dirname $sortClassl]
                    237: 
                    238:     set infoFrame [frame $sortClassl.info]
                    239:     set buttonFrame [frame $sortClassl.button]
                    240:     pack $infoFrame $buttonFrame -side top
                    241:     
                    242:     label $infoFrame.label -text "How would you like the classl sorted?"
                    243:     pack $infoFrame.label
                    244:     
                    245:     set gClassl($num.done) 0
                    246:     button $buttonFrame.section -text "Sort By Section" \
                    247: 	-command "set gClassl($num.done) Section"
                    248:     button $buttonFrame.name    -text "Sort By Name" \
                    249: 	-command "set gClassl($num.done) Name"
                    250:     button $buttonFrame.cancel  -text "Cancel" -command "set gClassl($num.done) 0"
                    251:     pack $buttonFrame.section $buttonFrame.name $buttonFrame.cancel -side left
                    252: 
                    253:     Centre_Dialog $sortClassl default
                    254:     update
                    255: 
                    256:     focus $sortClassl
                    257:     capaGrab $sortClassl
                    258:     vwait gClassl($num.done)
                    259:     capaGrab release $sortClassl
                    260:     
                    261:     if { $gClassl($num.done) != 0 } {
                    262: 	sortClassl$gClassl($num.done) $num
                    263: 	set gClassl($num.changed) 1
                    264:     }
                    265:     destroy $sortClassl
                    266: }
                    267: 
                    268: ###########################################################
                    269: # classlCompare
                    270: ###########################################################
                    271: ###########################################################
                    272: ###########################################################
                    273: proc classlCompare { field1 field2 val1 val2 } {
                    274:     switch $field1 {
                    275: 	section {
                    276: 	    set a [string range $val1 10 12]
                    277: 	    set b [string range $val2 10 12]
                    278: 	}
                    279: 	name {
                    280: 	    set a " [string range $val1 24 55]"
                    281: 	    set b " [string range $val2 24 55]"
                    282: 	}
                    283:     }
                    284:     switch $field2 {
                    285: 	name {
                    286: 	    append a " [string range $val1 24 55]"
                    287: 	    append b " [string range $val2 24 55]"
                    288: 	}
                    289: 	default {}
                    290:     }
                    291:     return [string compare $a $b]
                    292: }
                    293: 
                    294: ###########################################################
                    295: # sortClasslSection
                    296: ###########################################################
                    297: ###########################################################
                    298: ###########################################################
                    299: proc sortClasslSection { num } {
                    300:     global gClassl
                    301:     set allitems [$gClassl($num) get 0 end]
                    302:     set newitems [lsort -command "classlCompare section name" $allitems]
                    303:     $gClassl($num) delete 0 end
                    304:     eval "$gClassl($num) insert end $newitems"
                    305: }
                    306: 
                    307: ###########################################################
                    308: # sortClasslName
                    309: ###########################################################
                    310: ###########################################################
                    311: ###########################################################
                    312: proc sortClasslName { num } {
                    313:     global gClassl
                    314:     set allitems [$gClassl($num) get 0 end]
                    315:     set newitems [lsort -command "classlCompare name {}" $allitems]
                    316:     $gClassl($num) delete 0 end
                    317:     eval "$gClassl($num) insert end $newitems"
                    318: }
                    319:  
                    320: ###########################################################
                    321: # makeClasslEntryEditor 
                    322: ###########################################################
                    323: ###########################################################
                    324: ###########################################################
                    325: proc makeClasslEntryEditor { num window title buttonname } {
                    326:     global gClassl gWindowMenu
                    327: 
                    328:     if { [winfo exists $window] } {
                    329: 	capaRaise $window
                    330: 	return 1
                    331:     }
                    332: 
                    333:     set add [toplevel $window]
                    334:     $gWindowMenu add command -label "$title" -command "capaRaise $add"
                    335:     wm title $add "$title"
                    336: 
                    337:     set infoFrame [frame $add.info]
                    338:     set buttonFrame [frame $add.button]
                    339:     pack $infoFrame $buttonFrame -side top -anchor w
                    340: 
                    341:     set classFrame [frame $infoFrame.class]
                    342:     set sectionFrame [frame $infoFrame.section]
                    343:     set stuFrame [frame $infoFrame.stu]
                    344:     set nameFrame [frame $infoFrame.name]
                    345:     set emailFrame [frame $infoFrame.email]
                    346:     pack $classFrame $sectionFrame $stuFrame $nameFrame $emailFrame -side top -anchor w
                    347: 
                    348:     label $classFrame.label -text "Class Name" -width 20
                    349:     entry $classFrame.entry -textvariable gClassl($num.editclass) -width 9 \
                    350: 	-validate key -validatecommand "limitEntry %W 9 any %P"
                    351:     pack $classFrame.label $classFrame.entry -side left
                    352: 
                    353:     label $sectionFrame.label -text "Section" -width 20
                    354:     entry $sectionFrame.entry -textvariable gClassl($num.editsection) -width 3 \
                    355: 	-validate key -validatecommand "limitEntry %W 3 number %P"
                    356:     pack $sectionFrame.label $sectionFrame.entry -side left
                    357: 
                    358:     label $stuFrame.label -text "Student Number" -width 20
                    359:     entry $stuFrame.entry -textvariable gClassl($num.editstu) -width 9 \
                    360: 	-validate key -validatecommand "limitEntry %W 9 any %P"
                    361:     pack $stuFrame.label $stuFrame.entry -side left
                    362: 
                    363:     label $nameFrame.label -text "Name(Last, First MI)" -width 20
                    364:     entry $nameFrame.entry -textvariable gClassl($num.editname) -width 30 \
                    365: 	-validate key -validatecommand "limitEntry %W 30 any %P"
                    366:     pack $nameFrame.label $nameFrame.entry -side left
                    367: 
                    368:     label $emailFrame.label -text "Email" -width 20
                    369:     entry $emailFrame.entry -textvariable gClassl($num.editemail) -width 40 \
                    370: 	-validate key -validatecommand "limitEntry %W 40 any %P"
                    371:     pack $emailFrame.label $emailFrame.entry -side left
                    372: 
                    373:     button $buttonFrame.add -text $buttonname -command "set gClassl($num.done) 1"
                    374:     button $buttonFrame.cancel -text Cancel -command "set gClassl($num.done) 0"
                    375:     pack $buttonFrame.add $buttonFrame.cancel -side left
                    376: 
                    377:     bind $add <Return> "set gClassl($num.done) 1"
                    378: 
                    379:     Centre_Dialog $add default
                    380:     update
                    381: 
                    382:     focus $add
                    383:     capaGrab $add
                    384:     return 0
                    385: }
                    386: 
                    387: ###########################################################
                    388: # classlDelete
                    389: ###########################################################
                    390: ###########################################################
                    391: ###########################################################
                    392: proc classlDelete { num } {
                    393:     global gClassl gWindowMenu
                    394: 
                    395:     if { [set which [$gClassl($num) curselection]] == "" } {
                    396: 	displayMessage "Select a student first"
                    397: 	return
                    398:     } 
                    399:     $gClassl($num) delete $which
                    400:     set gClassl($num.changed) 1
                    401: }
                    402: 
                    403: ###########################################################
                    404: # classlEdit
                    405: ###########################################################
                    406: ###########################################################
                    407: ###########################################################
                    408: proc classlEdit { num } {
                    409:     global gClassl gWindowMenu
                    410: 
                    411:     if { [set which [$gClassl($num) curselection]] == "" } {
                    412: 	displayMessage "Select a student first"
                    413: 	return
                    414:     } 
                    415:     set record [$gClassl($num) get $which]
                    416:     
                    417:     set gClassl($num.editclass) [string trimright [string range $record 0 8]]
                    418:     set gClassl($num.editsection) [string trimright [string range $record 10 12]]
                    419:     set gClassl($num.editstu) [string trimright [string range $record 14 22]]
                    420:     set gClassl($num.editname) [string trimright [string range $record 24 53]]
                    421:     set gClassl($num.editemail) [string trimright [string range $record 60 99]]
                    422: 
                    423:     if { [makeClasslEntryEditor $num ".classledit$num" "Editing Student" "Done"] } { return }
                    424: 
                    425:     vwait gClassl($num.done)
                    426:     capaGrab release .classledit$num
                    427:     destroy .classledit$num
                    428:     if { $gClassl($num.done) } {
                    429: 	set gClassl($num.editsection) [string trimleft $gClassl($num.editsection) "0"]
                    430: 	set record [format "%-9s %03d %-9s %-30s      %-40s" $gClassl($num.editclass) \
                    431: 		   $gClassl($num.editsection) $gClassl($num.editstu) \
                    432: 		   $gClassl($num.editname) $gClassl($num.editemail)]
                    433: 	$gClassl($num) delete $which
                    434: 	$gClassl($num) insert $which $record
                    435: 	set gClassl($num.changed) 1
                    436:     }
                    437: }
                    438: 
                    439: ###########################################################
                    440: # findStuNumClassl 
                    441: ###########################################################
                    442: ###########################################################
                    443: ###########################################################
                    444: proc findStuNumClassl { num newstunum } {
                    445:     global gClassl 
                    446:     
                    447:     set max [$gClassl($num) index end]
                    448:     for {set i 0} {$i < $max} {incr i} {
                    449: 	set teststunum [string range [$gClassl($num) get $i] 14 22]
                    450: 	if { [regexp -nocase $newstunum $teststunum] } { return $i }
                    451:     }
                    452:     return -1
                    453: }
                    454: 
                    455: ###########################################################
                    456: # classlAdd
                    457: ###########################################################
                    458: ###########################################################
                    459: ###########################################################
                    460: proc classlAdd { num } {
                    461:     global gClassl gWindowMenu
                    462: 
                    463:     set gClassl($num.editclass) ""
                    464:     set gClassl($num.editsection) ""
                    465:     set gClassl($num.editstu) ""
                    466:     set gClassl($num.editname) ""
                    467:     set gClassl($num.editemail) ""
                    468: 
                    469:     if { [makeClasslEntryEditor $num ".classladd$num" "Adding a Student" "Add"] } { 
                    470: 	return 
                    471:     }
                    472:     vwait gClassl($num.done)
                    473:     capaGrab release .classladd$num
                    474:     destroy .classladd$num
                    475:     
                    476:     if { $gClassl($num.done) } {
                    477: 	if { [set which [findStuNumClassl $num $gClassl($num.editstu)]] > -1 } {
                    478: 	    if { "Cancel" == [makeSure "Found a duplicate student \n [$gClassl($num) get $which] \n Replace this one?"] } {
                    479: 		set gClassl($num.done) 0
                    480: 		displayMessage "Student was not added."
                    481: 	    } else {
                    482: 		$gClassl($num) delete $which
                    483: 	    }
                    484: 	}
                    485:     }
                    486:     if { $gClassl($num.done) } {
                    487: 	set gClassl($num.editsection) [string trimleft $gClassl($num.editsection) "0"]
                    488: 	set a [format "%-9s %03d %-9s %-30s      %-40s" $gClassl($num.editclass) \
                    489: 		   $gClassl($num.editsection) $gClassl($num.editstu) \
                    490: 		   $gClassl($num.editname) $gClassl($num.editemail)]
                    491: 	$gClassl($num) insert 0 $a
                    492: 	set gClassl($num.changed) 1
                    493:     }
                    494: }
                    495: 
                    496: ###########################################################
                    497: # classlPrint
                    498: ###########################################################
                    499: ###########################################################
                    500: ###########################################################
                    501: proc classlPrint { num } {
                    502:     global gClassl gWindowMenu gFile
                    503: 
                    504:     if { [set which [$gClassl($num) curselection]] == "" } {
                    505: 	displayMessage "Select a student first"
                    506: 	return
                    507:     } 
                    508:     if { $gClassl($num.changed) == 1 } {
                    509:         if {[askToSave "Do you wish to save $gFile($num)?" "saveClassl $num"]=="Yes"} { 
                    510: 	    saveClassl $num
                    511: 	}
                    512:     }
                    513:     set record [$gClassl($num) get $which]
                    514:     set stunum [string range $record 14 22]
                    515: 
                    516:     if { [winfo exists .capaprint$num] } {
                    517: 	capaRaise .capaprint$num
                    518: 	return 1
                    519:     }
                    520: 
                    521:     set print [toplevel .capaprint$num]
                    522:     $gWindowMenu add command -label "Printing a Student" -command "capaRaise $print"
                    523:     wm title $print "Printing a Student"
                    524: 
                    525:     set infoFrame [frame $print.info]
                    526:     set dataFrame [frame $print.data]
                    527:     set buttonFrame [frame $print.button]
                    528:     pack $infoFrame $dataFrame $buttonFrame -side top -anchor w
                    529: 
                    530:     label $infoFrame.label -text "Print For Student $stunum"
                    531:     pack $infoFrame.label
                    532: 
                    533:     set setFrame [frame $dataFrame.set]
                    534:     set printerFrame [frame $dataFrame.printer]
                    535:     pack $setFrame $printerFrame -side top -anchor w
                    536: 
                    537:     label $setFrame.label -text "Set" -width 13
                    538:     entry $setFrame.set -textvariable gClassl($num.printset) -width 2 \
                    539: 		-validate key -validatecommand "limitEntry %W 9 any %P"
                    540:     pack $setFrame.label $setFrame.set -side left
                    541: 
                    542:     label $printerFrame.label -text "Printer Name" -width 13
                    543:     entry $printerFrame.printer -textvariable gClassl($num.printername) -width 20 
                    544:     pack $printerFrame.label $printerFrame.printer -side left
                    545: 
                    546:     button $buttonFrame.print -text "Print" -command "set gClassl($num.done) 1"
                    547:     button $buttonFrame.cancel -text "Cancel" -command "set gClassl($num.done) 0"
                    548:     pack $buttonFrame.print $buttonFrame.cancel -side left
                    549: 
                    550:     bind $print <Return> "set gClassl($num.done) 1"
                    551: 
                    552:     Centre_Dialog $print default
                    553:     update
                    554: 
                    555:     focus $print
                    556:     capaGrab $print
                    557:     vwait gClassl($num.done)
                    558:     capaGrab release $print
                    559: 
                    560:     if { $gClassl($num.done) } {
                    561: 	global gCapaConfig
                    562: 	parseCapaConfig $num [file dirname $gFile($num)]
                    563: 	if {[catch {printStudent $num $stunum $gClassl($num.printset) $gClassl($num.printername)} error ]} {
                    564: 	    displayError "Unable to print  $stunum"
                    565: 	}
                    566: 	foreach name [array names gCapaConfig "$num.*"] {
                    567: 	    unset gCapaConfig($name)
                    568: 	}
                    569:     }
                    570:     destroy $print
                    571: }
                    572: 
                    573: ###########################################################
                    574: # printStudent
                    575: ###########################################################
                    576: ###########################################################
                    577: ###########################################################
                    578: proc printStudent { num stunum printset printername } {
                    579:     global gCapaConfig gFile
                    580:     set command "$gCapaConfig($num.qzparse_command) -c [file dirname $gFile($num)] \
                    581:                      -set $printset -stu $stunum"
                    582:     eval "exec $command"
                    583:     set tex_file [file join [file dirname $gFile($num)] TeX $stunum.tex]
                    584:     set command "$gCapaConfig($num.latex_command) $tex_file"
                    585:     removeStatus $num
                    586:     #if { "Yes" != [makeSure "Planning on running LaTeX, Continue?"] } { return }
                    587:     displayStatus "Running LaTeX" message $num
                    588:     set directory [pwd]
                    589:     cd [file join [file dirname $gFile($num)] TeX]
                    590:     eval "exec $command"
                    591:     cd $directory
                    592:     set dvi_file [file join [file dirname $gFile($num)] TeX $stunum.dvi]
                    593:     set ps_file [file join [file dirname $gFile($num)] TeX $stunum.ps]
                    594:     set command "$gCapaConfig($num.dvips_command) $dvi_file -o $ps_file >& /dev/null"
                    595:     removeStatus $num
                    596:     #if { "Yes" != [makeSure "Planning on running dvips, Continue?"] } { return }
                    597:     displayStatus "Running dvips" message $num
                    598:     eval "exec $command"
                    599:     removeStatus $num
                    600:     #if { "Cancel" == [set lprcmd [getLprCommand $ps_file $num]] } { return }
                    601:     if { [catch { eval "exec lpr -P$printername $ps_file" } errors ] } {
                    602: 	displayError "An error occurred while printing: $errors"
                    603:     }
                    604: }
                    605: 
                    606: ###########################################################
                    607: # updateClasslStatus
                    608: ###########################################################
                    609: ###########################################################
                    610: ###########################################################
                    611: proc updateClasslStatus { name1 name2 op } {
                    612:     global gClassl gWindowMenu
                    613: 
                    614:     set num [lindex [split $name2 .] 0]
                    615:     if { $gClassl($num.changed) != $gClassl($num.changedlast)} {
                    616: 	set gClassl($num.changedlast) $gClassl($num.changed)
                    617: 	global gFile
                    618: 	if { ![winfo exists $gClassl($num)] } { return }
                    619: 	if { $gClassl($num.changed) } {
                    620: 	    catch {removeWindowEntry "Classl $gFile($num)*"}
                    621: 	    wm title [winfo toplevel $gClassl($num)] "Classl $gFile($num) (Modified)"
                    622: 	    $gWindowMenu add command -label "Classl $gFile($num) (Modified)" -command \
                    623: 		"capaRaise $gClassl($num)"
                    624: 	} else {
                    625: 	    catch {removeWindowEntry "Classl $gFile($num)*"}
                    626: 	    wm title [winfo toplevel $gClassl($num)] "Classl $gFile($num)"
                    627: 	    $gWindowMenu add command -label "Classl $gFile($num)" -command \
                    628: 		"capaRaise $gClassl($num)"
                    629: 	}
                    630:     }
                    631: }
                    632: 
                    633: ###########################################################
                    634: # classlCopy
                    635: ###########################################################
                    636: ###########################################################
                    637: ###########################################################
                    638: proc classlCopy { num field } {
                    639:     global gClassl
                    640:     
                    641:     if { ![winfo exists $gClassl($num)] } { return }
                    642:     if { [set which [$gClassl($num) curselection]] == "" } {
                    643: 	displayMessage "Select a student first"
                    644: 	return
                    645:     }
                    646:     set entry [$gClassl($num) get $which]
                    647:     set text ""
                    648:     switch $field {
                    649: 	stunum { set text [string trimright [string range $entry 14 22]] }
                    650: 	name { set text [string trimright [string range $entry 24 53]] }
                    651: 	email { set text [string trimright [string range $entry 60 99]] }
                    652:     }
                    653:     if { $text != "" } {
                    654: 	set gClassl($num.selection) $text
                    655: 	selection own $gClassl($num)
                    656: 	selection handle $gClassl($num) "classlPaste $num"
                    657: 	selection handle -selection CLIPBOARD $gClassl($num) "classlPaste $num"
                    658: 	clipboard clear -displayof $gClassl($num)
                    659: 	clipboard append -displayof $gClassl($num) -- $text
                    660:     }
                    661: }
                    662: 
                    663: ###########################################################
                    664: # classlPaste
                    665: ###########################################################
                    666: ###########################################################
                    667: ###########################################################
                    668: proc classlPaste { num start length } {
                    669:     global gClassl
                    670:     return [string range $gClassl($num.selection) $start [expr $start + $length]]
                    671: }
                    672: 
                    673: ###########################################################
                    674: # classlFind
                    675: ###########################################################
                    676: ###########################################################
                    677: ###########################################################
                    678: proc classlFind { num } {
                    679:     global gClassl gWindowMenu
                    680: 
                    681:     if { [winfo exists .classlfind$num] } {
                    682: 	capaRaise .classlfind$num
                    683: 	return
                    684:     }
                    685:     set classlFind [toplevel .classlfind$num]
                    686:     $gWindowMenu add command -label "Find in Classl" \
                    687: 	    -command "capaRaise $classlFind"
                    688:     wm title $classlFind "Find"
                    689: 
                    690:     set infoFrame [frame $classlFind.info]
                    691:     set entryFrame [frame $classlFind.entry]
                    692:     set buttonFrame [frame $classlFind.button]
                    693:     pack $infoFrame $entryFrame $buttonFrame -side top -anchor w
                    694: 
                    695:     set nameFrame [frame $entryFrame.name]
                    696:     set stunumFrame [frame $entryFrame.stunum]
                    697:     set emailFrame [frame $entryFrame.email]
                    698:     pack $nameFrame $stunumFrame $emailFrame -side top -anchor w
                    699: 
                    700:     label $nameFrame.label -text "Name" -width 14 -anchor w
                    701:     entry $nameFrame.name -textvariable gClassl($num.findname) -width 30 \
                    702: 	-validate key -validatecommand "limitEntry %W 30 any %P"
                    703:     frame $nameFrame.spacer -width 80
                    704:     button $nameFrame.go -text "Find" -command "classlDoFind $num name"
                    705:     pack $nameFrame.label $nameFrame.name $nameFrame.spacer $nameFrame.go \
                    706: 	-side left -anchor w
                    707: 
                    708:     label $stunumFrame.label -text "Student Number" -width 14 -anchor w
                    709:     entry $stunumFrame.stunum -textvariable gClassl($num.findstunum) -width 9 \
                    710: 	-validate key -validatecommand "limitEntry %W 9 any %P"
                    711:     frame $stunumFrame.spacer -width 248
                    712:     button $stunumFrame.go -text "Find" -command "classlDoFind $num stunum"
                    713:     pack $stunumFrame.label $stunumFrame.stunum $stunumFrame.spacer \
                    714: 	$stunumFrame.go -side left -anchor w
                    715: 
                    716:     label $emailFrame.label -text "Email" -width 14 -anchor w
                    717:     entry $emailFrame.email -textvariable gClassl($num.findemail) -width 40 \
                    718: 	-validate key -validatecommand "limitEntry %W 40 any %P"
                    719:     button $emailFrame.go -text "Find" -command "classlDoFind $num email"
                    720:     pack $emailFrame.label $emailFrame.email $emailFrame.go -side left -anchor w
                    721: 
                    722:     button $buttonFrame.close -text "Close" -command "destroy $classlFind"
                    723:     pack $buttonFrame.close
                    724: 
                    725:     Centre_Dialog $classlFind default
                    726: }
                    727: 
                    728: ###########################################################
                    729: # classlDoFind
                    730: ###########################################################
                    731: ###########################################################
                    732: ###########################################################
                    733: proc classlDoFind { num type } {
                    734:     global gClassl 
                    735: 
                    736:     if {![winfo exists $gClassl($num)]} {return}
                    737:     if { [set which [$gClassl($num) curselection]] == "" } { 
                    738: 	set which 0 
                    739:     } else {
                    740: 	incr which
                    741:     }
                    742:     set max [$gClassl($num) index end]
1.2     ! albertel  743:     for {set i 0} { $i < ($max)} {incr i} {
1.1       albertel  744: 	set current [expr ($i+$which)%$max]
                    745: 	set entry [$gClassl($num) get $current]
                    746: 	switch $type {
                    747: 	    name { set tmp [string range [$gClassl($num) get $current] 24 53] }
                    748: 	    stunum { set tmp [string range [$gClassl($num) get $current] 14 22] }
                    749: 	    email { set tmp [string range [$gClassl($num) get $current] 60 99] }
                    750: 	}
                    751: 	if { [regexp -nocase $gClassl($num.find$type) $tmp] } {
                    752: 	    $gClassl($num) selection clear 0 end
                    753: 	    $gClassl($num) selection set $current
                    754: 	    $gClassl($num) see $current
                    755: 	    return
                    756: 	}
                    757:     }
                    758:     displayMessage "Not Found"
1.2     ! albertel  759: }
        !           760: 
        !           761: ###########################################################
        !           762: # classlMerge
        !           763: ###########################################################
        !           764: ###########################################################
        !           765: ###########################################################
        !           766: proc classlMerge { num } {
        !           767:     global gClassl 
        !           768: 
        !           769:     set filename [tk_getOpenFile -title "Select a File to merge in"]
        !           770: 
        !           771:     if { $filename == "" } { return }
        !           772:     set fileId [open $filename "r"]
        !           773:     set maxlines [lindex [exec wc -l $filename] 0]
        !           774:     set linenum 0
        !           775:     set newentries 0
        !           776:     displayStatus "Merging $filename" both $num
        !           777:     set aline [gets $fileId]
        !           778:     while {![eof $fileId]} {
        !           779: 	incr linenum
        !           780: 	set found 0
        !           781: 	set stunum [string range $aline 14 22]
        !           782: 	set max [$gClassl($num) index end]
        !           783: 	for {set i 0} { $i < ($max)} {incr i} {
        !           784: 	    set tmp [string range [$gClassl($num) get $i] 14 22]
        !           785: 	    if { [regexp -nocase $stunum $tmp] } { 
        !           786: 		set found 1
        !           787: 		break 
        !           788: 	    }
        !           789: 	}
        !           790: 	if { !$found } { 
        !           791: 	    incr newentries
        !           792: 	    $gClassl($num) insert end $aline 
        !           793: 	}
        !           794: 	updateStatusBar [expr $linenum/double($maxlines)] $num
        !           795: 	set aline [gets $fileId]
        !           796:     }    
        !           797:     removeStatus $num
        !           798:     if { $newentries != 0 } { 
        !           799: 	$gClassl($num) see $max 
        !           800: 	$gClassl($num) selection set $max
        !           801:     }
        !           802:     displayMessage "Added $newentries students."
1.1       albertel  803: }

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