Annotation of capa/capa51/GUITools/quizzer.tcl, revision 1.13
1.1 albertel 1: ###########################################################
2: # quizzer.tcl -
3: # Copyright Guy Albertelli II 1996
4: ###########################################################
5: set gTclVer 4.0
6:
7: ###########################################################
8: # createControlWindow
9: ###########################################################
10: # Creates the menu window
11: ###########################################################
12: # Arguments: none
13: # Returns: nothing
14: ###########################################################
15: proc createControlWindow {} {
16: global gPrefs gDate gFind gChanged gWindowMenu gStudentSelection gFile \
17: gUniqueNumber gXdviOpt gHeaderQCount gDir gHintVal gTryVal gProbVal \
18: gPutLine gQuizTemp gCapaConfig gStopPrinting gFindList gFirstTime \
19: gRefChanged gChangedLast gCreateImportLinks gFasterParsing
20:
21: after 500 { dateUpdate }
22: after 1000 { cleanWindowList }
23:
24: set gFasterParsing 1
25: set gFirstTime 1
26: set gPrefs(info) "Problem"
27: set gPrefs(TeXHeader) ""
28: set gPrefs(TeXFooter) ""
29: set gFind(find) ""
30: set gFind(replace) ""
31: set gFind(findOption) "-nocase"
32: set gFind(scope) File
33: set gChanged 0
34: set gChangedLast 0
35: trace variable gChanged w updateChangeStatus
36: trace variable gRefChanged w updateChangeStatus
37: set gStudentSelection(type) "Random"
38: set gStudentSelection(random) "1"
39: set gStudentSelection(studentNumber) ""
40: set gStudentSelection(studentName) ""
41: set gFile ""
42: set gUniqueNumber 1
43: set gXdviOpt "-geometry 800x650"
44: set gHeaderQCount 0
45: set gPutLine 1
46: set gTryVal 99
47: set gHintVal 1
48: set gProbVal 1
49: set gStopPrinting 0
50: set gDir(class) [pwd]
51: set gDir(import) [pwd]
52: set gDir(include) [pwd]
53: set gDir(reference) [pwd]
54: set gQuizTemp "true"
55: set gFindList(files) ""
56: set gFindList(refNum) ""
57: set gCreateImportLinks 1
58: set gCapaConfig(IMP_color) #0000ff
59: set gCapaConfig(comment_color) #008400
60: set gCapaConfig(Printer_selected) "0"
61: set gCapaConfig(latex_command) "latex"
62: set gCapaConfig(qzparse_command) "qzparse"
63: set gCapaConfig(dvips_command) "dvips"
64: set gCapaConfig(xdvi_command) "xdvi"
65: set gCapaConfig(lprOneSided_command) "lpr "
66: set gCapaConfig(lprTwoSided_command) ""
67: set gCapaConfig(printer_option) ""
68: set gCapaConfig(standardQuizzerHeader) "//CAPA system software is copyrighted by Michigan State University.\n//By using these materials, the User agrees to:\n//1) Protect the source code files from unauthorized copying.\n//2) Limit access of the source material to teaching staff.\n//3) The User is free to mix, cut and paste, modify, adapt, delete,\n// improve, etc. the problems and graphics for his/her own use.\n//\n/IMP \"../Tools/StdMacros\"\n/IMP \"../Tools/StdUnits\"\n/IMP \"../Tools/StdConst\"\n/IMP \"HWTop\"\n"
69:
70:
71: wm withdraw .
72:
73: # there is code later on that depends upon .main existing and being visable
74: set menuFrame [menu .main -tearoff 0 -type tearoff ]
75:
76: wm title $menuFrame "Quizzer"
77:
78: $menuFrame post 0 0
79:
80: wm geometry $menuFrame "+0+20"
81: $menuFrame add command -label "Quizzer" -foreground grey85 -background \
82: black -state disabled
83: $menuFrame add command -label "Info" -command { createInfoWindow }
84: $menuFrame add cascade -label "File" -menu $menuFrame.file
85: #$menuFrame add cascade -label "Edit .qz" -menu $menuFrame.edit
86: #$menuFrame add cascade -label "Find" -menu $menuFrame.find
87: $menuFrame add command -label "Prefs" -command { createPrefsWindow }
88: $menuFrame add cascade -label "Windows" -menu $menuFrame.windows
89: $menuFrame add command -label "Create .dvi" -command {
90: studentSelectWindow createDvi } -accelerator "Alt+D"
91: bind all <Alt-Shift-D> "studentSelectWindow createDvi"
92: $menuFrame add command -label "Analyze Set" -command {
93: analyzeSet } -accelerator "Alt+A"
94: bind all <Alt-Shift-A> "analyzeSet"
95: $menuFrame add command -label "Print" -command { printWindow }
96: $menuFrame add command -label "Remap" -command { createRemapWindow }
97: $menuFrame add command -label "Xdvi Options" -command { createXdviOpt }
98: #$menuFrame add command -label "Change font" -command { changeFont }
99: $menuFrame add command -label "Quit" -command { quit } \
100: -accelerator "Alt+q"
101: bind all <Alt-q> quit
102: bind $menuFrame <Destroy> "quit 1"
103:
104: set file [menu $menuFrame.file -tearoff 1 ]
105: set edit [menu $menuFrame.edit -tearoff 1 ]
106: #set find [menu $menuFrame.find -tearoff 1 ]
107: set windows [menu $menuFrame.windows -tearoff 1 ]
108: set gWindowMenu $windows
109:
110: $file add command -label "Set.qz File" -foreground grey50 -background \
111: black -state disabled
112: $file add command -label "New" -command {
113: createEditingWindow
114: pickCapaConfig
115: } -accelerator "Alt+n"
116: bind all <Alt-n> {
117: createEditingWindow
118: pickCapaConfig
119: }
120: $file add command -label "Open" -command { openDocument } -accelerator "Alt+o"
121: bind all <Alt-o> openDocument
122: $file add command -label "Save" -command { saveDocument } -accelerator "Alt+s"
123: # binding moved to the creation of the editwindow
124: # bind $menuFrame <Alt-s> saveDocument
125: $file add command -label "Save As..." -command { saveDocument 1 } \
126: -accelerator "Alt+S"
127: # binding moved to the creation of the editwindow
128: # bind $menuFrame <Alt-Shift-s> { saveDocument 1 }
129: $file add command -label "Delete" -command { deleteFile 0 }
130: $file add command -label "Close" -command { closeDocument } -accelerator "Alt+w"
131: # binding moved to the creation of the editwindow
132: # bind .main <Alt-w> closeDocument
133: $file add command -label "Reference File" -foreground grey90 -background \
134: black -state disabled
135: $file add command -label "New Reference File..." \
136: -command { newReferenceFile } -accelerator "Alt+t"
137: bind all <Alt-t> openReferenceFile
138: $file add command -label "Open Reference File..." \
139: -command { openReferenceFile } -accelerator "Alt+r"
140: bind all <Alt-r> openReferenceFile
141: $file add command -label "Open capa.config" \
142: -command { openReferenceFile capa.config }
143:
144: $edit add command -label "Cut" -command { cut } -accelerator "Alt+x"
145: # binding moved to the creation of the editwindow
146: # bind $menuFrame <Alt-x> cut
147: $edit add command -label "Copy" -command { copy } -accelerator "Alt+c"
148: # binding moved to the creation of the editwindow
149: # bind $menuFrame <Alt-c> copy
150: $edit add command -label "Paste" -command { paste } -accelerator "Alt+v"
151: # binding moved to the creation of the editwindow
152: # bind .main <Alt-v> paste
153: $edit add command -label "Select All " -command { selectAll } \
154: -accelerator "Alt+a"
155: # binding moved to the creation of the editwindow
156: # bind $menuFrame <Alt-a> selectAll
157: $edit add separator
158: $edit add command -label "Undo" -command "undo 0" \
159: -accelerator "Alt+u"
160: # $edit add command -label "Redo" -command "redo $num"
161: $edit add separator
162: $edit add command -label "Find" -command { createFindWindow } \
163: -accelerator "Alt+f"
164: bind all <Alt-f> createFindWindow
165:
166: # $find add command -label "Find Panel.." -command { createFindWindow } \
167: -accelerator "Alt+f"
168: # bind all <Alt-f> createFindWindow
169: # $find add command -label "Find Next" -command { next }
170: # $find add command -label "Find Previous" -command { previous }
171: # $find add command -label "Enter Selecton" -command { enterSelection }
172: # $find add command -label "Jump to Selection" -command { jumpToSelection }
173: # $find add command -label "Line Range..." -command { createLineWindow } \
174: -accelerator "Alt+l"
175: # bind all <Alt-l> createLineWindow
176:
177: bind all <Alt-0> printInfo
178: bind all <Alt-KeyPress> { #unbind tkTraverseToMenu
179: }
180: bind all <Control-Tab> {tkTabToWindow [tk_focusPrev %W]}
181: catch {bind all <ISO_Left_Tab> {tkTabToWindow [tk_focusPrev %W]}}
182: catch {bind all <KP_Tab> {tkTabToWindow [tk_focusPrev %W]}}
183: trace variable gQuizTemp w "changeMenuStatus $menuFrame"
184: }
185:
186: ###########################################################
187: # changeMenuStatus
188: ###########################################################
189: # either enables or disable printing or creation of Dvi files
190: # based on the value of the gQuizTemp global
191: ###########################################################
192: # Argument: menuFrame (path name of the menu window)
193: # name1 (name of traced varaiable, gQuizTemp)
194: # name2 (empty argument from trace)
195: # op (tracing on writes so this should be "w")
196: # Returns : nothing
197: # Globals : gQuizTemp (r)
198: ###########################################################
199: proc changeMenuStatus { menuFrame name1 name2 op } {
200: global gQuizTemp
201: if { $gQuizTemp } {
202: $menuFrame entryconfigure 5 -state normal
203: $menuFrame entryconfigure 6 -state normal
204: } else {
205: $menuFrame entryconfigure 5 -state disabled
206: $menuFrame entryconfigure 6 -state disabled
207: }
208: }
209:
210: ###########################################################
211: # printInfo
212: ###########################################################
213: # gets called by Alt-0, used to print out variable while
214: # still running
215: ###########################################################
216: # Argument: none
217: # Returns : nothing
218: # Globals : auto_path
219: ###########################################################
220: proc printInfo { } {
221: global auto_path gUndo gRefText
222: set num [lindex [array names gRefText] 0]
223: set a "updateLocation 0"
224: puts [list Main2: [time $a 20000]]
225: set a "updateLocation $num"
226: puts [list Ref : [time $a 20000]]
227: }
228:
229: ###########################################################
230: # createXdviOpt
231: ###########################################################
232: ###########################################################
233: ###########################################################
234: proc createXdviOpt {} {
235: global gXdviOpt gWindowMenu
236:
237: if { [winfo exists .xdviOpt] } {
238: capaRaise .xdviOpt
239: return
240: }
241:
242: set xdviOpt [toplevel .xdviOpt]
243: $gWindowMenu add command -label "XdviOptions" -command "capaRaise $xdviOpt"
244: wm title $xdviOpt "Options for Xdvi"
245:
246: set messageFrame [frame $xdviOpt.msg]
247: message $xdviOpt.msg2 -text "Example: -geometry 800x700" -aspect 5000
248: set buttonFrame [frame $xdviOpt.buttons -bd 10]
249: pack $messageFrame $xdviOpt.msg2 $buttonFrame -side top -fill x
250:
251: message $messageFrame.msg -text "Options to xdvi:" -aspect 5000
252: entry $messageFrame.entry -textvariable gXdviOpt
253:
254: pack $messageFrame.msg $messageFrame.entry -side left -fill x
255:
256: button $buttonFrame.ok -text Dismiss -command "destroy $xdviOpt
257: removeWindowEntry XdviOptions" -underline 0
258: pack $buttonFrame.ok -side left
259: bind $xdviOpt <Destroy> "removeWindowEntry XdviOptions"
260: }
261:
262: ###########################################################
263: # createInfoWindow
264: ###########################################################
265: # creates the Information window
266: ###########################################################
267: # Arguments: None
268: # Returns: Nothing
269: # Globals: gDate - the variable containg the current date
270: # gWindowMenu - used to register the new window in the
271: # windows menu
272: # gVer - Stores the current version of Quizzer (set in
273: # C init code
274: ###########################################################
275: proc createInfoWindow {} {
276: global gDate gWindowMenu gVer gTclVer gCmd gCompileDate gUndoSize gUniqueNumber
277:
278: if { [winfo exists .about] } {
279: capaRaise .about
280: return
281: }
282:
283: set about [toplevel .about]
284: $gWindowMenu add command -label "About" -command "capaRaise $about"
285: wm title $about "About"
286:
287: label $about.l1 -font 12x24 -text "Quizzer $gVer" -pady 20
288: label $about.l4 -font 8x13 -text "Quizzer.tcl version $gTclVer" -pady 20
289: label $about.l6 -font 8x13 -text "$gCompileDate"
290: message $about.l2 -font 8x13 -text "Code by: Y. Tsai, G. Albertelli II Copyright Michigan State University Board of Trustees, 1992-1999, No Unauthorized Commercial Use" \
291: -pady 20 -aspect 300
292: label $about.l3 -font 8x13 -textvariable gDate
293: label $about.l5 -font 8x13 -textvariable gCmd
294: label $about.l7 -font 8x13 -textvariable gUndoSize
295: label $about.l8 -font 8x13 -textvariable gUniqueNumber
296:
297: button $about.close -text "Close" -command "destroy $about
298: removeWindowEntry About"
299:
300: pack $about.l1 $about.l4 $about.l6 $about.l2 $about.l3 $about.l5 $about.l7 $about.l8\
301: $about.close -side top
302: bind $about <Destroy> "removeWindowEntry About"
303: Centre_Dialog $about default
304: }
305:
306: ###########################################################
307: # enterSelection
308: ###########################################################
309: ###########################################################
310: ###########################################################
311: proc enterSelection {} {
312: global gTextWindow gFind
313: if { [catch {set gTextWindow}] } { return }
314: if { ![winfo exists $gTextWindow] } { return }
315:
316: createFindWindow
317: catch {set gFind(find) [$gTextWindow get sel.first sel.last]}
318: }
319:
320: ###########################################################
321: # jumpToSelection
322: ###########################################################
323: ###########################################################
324: ###########################################################
325: proc jumpToSelection {} {
326: global gTextWindow
327: catch {$gTextWindow see sel.first}
328: }
329:
330: proc cut {} {global gTextWindow;tk_textCut $gTextWindow}
331: proc copy {} {global gTextWindow;tk_textCopy $gTextWindow}
332: proc paste {} {global gTextWindow;tk_textPaste $gTextWindow}
333:
334: ###########################################################
335: # selectAll
336: ###########################################################
337: ###########################################################
338: ###########################################################
339: proc selectAll { { refNum 0 } } {
340: global gTextWindow gRefText
341:
342: if { $refNum } { set window $gRefText($refNum) } else {
343: catch {set window $gTextWindow}
344: }
345: if { ![winfo exists $window] } { return }
346: $window tag add sel 0.0 end
347: }
348:
349: ###########################################################
350: # creatEditingWindow
351: ###########################################################
352: ###########################################################
353: # Arguments: none
354: # Returns: a one if the Editing window existed and a zero
355: # if it created a new window
356: # Globals:
357: ###########################################################
358: proc createEditingWindow { {setupUndo 1} } {
359: global gEditWindow gPreviewMode gTextWindow gSetNumberText gFile \
360: gWindowMenu gNumberParsedText gLineNumberGoto gUndo \
361: gCharacterNumberGoto gLineNumberGoto gClosedDocument \
362: gPreviewButton gFirstTime
363:
364: if { [winfo exists .editwindow] } {
365: capaRaise .editwindow
366: return 1
367: }
368: set gFirstTime 1
369:
370: set gEditWindow [toplevel .editwindow]
371: $gWindowMenu add command -label "$gFile" -command "capaRaise $gEditWindow"
372: wm title $gEditWindow $gFile
373: set gClosedDocument 0
374: set editWindow [frame $gEditWindow.frame -borderwidth 10]
375:
376: pack $editWindow -expand 1 -fill both
377:
378: set editTop [frame $editWindow.editTop]
379: set editBottom [frame $editWindow.editBottom]
380:
381: pack $editTop $editBottom -side top
382: pack configure $editBottom -expand 1 -fill both
383:
384: set menuFrame [frame $editTop.menu -borderwidth 2 -relief raised]
385: set assignInfo [frame $editTop.assignInfo -borderwidth 4 -relief groove]
386: set mode [frame $editTop.mode -borderwidth 4 -relief groove]
387: set buttonAndGoto [frame $editTop.buttonAndGoto ]
388: pack $menuFrame $assignInfo $mode $buttonAndGoto -side left
389: pack configure $menuFrame -anchor n
390:
391: menubutton $menuFrame.edit -text Edit -menu $menuFrame.edit.m
392: pack $menuFrame.edit -side left
393:
394: set edit [ menu $menuFrame.edit.m ]
395: $edit add command -label "Cut" -command { cut } -accelerator "Alt+x"
396: $edit add command -label "Copy" -command { copy } -accelerator "Alt+c"
397: $edit add command -label "Paste" -command { paste } -accelerator "Alt+v"
398: $edit add command -label "Select All " -command { selectAll } -accelerator "Alt+a"
399: $edit add separator
400: $edit add command -label "Undo" -command "undo 0" -accelerator "Alt+u"
401: $edit add separator
402: $edit add command -label "Find" -command { createFindWindow } -accelerator "Alt+f"
403: bind all <Alt-f> createFindWindow
404:
405: set buttons [frame $buttonAndGoto.buttons ]
406: set gotoFrame [ frame $buttonAndGoto.gotoFrame ]
407: pack $buttons $gotoFrame -side top
408:
409: set button1 [frame $buttons.button1]
410: set button2 [frame $buttons.button2]
411: pack $button1 $button2 -side top
412:
413: set gPreviewButton [button $button1.preview -text "Preview" -command \
414: { studentSelectWindow createPreviewWindow }]
415: button $button1.dbHeader -text "DB Header" -command createDBHeader
416: button $button1.include -text "Include" -command includeFile
417: pack $button1.preview $button1.dbHeader $button1.include -side left
418:
419: button $button2.header -text "Std. Header" \
420: -command insertStandardHeader
421: button $button2.import -text "Import" -command importFile
422: button $button2.end -text "Endline" -command insertEndline
423: pack $button2.header $button2.import $button2.end -side left
424:
425: label $gotoFrame.msg -text "Current Line:"
426: label $gotoFrame.current -textvariable gLineNumber
427: entry $gotoFrame.line -width 8 -textvariable gLineNumberGoto
428: bind $gotoFrame.line <KeyPress-Return> "gotoLine"
429: button $gotoFrame.button -text "Goto" -command "gotoLine"
430: pack $gotoFrame.msg $gotoFrame.current $gotoFrame.line \
431: $gotoFrame.button -side left
432: # variable used by gotoLine, needs to be set if it doesn't exist
433: if { [ catch { set gCharacterNumberGoto } ] } {
434: set gCharacterNumberGoto ""
435: }
436:
437: label $assignInfo.time -textvariable gDate
438: set setNum [frame $assignInfo.setNum -borderwidth 2]
439: set probsParsed [frame $assignInfo.probsParsed -borderwidth 2]
440:
441: pack $assignInfo.time $setNum $probsParsed -side top
442: pack configure $setNum $probsParsed -anchor e
443:
444: message $setNum.msg -text "Problem Set Number" -aspect 10000
445: set setNumberWindow [message $setNum.num -relief sunken -width 70 \
446: -textvariable gSetNumberText]
447:
448: pack $setNum.num $setNum.msg -side right -anchor e
449:
450: label $probsParsed.msg -text "Number of Questions Parsed"
451: set numberParsedWindow [label $probsParsed.num -relief sunken \
452: -textvariable gNumberParsedText]
453:
454: pack $probsParsed.num $probsParsed.msg -side right -anchor e
455:
456: message $mode.msg -text "Mode" -aspect 10000
457: radiobutton $mode.enscript -text "Enscript" -value "Enscript" \
458: -variable gPreviewMode
459: radiobutton $mode.tex -text "TeX" -value "TeX" -variable gPreviewMode
460: radiobutton $mode.web -text "Web" -value "Web" -variable gPreviewMode
461:
462: pack $mode.msg $mode.enscript $mode.tex $mode.web -side top
463: pack configure $mode.enscript $mode.tex $mode.web -anchor w
464: set gPreviewMode Enscript
465:
466: scrollbar $editBottom.scroll -orient vertical -command \
467: "$editBottom.text yview"
468: set gTextWindow [text $editBottom.text -yscrollcommand \
469: "$editBottom.scroll set" -wrap char -height 40]
470:
471: pack $editBottom.scroll $editBottom.text -side left -expand 0
472: pack configure $editBottom.scroll -expand 0 -fill y
473: pack configure $editBottom.text -expand true -fill both
474:
475: if { $setupUndo} {
476: rename $gTextWindow .$gTextWindow
477: trackChanges $gTextWindow 0
478: set gUndo(0) 0
479: set gUndo(0.cur) 0
480: }
481:
482: bind $gTextWindow <Alt-s> saveDocument
483: bind $gTextWindow <Alt-Shift-s> { saveDocument 1 }
484: bind $gEditWindow <Alt-w> closeDocument
485: # bind $gEditWindow <Destroy> "closeDocument 1"
486: wm protocol $gEditWindow WM_DELETE_WINDOW "closeDocument 1"
487: bind $gTextWindow <Alt-x> "tk_textCut %W"
488: bind $gTextWindow <Alt-c> "tk_textCopy %W"
489: bind $gTextWindow <Alt-v> "tk_textPaste %W"
490: bind $gTextWindow <Alt-a> selectAll
491: bind $gTextWindow <Alt-u> "undo 0"
492: addFindList
493: Centre_Dialog $gEditWindow default
494:
495: createImportLinks 0 0.0 end
496: return 0
497: }
498:
499: ###########################################################
500: # includeFile
501: ###########################################################
502: ###########################################################
503: ###########################################################
504: proc includeFile {} {
505: global gTextWindow gDir
506:
507: if { [makeSure "Is the cursor in the correct position?"] == "Cancel" } {
508: return
509: }
510:
511: # if { $gDir(include) == "." } { set gDir(include) [pwd] }
512: set file [tk_getOpenFile -filetypes \
513: { { {All Files} {"*"} } { {Quizzer} {"*.qz"} } } \
514: -title "Select the proper file" \
515: -initialdir "$gDir(include)" ]
516: if { $file == "" } { return }
517: set gDir(include) [file dirname $file]
518:
519: if { $file == "" } { return }
520:
521: set fileId [open $file "r"]
522:
523: $gTextWindow insert insert [read $fileId [file size $file]]
524: }
525:
526: ###########################################################
527: # insertStandardHeader
528: ###########################################################
529: ###########################################################
530: ###########################################################
531: proc insertStandardHeader {} {
532: global gTextWindow gCapaConfig
533:
534: if { [makeSure "Is the cursor in the correct position?"] == "Cancel" } {
535: return
536: }
537: $gTextWindow insert insert $gCapaConfig(standardQuizzerHeader)
538: }
539:
540: ###########################################################
541: # importFile
542: ###########################################################
543: ###########################################################
544: ###########################################################
545: proc importFile {} {
546: global gTextWindow gDir gProbVal gTryVal gHintVal gPutLine
547:
548: if { [makeSure "Is the cursor in the correct position?"] == "Cancel" } {
549: return
550: }
551:
552: # if { $gDir(import) == "." } { set gDir(import) [pwd] }
553: set file [tk_getOpenFile -filetypes \
554: { { {All Files} {"*"} } { {Quizzer} {"*.qz"} } } \
555: -title "Select the proper file" -initialdir "$gDir(import)" ]
556: if { $file == "" } { return }
557: set gDir(import) [file dirname $file]
558:
559:
560: if { [getProbValTryVal] == "Cancel" } { return }
561:
562: $gTextWindow insert insert "//\n/BEG prob_val=$gProbVal\n/LET try_val=$gTryVal\n/LET hint_val=$gHintVal\n/DIS(\"$file\")\n/IMP \"$file\"\n"
563: if { $gPutLine } {
564: $gTextWindow insert insert "/DIS(stdline)\n"
565: } else {
566: $gTextWindow insert insert "/DIS(webonlyline)\n"
567: }
568: $gTextWindow see insert
569: }
570:
571: ###########################################################
572: # insertEndline
573: ###########################################################
574: ###########################################################
575: ###########################################################
576: proc insertEndline {} {
577: global gTextWindow
578:
579: if { [makeSure "Is the cursor in the correct position?"] == "Cancel" } {
580: return
581: }
582: $gTextWindow insert insert "/END(stdendline)\n"
583: }
584:
585: ###########################################################
586: # getProbValTryVal
587: ###########################################################
588: ###########################################################
589: ###########################################################
590: proc getProbValTryVal {} {
591: global gPrompt gProbVal gTryVal gHintVal gPutLine
592:
593: set dialog [toplevel .getProbValTryVal -borderwidth 10]
594: wm title $dialog "Getting Problem Value and Try Value"
595: wm geo $dialog "+200+200"
596: message $dialog.msg -text "Set the weight of the problem and the number of tries allowed." -aspect 700
597:
598: set gPrompt(result) ""
599: scale $dialog.probVal -orient horizontal -variable gProbVal \
600: -from 0 -to 9 -label "Problem Value" -length 150
601: scale $dialog.tryVal -orient horizontal -variable gTryVal \
602: -from 0 -to 99 -label "Try Value" -length 150
603: scale $dialog.hintVal -orient horizontal -variable gHintVal \
604: -from 1 -to 99 -label "Number of Tries Before Showing Hint" -length 150
605: set gPrompt(stdline.1) "Put a stdline after this problem."
606: set gPrompt(stdline.0) "Put a webonlyline after this problem."
607: checkbutton $dialog.putLine -variable gPutLine \
608: -width 38 \
609: -textvariable gPrompt(displayLine) \
610: -command { set gPrompt(displayLine) $gPrompt(stdline.$gPutLine) }
611: set gPrompt(displayLine) $gPrompt(stdline.$gPutLine)
612: set buttonFrame [frame $dialog.buttons -bd 10]
613: pack $dialog.msg $dialog.probVal $dialog.tryVal $dialog.hintVal $dialog.putLine \
614: $buttonFrame -side top -fill x
615:
616: button $buttonFrame.yes -text Import -command {set gPrompt(yes) 1} \
617: -underline 0
618: button $buttonFrame.cancel -text Cancel -command { set gPrompt(yes) 0 } \
619: -underline 0
620: pack $buttonFrame.yes $buttonFrame.cancel -side left
621:
622: bind $dialog <Alt-Key> break
623: bind $dialog <Destroy> "set gPrompt(yes) 0"
624: Centre_Dialog $dialog default
625: update
626:
627: focus $dialog
628: capaRaise $dialog
629: capaGrab $dialog
630: vwait gPrompt(yes)
631: capaGrab release $dialog
632: bind $dialog <Destroy> ""
633: destroy $dialog
634: if {$gPrompt(yes)} {
635: return Done
636: } else {
637: return Cancel
638: }
639: }
640:
641: ###########################################################
642: # updateDateBox
643: ###########################################################
1.13 ! albertel 644: # sticks the date information from gControlDates into the date listbox
1.1 albertel 645: ###########################################################
646: ###########################################################
647: proc updateDateBox { listbox } {
648: global gControlDates
649: $listbox delete 0 end
650: for {set i 0} {$i < [llength $gControlDates]} {incr i } {
651: set date [lindex $gControlDates $i]
652: if { $i != 0 } {
653: $listbox insert end [eval format {"%4d %4d %s %s %s"} $date]
654: } else {
655: $listbox insert end [eval format {" DEFAULT %s %s %s"} [lrange $date 2 end]]
656: }
657: }
658: }
659:
660: ###########################################################
661: # loadDates
662: ###########################################################
663: ###########################################################
664: ###########################################################
665: proc loadDates { listbox } {
666: global gControlDates
667: if { [catch {getHeaderInfo}]} {
668: displayError "That set.db does not exist"
1.13 ! albertel 669: } else {
! 670: if { [llength $gControlDates] > 2 } {
! 671: set gControlDates [linsert [lreverse [lrange $gControlDates 1 end]] 0 [lindex $gControlDates 0]]
! 672: }
! 673: }
1.1 albertel 674: updateDateBox $listbox
675: }
676:
677: ###########################################################
678: # deleteDate
679: ###########################################################
680: ###########################################################
681: ###########################################################
682: proc deleteDate { listbox } {
683: global gControlDates
684: if { [set a [$listbox index anchor]] != 0 } {
685: catch {$listbox delete anchor}
686: set gControlDates [lreplace $gControlDates $a $a]
687: } else {
688: displayError "You can not delete the default setting, only change it."
689: }
690: }
691:
692: ###########################################################
693: # checkHeaderForDefault
694: ###########################################################
695: ###########################################################
696: ###########################################################
697: proc checkHeaderForDefault { } {
698: global gControlDates
699: if { [lindex [lindex $gControlDates 0] 0] == 0 && \
700: [lindex [lindex $gControlDates 0] 1] == 0 } {
701: return 1
702: }
703: return 0
704: }
705:
706: ###########################################################
707: # dueAnswerOrder
708: ###########################################################
709: ###########################################################
710: ###########################################################
711: proc dueAnswerOrder { } {
712: global gDates
713: set duetime [clock scan "$gDates(duemonth)/$gDates(dueday)/$gDates(dueyear) $gDates(duehour):$gDates(dueminute)"]
714: set answertime [clock scan "$gDates(answermonth)/$gDates(answerday)/$gDates(answeryear) $gDates(answerhour):$gDates(answerminute)"]
715: if { $duetime > $answertime } { return 1 } { return 0 }
716: }
717:
718: ###########################################################
719: # checkDateFields
720: ###########################################################
721: ###########################################################
722: ###########################################################
723: proc checkDateFields { } {
724: global gDates
725:
726: set result 1
727: foreach kind { open due answer } {
728: foreach type { year month day hour minute } {
729: if { [validate $kind $type] != 1 } {
730: return $kind$type
731: }
732: }
733: }
734: if { [validate "" durationhour] != 1 } { return durationhour }
735: if { [validate duration minute] != 1 } { return durationminute }
736: if { [catch { expr $gDates(sectionstart) }] } { return sectionstart } else {
737: if {[string length $gDates(sectionstart)] <1} { return sectionstart } else {
738: if { [catch { expr $gDates(sectionend) }] } { return sectionend } else {
739: if {[string length $gDates(sectionend)] <1} { return sectionend }
740: }
741: }
742: }
743: return $result
744: }
745:
746: ###########################################################
747: # validate
748: ###########################################################
749: ###########################################################
750: ###########################################################
751: proc validate { kind type {newvalue novalue} } {
752: global gDates
753: #tcl interprets all strings of digits with 0 as the first number as being
754: #in octal, need to prevent this from causing an error
755: if { $newvalue == "novalue" } {
756: set temp $gDates($kind$type)
757: set lowfail -1
758: } else {
759: if { $newvalue == "" } { return 1 }
760: set temp $newvalue
761: set lowfail 1
762: }
763: if { [string length $temp] > 1 && [string index $temp 0] == 0 } {
764: set test [string range $temp 1 end]
765: } else {
766: set test $temp
767: }
768: if { [catch { expr $test }] } { return 0 } else {
769: switch $type {
770: year {
771: if { $test < 1990 } { return $lowfail }
772: if { $test > 9999 } { return 0 }
773: if { [string length $temp] > 4 } { return 0 }
774: }
775: month {
776: if { $test < 1 } { return $lowfail }
777: if { $test > 12 } { return 0 }
778: if { [string length $temp] > 2 } { return 0 }
779: }
780: day {
781: if { $test < 1 } { return $lowfail }
782: if { $test > 31 } { return 0 }
783: if { [string length $temp] > 2 } { return 0 }
784: }
785: hour {
786: if { $test < 0 } { return 0 }
787: if { $test > 23 } { return 0 }
788: if { [string length $temp] > 2 } { return 0 }
789: }
790: minute {
791: if { $test < 0 } { return 0 }
792: if { $test > 59 } { return 0 }
793: if { [string length $temp] > 2 } { return 0 }
794: }
795: durationhour {
796: if { $test < 0 } { return 0 }
797: if { [string length $temp] > 4 } { return 0 }
798: }
799: }
800: }
801: return 1
802: }
803:
804: ###########################################################
805: # getday
806: ###########################################################
807: ###########################################################
808: ###########################################################
809: proc getday { kind } {
810: global gDates
811: if { [set day $gDates([set kind]day)] != ""} {
812: if { [set month $gDates([set kind]month)] != ""} {
813: if { [set year $gDates([set kind]year)] != ""} {
814: if { [ catch { set gDates($kind.dayoweek) \
815: [clock format [clock scan "$month/$day/$year"] \
816: -format %a] } error ] } {
817: set gDates($kind.dayoweek) ""
818: }
819: return
820: }
821: }
822: }
823: set gDates($kind.dayoweek) ""
824: }
825:
826: ###########################################################
1.13 ! albertel 827: # moveUpDate
! 828: ###########################################################
! 829: ###########################################################
! 830: ###########################################################
! 831: proc moveUpDate { listbox } {
! 832: global gControlDates gDates
! 833: if { ![winfo exists $listbox] } { return }
! 834: if { [set which [$listbox curselection]] == "" } {
! 835: displayMessage "Please select a date to move."
! 836: return
! 837: }
! 838: if { $which > 1 } {
! 839: set element [lindex $gControlDates $which]
! 840: set gControlDates [lreplace $gControlDates $which $which]
! 841: set gControlDates [linsert $gControlDates [expr $which - 1] $element]
! 842: updateDateBox $listbox
! 843: $listbox selection set [expr {$which - 1}]
! 844: $listbox see [expr {$which -1}]
! 845: }
! 846: }
! 847:
! 848: ###########################################################
! 849: # moveDownDate
! 850: ###########################################################
! 851: ###########################################################
! 852: ###########################################################
! 853: proc moveDownDate { listbox } {
! 854: global gControlDates gDates
! 855: if { ![winfo exists $listbox] } { return }
! 856: if { [set which [$listbox curselection]] == "" } {
! 857: displayMessage "Please select a date to move."
! 858: return
! 859: }
! 860: if { ($which > 0) && ($which < ([llength $gControlDates]-1)) } {
! 861: set element [lindex $gControlDates $which]
! 862: set gControlDates [lreplace $gControlDates $which $which]
! 863: set gControlDates [linsert $gControlDates [expr $which + 1] $element]
! 864: updateDateBox $listbox
! 865: $listbox selection set [expr {$which + 1}]
! 866: $listbox see [expr {$which + 1}]
! 867: }
! 868: }
! 869:
! 870: ###########################################################
1.1 albertel 871: # enableDateValidation
872: ###########################################################
873: ###########################################################
874: ###########################################################
875: proc enableDateValidation { toplevel } {
876: global gDates
877: set dateFrame $toplevel.dateFrame
878: foreach type { open due answer } {
879: $dateFrame.[set type]date.year configure -validate key \
880: -validatecommand "validate $type year %P"
881: $dateFrame.[set type]date.month configure -validate key \
882: -validatecommand "validate $type month %P"
883: $dateFrame.[set type]date.day configure -validate key \
884: -validatecommand "validate $type day %P"
885: $dateFrame.[set type]time.hour configure -validate key \
886: -validatecommand "validate $type hour %P"
887: $dateFrame.[set type]time.minute configure -validate key \
888: -validatecommand "validate $type minute %P"
889: }
890: $gDates(optFrame).duration.hour configure -validate key \
891: -validatecommand "validate {} durationhour %P"
892: $gDates(optFrame).duration.minute configure -validate key \
893: -validatecommand "validate duration minute %P"
894:
895: }
896:
897: ###########################################################
898: # addDateOptions
899: ###########################################################
900: ###########################################################
901: ###########################################################
902: proc addDateOptions {} {
903: global gDates
904: pack $gDates(optFrame2)
905: $gDates(optBut) configure -text "Less Options" -command "removeDateOptions"
906: }
907:
908: ###########################################################
909: # removeDateOptions
910: ###########################################################
911: ###########################################################
912: ###########################################################
913: proc removeDateOptions {} {
914: global gDates
915: pack forget $gDates(optFrame2)
916: $gDates(optBut) configure -text "More Options" -command "addDateOptions"
917: }
918:
919: ###########################################################
920: # createDateDialog
921: ###########################################################
922: ###########################################################
923: ###########################################################
924: proc createDateDialog { toplevel makedefault } {
925: global gDates gPrompt2
926:
927: catch [unset gDates]
928:
929: set infoFrame [frame $toplevel.infoFrame]
930: set sectionFrame [frame $toplevel.sectionFrame -borderwidth 4]
931: set dateFrame [frame $toplevel.dateFrame]
932: set optionsFrame [frame $toplevel.optionsFrame]
933: set buttonFrame [frame $toplevel.buttonFrame]
934: pack $infoFrame $sectionFrame $dateFrame $buttonFrame -side top
935:
936: if { $makedefault } {
937: label $sectionFrame.sectionl -text "Default value for all sections:"
938: pack $sectionFrame.sectionl
939: set gDates(sectionstart) 0
940: set gDates(sectionend) 0
941: } else {
942: grid [label $sectionFrame.sectionl -text "Dates and times are for"] \
943: -column 0 -columnspan 4 -row 0
944: grid [label $sectionFrame.section12 -text "section:"] -column 0 -row 1
945: grid [entry $sectionFrame.start -width 3 -textvariable gDates(sectionstart)] \
946: -column 1 -row 1
947: grid [label $sectionFrame.sectionl3 -text "through section: "] -column 2 -row 1
948: grid [entry $sectionFrame.end -width 3 -textvariable gDates(sectionend)] \
949: -column 3 -row 1
950: button $buttonFrame.getdefaults -text "Get Defaults" -command \
951: "setValues 0 0;enableDateValidation $toplevel"
952: pack $buttonFrame.getdefaults -side left
953: }
954:
955: grid [label $dateFrame.datel -text "Date"] -column 1 -row 0
956: grid [label $dateFrame.timel -text "Time"] -column 2 -row 0
957: grid [label $dateFrame.helpd -text "yyyy/mm/dd"] -column 1 -row 1
958: grid [label $dateFrame.helpt -text "hh:mm"] -column 2 -row 1
959: grid [label $dateFrame.openl -text "Open"] -column 0 -row 2
960: grid [set openDate [frame $dateFrame.opendate -borderwidth 2 -relief sunken]] -column 1 -row 2
961: grid [set openTime [frame $dateFrame.opentime -borderwidth 2 -relief sunken]] -column 2 -row 2
962: grid [label $dateFrame.openday -textvariable gDates(open.dayoweek)] -column 3 -row 2
963: grid [label $dateFrame.duel -text "Due"] -column 0 -row 3
964: grid [set dueDate [frame $dateFrame.duedate -borderwidth 2 -relief sunken]] -column 1 -row 3
965: grid [set dueTime [frame $dateFrame.duetime -borderwidth 2 -relief sunken]] -column 2 -row 3
966: grid [label $dateFrame.dueday -textvariable gDates(due.dayoweek)] -column 3 -row 3
967: grid [label $dateFrame.answerl -text "Answer"] -column 0 -row 4
968: grid [set answerDate [frame $dateFrame.answerdate -borderwidth 2 -relief sunken]] -column 1 -row 4
969: grid [set answerTime [frame $dateFrame.answertime -borderwidth 2 -relief sunken]] -column 2 -row 4
970: grid [label $dateFrame.ansday -textvariable gDates(answer.dayoweek)] -column 3 -row 4
971:
972:
973: foreach type { open due answer } {
974: entry [set [set type]Date].year -width 4 -textvariable gDates([set type]year)
975: label [set [set type]Date].sl1 -text "/"
976: entry [set [set type]Date].month -width 2 -textvariable gDates([set type]month)
977: label [set [set type]Date].sl2 -text "/"
978: entry [set [set type]Date].day -width 2 -textvariable gDates([set type]day)
979: entry [set [set type]Time].hour -width 2 -textvariable gDates([set type]hour)
980: label [set [set type]Time].colon -text ":"
981: entry [set [set type]Time].minute -width 2 -textvariable gDates([set type]minute)
982: pack [set [set type]Date].year [set [set type]Date].sl1 \
983: [set [set type]Date].month [set [set type]Date].sl2 \
984: [set [set type]Date].day -side left
985: pack [set [set type]Time].hour [set [set type]Time].colon \
986: [set [set type]Time].minute -side left
987: }
988:
989: set optionsFrame3 [frame $optionsFrame.options]
990: set gDates(optFrame) [ set optionsFrame2 [frame $optionsFrame3.options ] ]
991: pack $gDates(optFrame) $optionsFrame3
992: set gDates(optFrame2) $optionsFrame
993:
994: set durationFrame [frame $optionsFrame2.duration]
995: checkbutton $optionsFrame2.view -variable gDates(viewbetween) \
996: -text "Allow Viewing between Due and Answer dates"
997: checkbutton $optionsFrame2.response -variable gDates(inhibitresponse) \
998: -text "Inhibit Correct/Incorrect response \n(normally only for exams/quizzes)"
999: pack $durationFrame $optionsFrame2.view $optionsFrame2.response -side top
1.7 albertel 1000: set gDates(viewbetween) 0
1.1 albertel 1001: set gDates(inhibitresponse) 0
1002:
1003: label $durationFrame.label -text "Duration"
1004: entry $durationFrame.hour -width 4 -textvariable gDates(durationhour)
1005: label $durationFrame.colon -text ":"
1006: entry $durationFrame.minute -width 2 -textvariable gDates(durationminute)
1007: pack $durationFrame.label $durationFrame.hour $durationFrame.colon \
1008: $durationFrame.minute -side left
1009: set gDates(durationhour) 0
1010: set gDates(durationminute) 0
1011:
1012: button $buttonFrame.help -text "Help" -command "showHelp dateEntry"
1013: button $buttonFrame.set -text "Ok" -command "set gPrompt2(ok) 1"
1014: button $buttonFrame.cancel -text "Cancel" -command "set gPrompt2(ok) 0"
1015: set gDates(optBut) [ button $buttonFrame.options -text "More Options" \
1016: -command "addDateOptions"]
1017: pack $buttonFrame.help $buttonFrame.set $buttonFrame.cancel $buttonFrame.options \
1018: -side left
1019: bind $toplevel <Destroy> "set gPrompt2(ok) 0"
1020: bind $toplevel <KeyPress> "getday open;getday due;getday answer"
1021: bind $toplevel <Return> {tkTabToWindow [tk_focusNext %W]}
1022: }
1023:
1024: ###########################################################
1025: # addCurrentDates
1026: ###########################################################
1027: ###########################################################
1028: ###########################################################
1029: proc addCurrentDates { listbox makedefault {which -1} } {
1030: global gControlDates gDates
1031: foreach kind { open due answer } {
1032: foreach type { year month day hour minute } {
1033: #tcl interprets all strings of digits with 0 as the first number as
1034: #being in octal, need to prevent this from causing an error
1035: if { [string length $gDates($kind$type)] > 1 && \
1036: [string index $gDates($kind$type) 0] == 0 } {
1037: set gDates($kind$type) [string range $gDates($kind$type) 1 end]
1038: }
1039: }
1040: }
1041: set datestring [list $gDates(sectionstart) $gDates(sectionend) \
1042: [format "%04d/%02d/%02d %02d:%02d" $gDates(openyear) \
1043: $gDates(openmonth) $gDates(openday) \
1044: $gDates(openhour) $gDates(openminute) ] \
1045: [format "%04d/%02d/%02d %02d:%02d" $gDates(dueyear) \
1046: $gDates(duemonth) $gDates(dueday) \
1047: $gDates(duehour) $gDates(dueminute) ] \
1048: [format "%04d/%02d/%02d %02d:%02d" $gDates(answeryear) \
1049: $gDates(answermonth) $gDates(answerday) \
1050: $gDates(answerhour) $gDates(answerminute) ] \
1051: [format "%d:%d" $gDates(durationhour) $gDates(durationminute)] \
1052: $gDates(inhibitresponse) $gDates(viewbetween) ]
1053: if { $makedefault } {
1054: if { ([info globals gControlDates] == "") || ($gControlDates == "") } {
1055: set gControlDates [list $datestring]
1056: } else {
1057: set gControlDates [lreplace $gControlDates 0 0 $datestring]
1058: }
1059: } else {
1060: if { $which > -1 } {
1061: # puts "$gControlDates=$which=$which=$datestring"
1062: set gControlDates [lreplace $gControlDates $which $which $datestring]
1063: } else {
1064: lappend gControlDates $datestring
1065: }
1066: }
1067: updateDateBox $listbox
1068: }
1069:
1070: ###########################################################
1071: # setValues
1072: ###########################################################
1073: ###########################################################
1074: ###########################################################
1075: proc setValues { which {doSections 1} } {
1076: global gControlDates gDates
1077: set datestring [lindex $gControlDates $which]
1078: if { $doSections } {
1079: set gDates(sectionstart) [lindex $datestring 0]
1080: set gDates(sectionend) [lindex $datestring 1]
1081: }
1082: foreach type {open due answer} element {2 3 4} {
1083: set gDates([set type]year) [lindex [split [lindex $datestring $element] "/" ] 0]
1084: set gDates([set type]month) [lindex [split [lindex $datestring $element] "/" ] 1]
1085: set gDates([set type]day) [lindex [split [lindex [lindex $datestring $element] 0] "/" ] 2]
1086: set gDates([set type]hour) [lindex [split [lindex [lindex $datestring $element] 1] ":" ] 0]
1087: set gDates([set type]minute) [lindex [split [lindex [lindex $datestring $element] 1] ":" ] 1]
1088: }
1089: set gDates(durationhour) [lindex [split [lindex $datestring 5] ":" ] 0]
1090: set gDates(durationminute) [lindex [split [lindex $datestring 5] ":" ] 1]
1091: set gDates(inhibitresponse) [lindex $datestring 6]
1092: set gDates(viewbetween) [lindex $datestring 7]
1093: getday open
1094: getday due
1095: getday answer
1096: }
1097:
1098: ###########################################################
1099: # changeDate
1100: ###########################################################
1101: ###########################################################
1102: ###########################################################
1103: proc changeDate { listbox } {
1104: global gDates gPrompt2 gControlDates
1105:
1106: if { ![winfo exists $listbox] } { return }
1107: if { [winfo exists .adddate] } { return }
1108: if { [set which [$listbox index anchor]] == 0 } { set makedefault 1 } else {
1109: set makedefault 0 }
1110: if { $which == [$listbox index end] } {addDate $listbox;return}
1111: set changeDate [toplevel .changeDate]
1112: createDateDialog $changeDate $makedefault
1113: setValues $which
1114: enableDateValidation $changeDate
1115:
1116: if { $makedefault } {
1117: set gDates(sectionstart) 0
1118: set gDates(sectionend) 0
1119: }
1120:
1121: Centre_Dialog $changeDate default
1122: update
1123:
1124: focus $changeDate
1125: capaRaise $changeDate
1126: capaGrab $changeDate
1127: set done 0
1128: while { $done != 1 } {
1129: vwait gPrompt2(ok)
1130: if { $gPrompt2(ok) == 1 } {
1131: if { 1 != [set done [checkDateFields]] } {
1132: displayError "Please correct field: $done"
1133: set done 0
1134: } else {
1135: if { [dueAnswerOrder] } {
1136: if { "Yes" == [makeSure "Right now answers are available before an assignment is due. Would you like to change this?."]} {
1137: set done 0
1138: } else {
1139: set done 1
1140: }
1141: }
1142: }
1143: } else {
1144: set done 1
1145: }
1146: }
1147: capaGrab release $changeDate
1148: bind $changeDate <Destroy> ""
1149: destroy $changeDate
1150: if {$gPrompt2(ok) == 1 } {
1151: addCurrentDates $listbox $makedefault $which
1152: }
1153: return
1154: }
1155:
1156: ###########################################################
1157: # addDate
1158: ###########################################################
1159: ###########################################################
1160: ###########################################################
1161: proc addDate { listbox } {
1162: global gDates gPrompt2
1163:
1164: if { ![winfo exists $listbox ] } { return }
1165: if { [winfo exists .adddate ] } { return }
1166: if { [$listbox index end] == 0 } { set makedefault 1 } else { set makedefault 0 }
1167: set addDate [toplevel .adddate]
1168:
1169: createDateDialog $addDate $makedefault
1170: enableDateValidation $addDate
1171:
1172: Centre_Dialog $addDate default
1173: update
1174:
1175: focus $addDate
1176: capaRaise $addDate
1177: capaGrab $addDate
1178: set done 0
1179: while { $done != 1 } {
1180: vwait gPrompt2(ok)
1181: if { $gPrompt2(ok) == 1 } {
1182: if { 1 != [set done [checkDateFields]] } {
1183: displayError "Please correct field: $done"
1184: set done 0
1185: } else {
1186: if { [dueAnswerOrder] } {
1187: if { "Yes" == [makeSure "Right now answers are available before an assignment is due. Would you like to change this?."]} {
1188: set done 0
1189: } else {
1190: set done 1
1191: }
1192: }
1193: }
1194: } else {
1195: set done 1
1196: }
1197: }
1198: capaGrab release $addDate
1199: bind $addDate <Destroy> ""
1200: destroy $addDate
1201: if {$gPrompt2(ok) == 1 } {
1202: addCurrentDates $listbox $makedefault
1203: }
1204: return
1205: }
1206:
1207: ###########################################################
1208: # createDBHeader
1209: ###########################################################
1210: ###########################################################
1211: ###########################################################
1212: proc createDBHeader {} {
1213: global gNumberParsedText gPrompt gLoadHeaderSet gControlDates \
1.2 albertel 1214: gSetNumberText gHeaderQCount gEnableDiscussion gFile
1.1 albertel 1215:
1216: if { $gNumberParsedText == "" } {
1217: displayError "You must first preview the file before creating the \
1218: DB header."
1219: return
1220: }
1221:
1222: if { [winfo exists .headerPrompt] } {
1223: capaRaise .headerPrompt
1224: return
1225: }
1226:
1227: set dialog [toplevel .headerPrompt -borderwidth 10]
1228: wm geo $dialog "+200+200"
1229: wm title $dialog "Creating DB Header"
1230:
1231: message $dialog.msg -text "Header Information" -aspect 1000
1232: set loadFrame [frame $dialog.loadFrame -borderwidth 4 -relief sunken]
1233: set infoFrame [frame $dialog.infoFrame -borderwidth 4 -relief sunken]
1.13 ! albertel 1234: label $dialog.message -text "Later entries will override earlier entries"
1.2 albertel 1235: set optionFrame [frame $dialog.options]
1.1 albertel 1236: set buttonFrame [frame $dialog.buttons -bd 10]
1.13 ! albertel 1237: pack $dialog.msg $loadFrame $dialog.message $infoFrame $optionFrame \
! 1238: $buttonFrame -side top -fill x
1.1 albertel 1239:
1240: set legendFrame [frame $infoFrame.legendFrame]
1241: set listFrame [frame $infoFrame.listFrame]
1242: set commandFrame [frame $infoFrame.commandFrame]
1243: pack $legendFrame $listFrame $commandFrame -side top
1244:
1245: label $legendFrame.legend1 -text " Section# | Open | Due | Answer "
1246: label $legendFrame.legend2 -text "Start End| Date Time | Date Time | Date Time "
1247: pack $legendFrame.legend1 $legendFrame.legend2 -side top
1248:
1249: set listbox [listbox $listFrame.list -width 63 -yscrollcommand "$listFrame.scroll set" ]
1250: scrollbar $listFrame.scroll -command "$listbox yview"
1251: pack $listFrame.list $listFrame.scroll -side left
1.13 ! albertel 1252: pack configure $listFrame.scroll -fill y
1.1 albertel 1253: updateDateBox $listbox
1254:
1255: button $commandFrame.add -text "Add" -command "addDate $listbox"
1256: button $commandFrame.change -text "Change" -command "changeDate $listbox"
1257: button $commandFrame.delete -text "Delete" -command "deleteDate $listbox"
1.13 ! albertel 1258: button $commandFrame.moveup -text "MoveUp" -command "moveUpDate $listbox"
! 1259: button $commandFrame.movedown -text "MoveDown" -command "moveDownDate $listbox"
! 1260: pack $commandFrame.add $commandFrame.change $commandFrame.delete \
! 1261: $commandFrame.moveup $commandFrame.movedown -side left
1.1 albertel 1262: bind $listbox <Double-ButtonPress-1> "changeDate $listbox"
1263:
1264: message $loadFrame.msg -text "Load header information from set:" \
1265: -aspect 1000
1266: set gLoadHeaderSet $gSetNumberText
1267: entry $loadFrame.entry -textvariable gLoadHeaderSet -width 2
1268: button $loadFrame.load -text "load" -command "loadDates $listbox"
1269: pack $loadFrame.msg $loadFrame.entry $loadFrame.load -side left
1270:
1.2 albertel 1271: if { [file exists [file join [file dirname $gFile] discussion $gSetNumberText]] } {
1272: set gEnableDiscussion 1
1273: } else {
1274: set gEnableDiscussion 0
1275: }
1276: checkbutton $optionFrame.discuss -text "Enable Discussion Forum" \
1277: -variable gEnableDiscussion
1278: pack $optionFrame.discuss
1279:
1.1 albertel 1280: button $buttonFrame.ok -text Set -command { set gPrompt(ok) 1 } \
1281: -underline 0
1282: button $buttonFrame.cancel -text Cancel -command { set gPrompt(ok) 0 } \
1283: -underline 0
1284: pack $buttonFrame.ok $buttonFrame.cancel -side left
1285:
1286: bind $dialog <Destroy> "set gPrompt(ok) 0"
1287: Centre_Dialog $dialog default
1288: update
1289:
1290: focus $dialog
1291: capaRaise $dialog
1292: capaGrab $dialog
1293: bind $dialog <Destroy> ""
1294: set done 0
1295: while { $done != 1 } {
1296: vwait gPrompt(ok)
1297: if { $gPrompt(ok) == 1 } {
1298: set done [checkHeaderForDefault]
1299: if { $done == 0 } {
1300: displayError "Must have a Default setting."
1301: }
1302: } else {
1303: set done 1
1304: }
1305: }
1306: capaGrab release $dialog
1307: destroy $dialog
1308: if {$gPrompt(ok) == 1 } {
1.2 albertel 1309: updateDiscussion
1.13 ! albertel 1310: if { [llength $gControlDates] > 2 } {
! 1311: set gControlDates [linsert [lreverse [lrange $gControlDates 1 end]] 0 [lindex $gControlDates 0]]
! 1312: }
1.1 albertel 1313: eval updateHeader [ eval concat $gControlDates ]
1314: }
1315:
1316: return
1317:
1318: }
1319:
1320: ###########################################################
1.2 albertel 1321: # updateDiscussion
1322: ###########################################################
1323: ###########################################################
1324: ###########################################################
1325: proc updateDiscussion {} {
1326: global gFile gSetNumberText gEnableDiscussion
1327: set dir [file dirname $gFile]
1328: set disDir [file join $dir discussion $gSetNumberText]
1329: set logDir [file join $dir discussion logs]
1330: if { $gEnableDiscussion } {
1331: if { ![file exists $disDir] } {
1332: if { [file exists $disDir.unavailable] } {
1333: exec mv $disDir.unavailable $disDir
1334: } else {
1335: file mkdir $disDir
1336: file attributes $disDir -permissions 0777
1337: }
1338: }
1339: if { ![file exists $logDir] } {
1340: file mkdir [file join $dir discussion logs]
1341: file attributes [file join $dir discussion logs] -permissions 0777
1342: }
1343: } else {
1344: if { [file exists $disDir] } { exec mv $disDir $disDir.unavailable }
1345: }
1346: }
1347:
1348: ###########################################################
1.1 albertel 1349: # allFieldsComplete2
1350: ###########################################################
1351: ###########################################################
1352: ###########################################################
1353: proc allFieldsComplete2 {} {
1.2 albertel 1354: global gLoadHeaderSet gControlDates
1.1 albertel 1355:
1356: if { [string length $gOpenDate] != 8 } {
1357: return 0
1358: } elseif { [string length $gOpenTime] != 5 } {
1359: return 0
1360: } elseif { [string length $gDueDate] != 8 } {
1361: return 0
1362: } elseif { [string length $gDueTime] != 5 } {
1363: return 0
1364: } elseif { [string length $gAnswerDate] != 8 } {
1365: return 0
1366: } elseif { [string length $gAnswerTime] != 5 } {
1367: return 0
1368: } else {
1369: return 1
1370: }
1371: }
1372:
1373: ###########################################################
1374: # createFindWindow
1375: ###########################################################
1376: ###########################################################
1377: ###########################################################
1378: proc createFindWindow { {num 0} } {
1379: global gFind gWindowMenu gFindListbox
1380:
1381: if { [winfo exists .find] } {
1382: capaRaise .find
1383: pickFindFile $num
1384: return
1385: }
1386:
1387: set find [toplevel .find]
1388: $gWindowMenu add command -label "Find" -command "capaRaise $find"
1389: wm title $find "Find"
1390:
1391: set findFrame [frame $find.findFrame -width 5i]
1392: set replaceFrame [frame $find.replaceFrame ]
1393: set optionsFrame [frame $find.optionsFrame ]
1394: set buttonFrame [frame $find.buttonsFrame ]
1395: pack $findFrame $replaceFrame $optionsFrame $buttonFrame -side top \
1396: -anchor e
1397: pack configure $buttonFrame -anchor center
1398:
1399: message $findFrame.msg -text "Find:" -aspect 10000
1400: entry $findFrame.entry -width 50 -textvariable gFind(find)
1401: pack $findFrame.msg $findFrame.entry -side left
1402:
1403: message $replaceFrame.msg -text "Replace with:" -aspect 10000
1404: entry $replaceFrame.entry -width 50 -textvariable gFind(replace)
1405: pack $replaceFrame.msg $replaceFrame.entry -side left
1406:
1407: set fileFrame [frame $optionsFrame.file]
1408: set scopeFrame [frame $optionsFrame.scope -relief groove -borderwidth 4]
1409: set findOptionsFrame [frame $optionsFrame.findOptionsFrame -relief \
1410: groove -borderwidth 4]
1411: pack $fileFrame $scopeFrame $findOptionsFrame -side left
1412:
1413: set fileList [ frame $fileFrame.list ]
1414: set fileScroll [frame $fileFrame.scroll ]
1415: pack $fileList $fileScroll -side left
1416: pack configure $fileScroll -fill y
1417:
1418: set gFindListbox [listbox $fileList.list -width 35 -height 4 \
1419: -xscrollcommand "$fileList.scroll set" \
1420: -yscrollcommand "$fileScroll.scroll set" \
1421: -exportselection no]
1422: scrollbar $fileList.scroll -orient h -command "$fileList.list xview"
1423: pack $fileList.list $fileList.scroll -side top
1424: pack configure $fileList.scroll -fill x
1425: pack configure $fileList.list -fill both -expand 1
1426: $fileList.list xview moveto 1
1427:
1428: scrollbar $fileScroll.scroll -orient v \
1429: -command "$fileList.list yview"
1430: pack $fileScroll.scroll -fill y -expand 1
1431:
1432: message $scopeFrame.msg -text "Replace All Scope" -aspect 10000
1433: radiobutton $scopeFrame.file -value "File" -variable gFind(scope) -text \
1434: "Entire File" \
1435:
1436: radiobutton $scopeFrame.selection -value "Selection" -variable \
1437: gFind(scope) -text "Selection"
1438: pack $scopeFrame.msg $scopeFrame.file $scopeFrame.selection
1439: pack configure $scopeFrame.file $scopeFrame.selection -anchor w
1440: set gFind(scope) File
1441:
1442: message $findOptionsFrame.msg -text "Find Options" -aspect 10000
1443: radiobutton $findOptionsFrame.ignoreCase -variable gFind(findOption) \
1444: -text "Ignore Case" -value "-nocase"
1445: radiobutton $findOptionsFrame.exactCase -variable gFind(findOption) \
1446: -text "Exact Case" -value "-exact"
1447: radiobutton $findOptionsFrame.regexp -variable gFind(findOption) \
1448: -text "Regular Expression" -value "-regexp"
1449: pack $findOptionsFrame.msg $findOptionsFrame.ignoreCase \
1450: $findOptionsFrame.exactCase $findOptionsFrame.regexp
1451: pack $findOptionsFrame.ignoreCase $findOptionsFrame.exactCase \
1452: $findOptionsFrame.regexp -anchor w
1453: set gFind(findOption) "-nocase"
1454:
1455: button $buttonFrame.replaceAll -text "Replace All" -command "replaceAll"
1456: button $buttonFrame.replace -text "Replace" -command "replace"
1457: button $buttonFrame.replaceFind -text "Replace and Find" -command \
1458: "replaceFind"
1459: button $buttonFrame.previous -text "Previous" -command "previous"
1460: button $buttonFrame.next -text "Next <Return>" -command "next"
1461: bind $find <KeyPress-Return> next
1462: button $buttonFrame.close -text "Close" -command "removeWindowEntry Find
1463: destroy $find"
1464: bind $find <Destroy> "removeWindowEntry Find"
1465: pack $buttonFrame.replaceAll $buttonFrame.replace \
1466: $buttonFrame.replaceFind $buttonFrame.previous \
1467: $buttonFrame.next $buttonFrame.close -side left
1468:
1469: Centre_Dialog $find default
1470: updateFindList
1471: pickFindFile $num
1472: }
1473:
1474: ###########################################################
1475: # pickFindFile
1476: ###########################################################
1477: ###########################################################
1478: ###########################################################
1479: proc pickFindFile { num } {
1480: global gFindListbox gFindList gRefFile gFile
1481: if { [catch {set gFindListbox}] } { return }
1482: if { ![winfo exists $gFindListbox] } { return }
1483: if { $num == 0 } {
1484: set newfile $gFile
1485: } else {
1486: set newfile $gRefFile($num)
1487: }
1488: for {set i 0} {$i<[llength $gFindList(files)]} {incr i} {
1489: set file [lindex $gFindList(files) $i]
1490: if { $file == $newfile } { break }
1491: }
1492: if { $i < [llength $gFindList(files)] } {
1493: $gFindListbox selection clear 0 end
1494: $gFindListbox selection set $i
1495: }
1496: }
1497:
1498: ###########################################################
1499: # updateFindList
1500: ###########################################################
1501: ###########################################################
1502: ###########################################################
1503: proc updateFindList {} {
1504: global gFindListbox gFindList
1505: if { [catch {set gFindListbox}] } { return }
1506: if { ![winfo exists $gFindListbox] } { return }
1507: $gFindListbox delete 0 end
1508: eval "$gFindListbox insert end $gFindList(files)"
1509: $gFindListbox xview moveto 1
1510: }
1511:
1512: ###########################################################
1513: # whichFile
1514: ###########################################################
1515: ###########################################################
1516: ###########################################################
1517: proc whichFile { refNum } {
1518: global gRefFile gFile
1519: if { $refNum > 0 } {
1520: return $gRefFile($refNum)
1521: } else {
1522: if { $refNum < 0 } {
1523: switch -- $refNum {
1524: -1 { return "Preview Window" }
1525: -2 { return "Parse Errors Window" }
1526: -3 { return "LaTeX Output Window" }
1527: }
1528: } else {
1529: return $gFile
1530: }
1531: }
1532: }
1533: ###########################################################
1534: # addFindList
1535: ###########################################################
1536: ###########################################################
1537: ###########################################################
1538: proc addFindList { {refNum 0} } {
1539: global gFindList gRefFile gFile
1540:
1541: set file [whichFile $refNum]
1542: lappend gFindList(files) $file
1543: lappend gFindList(refNum) $refNum
1544: updateFindList
1545: }
1546:
1547: ###########################################################
1548: # removeFindList
1549: ###########################################################
1550: ###########################################################
1551: ###########################################################
1552: proc removeFindList { {refNum 0} } {
1553: global gFindList gRefFile gFile
1554:
1555: set file [whichFile $refNum]
1556: set k [llength $gFindList(refNum)]
1557: for {set i 0} {$i < $k } { incr i } {
1558: if { $refNum == [lindex $gFindList(refNum) $i] } { break }
1559: }
1560: if { $i != $k } {
1561: set gFindList(refNum) [lreplace $gFindList(refNum) $i $i]
1562: set gFindList(files) [lreplace $gFindList(files) $i $i]
1563: }
1564: updateFindList
1565: }
1566:
1567: ###########################################################
1568: # getFindWindow
1569: ###########################################################
1570: ###########################################################
1571: ###########################################################
1572: proc getFindWindow { {refNumVar none} } {
1573: global gFindListbox gFindList gRefText gTextWindow \
1574: gPreviewText gParseErrorsText gCreateDviText
1575:
1576: set current [$gFindListbox curselection]
1577: if { $current == "" } { set current 0 }
1578: if { [set refNum [lindex $gFindList(refNum) $current] ] } {
1579: if { $refNum < 0 } {
1580: switch -- $refNum {
1581: -1 { set window $gPreviewText }
1582: -2 { set window $gParseErrorsText }
1583: -3 { set window $gCreateDviText }
1584: }
1585: } else {
1586: set window $gRefText($refNum)
1587: }
1588: } else {
1589: set window $gTextWindow
1590: }
1591: if { $refNumVar != "none" } {
1592: upvar $refNumVar refNumUp
1593: set refNumUp $refNum
1594: }
1595: return $window
1596: }
1597:
1598: ###########################################################
1599: # replaceAll
1600: ###########################################################
1601: ###########################################################
1602: ###########################################################
1603: proc replaceAll {} {
1604: global gFind gCreateImportLinks
1605:
1606: set window [getFindWindow]
1607: if { ![winfo exists $window] } { return }
1608:
1609: set gCreateImportLinks 0
1610: set num 0
1611: switch $gFind(scope) {
1612: File
1613: {
1614: $window mark set insert 0.0
1615: set begin 0.0
1616: while { [nextRegion $begin end] != "" } {
1617: incr num
1618: replace
1619: if { ! ($num%10) } { update idletasks }
1620: set begin sel.last
1621: }
1622: }
1623: Selection
1624: {
1625: set error [ catch {$window mark set replace sel.first}]
1626: if { $error != 0 } { return }
1627: $window mark set capaBegin sel.first
1628: $window mark set capaEnd sel.last
1629: while { [set begin [nextRegion capaBegin capaEnd]] != "" } {
1630: incr num
1631: replace
1632: $window mark set capaBegin $begin
1633: }
1634: }
1635: }
1636: if { $num == 1 } { set s {} } { set s s }
1637: update idletasks
1638: set gCreateImportLinks 1
1639: getFindWindow refNum
1640: if { $refNum >= 0 } { registerCreateImportLinks $refNum 0.0 end }
1.12 albertel 1641: displayMessage "Replaced $num occurrence$s"
1.1 albertel 1642: }
1643:
1644: ###########################################################
1645: ###########################################################
1646: ###########################################################
1647: ###########################################################
1648: proc replace {} {
1649: global gFind
1650:
1651: set refNum 0
1652: set window [getFindWindow refNum]
1653: if { ![winfo exist $window] } { return }
1654:
1655: set error [ catch {$window mark set replace sel.first}]
1656: if { $error == 0 } {
1657: $window delete sel.first sel.last
1658: } else {
1659: $window mark set replace insert
1660: }
1661:
1662: $window insert replace "$gFind(replace)"
1663:
1664: catch {$window tag remove sel sel.first sel.last}
1665:
1666: $window tag add sel "replace - [string length "$gFind(replace)"] \
1667: chars " replace
1668: $window see replace
1669:
1670: $window mark unset replace
1671: }
1672:
1673: ###########################################################
1674: ###########################################################
1675: ###########################################################
1676: ###########################################################
1677: proc replaceFind {} {
1678: set window [getFindWindow]
1679: if { ![winfo exists $window] } { return }
1680: replace
1681: next
1682: }
1683:
1684: ###########################################################
1685: ###########################################################
1686: ###########################################################
1687: ###########################################################
1688: proc searchBody { found } {
1689: global gFind
1690:
1691: set window [getFindWindow refNum]
1692: if { ![winfo exists $window] } { return }
1693:
1694: catch {$window tag remove sel sel.first sel.last}
1695: $window tag add sel $found "$found + [string length $gFind(find)] \
1696: chars"
1697: $window see $found
1698: $window mark set insert "$found + [string length $gFind(find)] chars"
1699: }
1700:
1701: ###########################################################
1702: ###########################################################
1703: ###########################################################
1704: ###########################################################
1705: proc previous {} {
1706: global gFind
1707:
1708: set window [getFindWindow]
1709: if { ![winfo exists $window] } { return }
1710:
1711: if { [catch { set found [$window search $gFind(findOption) -backwards -- \
1712: $gFind(find) "sel.first - 1 c" ] } ] } {
1713: set found [ $window search $gFind(findOption) -backwards -- \
1714: $gFind(find) "insert - 1 c" ]
1715: }
1716: if { $found != "" } { searchBody $found }
1717: return $found
1718: }
1719:
1720: ###########################################################
1721: ###########################################################
1722: ###########################################################
1723: ###########################################################
1724: proc next {} {
1725: global gFind
1726:
1727: set window [getFindWindow]
1728: if { ![winfo exists $window] } { return }
1729:
1730: set found [ $window search $gFind(findOption) -forwards -- \
1731: $gFind(find) "insert + 1 c" ]
1732: if { $found != "" } {
1733: searchBody $found
1734: } else {
1735: displayMessage "Search String Not Found"
1736: }
1737: return $found
1738: }
1739:
1740: ###########################################################
1741: ###########################################################
1742: ###########################################################
1743: ###########################################################
1744: proc nextRegion { begin end } {
1745: global gFind
1746:
1747: set window [getFindWindow]
1748: if { ![winfo exists $window] } { return }
1749:
1750: set error [ catch {set found [ $window search $gFind(findOption) \
1751: -forwards -- $gFind(find) $begin $end ] } ]
1752: if { $error != 0 } { set found "" }
1753: if { $found != "" } {
1754: searchBody $found
1755: set found "$found + [string length $gFind(find)] chars"
1756: }
1757: return $found
1758: }
1759:
1760: ###########################################################
1761: ###########################################################
1762: ###########################################################
1763: ###########################################################
1764: proc createLineWindow {} {
1765: global gLineNumber gCharacterNumber gLineNumberGoto gCharacterNumberGoto
1766: global gWindowMenu
1767:
1768: if { [winfo exists .lineWindow] } {
1769: capaRaise .lineWindow
1770: return
1771: }
1772:
1773: set lineWindow [toplevel .lineWindow]
1774: $gWindowMenu add command -label "LineSelect" -command \
1775: "capaRaise $lineWindow"
1776: wm title $lineWindow "Select Line"
1777:
1778: label $lineWindow.line -text "Line:"
1779: grid $lineWindow.line -column 1 -row 0
1780: label $lineWindow.character -text "Character:"
1781: grid $lineWindow.character -column 2 -row 0
1782: label $lineWindow.current -text "Current:"
1783: grid $lineWindow.current -column 0 -row 1
1784: label $lineWindow.lineNumber -textvariable gLineNumber
1785: grid $lineWindow.lineNumber -column 1 -row 1
1786: label $lineWindow.characterNumber -textvariable gCharacterNumber
1787: grid $lineWindow.characterNumber -column 2 -row 1
1788: label $lineWindow.goto -text "Goto:"
1789: grid $lineWindow.goto -column 0 -row 2
1790: entry $lineWindow.lineEntry -textvariable gLineNumberGoto
1791: grid $lineWindow.lineEntry -column 1 -row 2
1792: set gLineNumberGoto ""
1793: entry $lineWindow.characterEntry -textvariable gCharacterNumberGoto
1794: grid $lineWindow.characterEntry -column 2 -row 2
1795: set gCharacterNumberGoto ""
1796: button $lineWindow.close -text "Close" -command "destroy $lineWindow
1797: removeWindowEntry LineSelect"
1798: bind $lineWindow <Destroy> "removeWindowEntry LineSelect"
1799: grid $lineWindow.close -column 1 -row 3
1800: button $lineWindow.gotoButton -text "Goto<Return>" -command "gotoLine"
1801: grid $lineWindow.gotoButton -column 2 -row 3
1802:
1803: bind $lineWindow <KeyPress-Return> gotoLine
1804:
1805: Centre_Dialog $lineWindow default
1806: }
1807:
1808: ###########################################################
1809: ###########################################################
1810: ###########################################################
1811: ###########################################################
1812: proc gotoLine {} {
1813: global gTextWindow gLineNumberGoto gCharacterNumberGoto
1814: if { [catch {set gTextWindow}] } { return }
1815: if { ![winfo exists $gTextWindow] } { return }
1816:
1817: if { $gCharacterNumberGoto == "" } {
1818: if { $gLineNumberGoto == "" } {
1819: return
1820: } else {
1821: $gTextWindow mark set insert $gLineNumberGoto.0
1822: catch {$gTextWindow tag remove sel sel.first sel.last}
1823: $gTextWindow tag add sel "insert linestart" "insert lineend"
1824: $gTextWindow see insert
1825: }
1826: } else {
1827: if { $gLineNumberGoto == "" } {
1828: $gTextWindow mark set insert "insert linestart + \
1829: $gCharacterNumberGoto chars"
1830: catch {$gTextWindow tag remove sel sel.first sel.last}
1831: $gTextWindow tag add sel "insert - 1 chars " insert
1832: $gTextWindow see insert
1833: } else {
1834: $gTextWindow mark set insert $gLineNumberGoto.$gCharacterNumberGoto
1835: catch {$gTextWindow tag remove sel sel.first sel.last}
1836: $gTextWindow tag add sel "$gLineNumberGoto.$gCharacterNumberGoto \
1837: - 1 chars " "$gLineNumberGoto.$gCharacterNumberGoto"
1838: $gTextWindow see insert
1839: }
1840: }
1841: }
1842:
1843: proc faster {} {
1844: global gFasterParsing
1845: puts $gFasterParsing
1846: }
1847:
1848: ###########################################################
1849: # createPrefsWindow
1850: ###########################################################
1851: ###########################################################
1852: ###########################################################
1853: proc createPrefsWindow {} {
1854: global gPrefs gWindowMenu gEditWindow gFile gWhichFile gPrefsEditWindow \
1855: gFasterParsing
1856: if { [catch {set gEditWindow}] } { return }
1857: if { ![winfo exists $gEditWindow] } { return }
1858: if { [winfo exists .prefs] } { capaRaise .prefs; return }
1859:
1860: set prefs [toplevel .prefs]
1.13 ! albertel 1861: $gWindowMenu add command -label "Prefernces" -command "capaRaise $prefs"
1.1 albertel 1862: wm title $prefs "Preferences"
1863:
1864: set frameAll [frame $prefs.frameAll -relief groove -borderwidth 4]
1865: pack $frameAll -expand true -fill both
1866:
1867: set frameFile [frame $frameAll.file]
1868: set frameInfo [frame $frameAll.info -relief groove -borderwidth 4 ]
1869: set frameButton [frame $frameAll.button ]
1870: pack $frameButton $frameInfo $frameFile -side top -expand false
1871: pack configure $frameButton -expand false -anchor center
1872:
1873: message $frameInfo.msg -text "Print Out"
1874: radiobutton $frameInfo.problem -text "Problems Only" -value "Problem" \
1875: -variable gPrefs(info)
1876: radiobutton $frameInfo.problemandanswer -text "Problems and Answers" \
1877: -value "ProblemAnswer" -variable gPrefs(info)
1878: radiobutton $frameInfo.answer -text "Answers Only" -value "Answer" \
1879: -variable gPrefs(info)
1880: pack $frameInfo.msg $frameInfo.problem $frameInfo.problemandanswer \
1881: $frameInfo.answer -side left -expand false -anchor w
1882:
1883:
1884: set selectMenu [tk_optionMenu $frameFile.menu gWhichFile HTMLheader HTMLfooter \
1885: TeXheader TeXfooter]
1886: set frameEdit [frame $frameFile.edit]
1887: pack $frameFile.menu $frameEdit
1888: pack configure $frameEdit -expand true -fill both
1889: trace variable gWhichFile w changePrefFile
1890:
1891: scrollbar $frameEdit.scroll -orient vertical -command "$frameEdit.text yview"
1892: set gPrefsEditWindow [text $frameEdit.text -yscrollcommand \
1893: "$frameEdit.scroll set" -wrap char -height 20 -width 80]
1894: pack $frameEdit.scroll $frameEdit.text -side left
1895: pack configure $frameEdit.scroll -expand false -fill y
1896: pack configure $frameEdit.text -expand true -fill both
1897:
1898: checkbutton $frameButton.faster -text "Faster Parsing" -command faster \
1899: -variable gFasterParsing
1900: button $frameButton.impcolor -text "/IMP color" -command "getColor IMP_color"
1901: button $frameButton.commentcolor -text "// color" -command "getColor comment_color"
1902: button $frameButton.config -text "Reread capa.config" -command "rereadCapaConfig"
1903: button $frameButton.ok -text "Dismiss" -command "destroy $prefs
1904: trace vdelete gWhichFile w changePrefFile
1.13 ! albertel 1905: removeWindowEntry Prefernces"
1.1 albertel 1906: bind $prefs <Destroy> "removeWindowEntry Preferences"
1907: button $frameButton.save -text "Save All" -command "savePrefs"
1908: pack $frameButton.impcolor $frameButton.commentcolor $frameButton.config \
1909: $frameButton.ok $frameButton.save $frameButton.faster -side left
1910:
1911: foreach file {HTMLheader HTMLfooter TeXheader TeXfooter} {
1912: if { [ catch {
1913: set filename [file join [file dirname $gFile] $file ]
1914: set fileId [open $filename r]
1915: set gPrefs($file) [read $fileId [file size $filename ]]
1916: close $fileId } errors ] } {
1917: set gPrefs($file) ""
1918: }
1919: }
1920: set gPrefs(currentFile) ""
1921: set gWhichFile HTMLheader
1922:
1923:
1924: Centre_Dialog $prefs default
1925: }
1926:
1927: ###########################################################
1928: # getColor
1929: ###########################################################
1930: ###########################################################
1931: ###########################################################
1932: proc getColor { whatfor } {
1933: global gCapaConfig gUniqueNumber gRefText
1934: set color [tk_chooseColor -initialcolor $gCapaConfig($whatfor)]
1935: set gCapaConfig($whatfor) $color
1936: if { $color != "" } { updateColors }
1937: displayMessage "To keep this color, put \"$whatfor = $color\" in the capa.config file."
1938: }
1939:
1940: ###########################################################
1941: # updateColors
1942: ###########################################################
1943: ###########################################################
1944: ###########################################################
1945: proc updateColors {} {
1946: global gCapaConfig gUniqueNumber gRefText
1947: set todo [array names gRefText]
1948: lappend todo 0
1949: displayStatus "Updating Colors . . ." both
1950: set num 0
1951: foreach win $todo {
1952: createImportLinks $win 0.0 end
1953: incr num
1954: updateStatusBar [expr $num/double([llength $todo])]
1955: }
1956: removeStatus
1957: }
1958:
1959: ###########################################################
1960: # changePrefFile
1961: ###########################################################
1962: ###########################################################
1963: ###########################################################
1964: proc changePrefFile { var1 var2 op } {
1965: global gPrefs gPrefsEditWindow gFile gWhichFile
1966:
1967: if { $gPrefs(currentFile) != "" } {
1968: set gPrefs($gPrefs(currentFile)) [$gPrefsEditWindow get 0.0 end-1c]
1969: }
1970: set gPrefs(currentFile) $gWhichFile
1971: $gPrefsEditWindow delete 0.0 end
1972: $gPrefsEditWindow insert 0.0 $gPrefs($gWhichFile)
1973: }
1974:
1975: ###########################################################
1976: # updatePrefsWindow
1977: ###########################################################
1978: ###########################################################
1979: ###########################################################
1980: proc updatePrefsWindow {} {
1981: global gPrefs gPrefsEditWindow gFile gWhichFile
1982: if { [catch {set gPrefsEditWindow}] } { return }
1983: if { ![winfo exists $gPrefsEditWindow] } { return }
1984:
1985: foreach file {HTMLheader HTMLfooter TeXheader TeXfooter} {
1986: if { [ catch {
1987: set filename [file join [file dirname $gFile] $file ]
1988: set fileId [open $filename r]
1989: set gPrefs($file) [read $fileId [file size $filename]]
1990: close $fileId } ] } {
1991: set gPrefs($file) ""
1992: }
1993: }
1994: $gPrefsEditWindow delete 0.0 end
1995: $gPrefsEditWindow insert 0.0 $gPrefs($gWhichFile)
1996: }
1997:
1998: ###########################################################
1999: ###########################################################
2000: ###########################################################
2001: ###########################################################
2002: proc savePrefs {} {
2003: global gPrefsEditWindow gFile gPrefs
2004: if { [catch {set gPrefsEditWindow}] } { return }
2005: if { ![winfo exists $gPrefsEditWindow] } { return }
2006: if { $gPrefs(currentFile) != "" } {
2007: set gPrefs($gPrefs(currentFile)) [$gPrefsEditWindow get 0.0 end-1c]
2008: }
2009: foreach file {HTMLheader HTMLfooter TeXheader TeXfooter} {
2010: if { $gPrefs($file) != "" } {
2011: set fileId [open [file join [file dirname $gFile] $file ] w]
2012: puts -nonewline $fileId $gPrefs($file)
2013: close $fileId
2014: } else {
2015: exec rm -f [file join [file dirname $gFile] $file ]
2016: }
2017: }
2018: }
2019:
2020: ###########################################################
2021: # checkHeader
2022: ###########################################################
2023: ###########################################################
2024: ###########################################################
2025: proc checkHeader { numberParsed } {
2026: global gWeightsDiffer gPartialDiffer gSetNumberText gHeaderQCount \
2027: gControlDates gLoadHeaderSet gFirstTime
2028:
2029: # if { $gFirstTime } { set gFirstTime 0; return }
2030: set gLoadHeaderSet $gSetNumberText
2031: set error [catch {getHeaderInfo}]
1.13 ! albertel 2032: if { [llength $gControlDates] > 2 } {
! 2033: set gControlDates [linsert [lreverse [lrange $gControlDates 1 end]] 0 [lindex $gControlDates 0]]
! 2034: }
1.1 albertel 2035: if { $error == 1 } {
2036: set gHeaderQCount "0"
2037: set gControlDates ""
2038: displayError "The db file for this set does not yet exist."
2039: } else {
2040: set errortext ""
2041: if { ( $numberParsed != $gHeaderQCount ) } {
2042: set error 1
2043: append errortext "Number of questions ($numberParsed) is different from the number in setX.db ($gHeaderQCount). "
2044: }
2045: if { $gWeightsDiffer } {
2046: set error 1
2047: append errortext "The problem weights specified in the QZ file are different from the ones in the DB file. "
2048: }
2049: if { $gPartialDiffer } {
2050: set error 1
2051: append errortext "Whether or not a problem is hand graded as specified in the QZ file is different from the DB file. "
2052: }
2053: if { $error } {
2054: displayError "The curent DB Header does not match what the set file says it should be: $errortext. Set the DB Header!" red
2055: }
2056: }
2057: return $error
2058: }
2059:
2060: ###########################################################
2061: # fillInStudentName
2062: ###########################################################
2063: ###########################################################
2064: ###########################################################
2065: #proc notherefillInStudentName { v } {
2066: # global $v
2067:
2068: # set student [capaGetStudent [set ${v}(studentNumber)]]
2069: # set ${v}(studentName) [lindex $student [expr [llength $student] - 1] ]
2070: #}
2071:
2072: ###########################################################
2073: # studentSelectWindow
2074: ###########################################################
2075: ###########################################################
2076: ###########################################################
2077: proc studentSelectWindow { followupCommand } {
2078: global gStudentSelection gChanged gWindowMenu gEditWindow
2079: if { [catch {set gEditWindow}] } { return }
2080: if { ![winfo exists $gEditWindow] } { return }
2081: if { $gChanged } { if { [askToSave 0 0] == "Cancel" } { return } }
2082:
2083: if { [winfo exists .studentSelect] } {
2084: capaRaise .studentSelect
2085: return
2086: }
2087: set student [toplevel .studentSelect]
2088: $gWindowMenu add command -label "SelectStudent" \
2089: -command "capaRaise $student"
2090: wm title $student "Select Student"
2091:
2092: message $student.msg -text "Please specify a student to preview" \
2093: -aspect 10000
2094: set infoFrame [frame $student.frame -relief groove -borderwidth 4]
2095: set buttonFrame [frame $student.buttonFrame ]
2096: pack $student.msg $infoFrame $buttonFrame -side top
2097:
2098: button $buttonFrame.ok -text "Preview" -command \
2099: "selectStudentPreview $student $followupCommand"
2100: button $buttonFrame.cancel -text "Cancel" -command \
2101: "destroy $student
2102: trace vdelete gStudentSelection(studentNumber) w \"global gStudentSelection; set gStudentSelection(type) Specific ;#\"
2103: trace vdelete gStudentSelection(studentName) w \"global gStudentSelection; set gStudentSelection(type) Specific ;#\"
2104: removeWindowEntry SelectStudent"
2105: bind $student <Destroy> \
2106: "trace vdelete gStudentSelection(studentNumber) w \"global gStudentSelection; set gStudentSelection(type) Specific ;#\"
2107: trace vdelete gStudentSelection(studentName) w \"global gStudentSelection; set gStudentSelection(type) Specific ;#\"
2108: removeWindowEntry SelectStudent"
2109: pack $buttonFrame.ok $buttonFrame.cancel -side left
2110:
2111: set randomAnyFrame [frame $infoFrame.randomany]
2112: set randomFrame [frame $infoFrame.random]
2113: set specificFrame [frame $infoFrame.specific]
2114: set sectionFrame [frame $infoFrame.section]
2115: # pack $randomAnyFrame $randomFrame $specificFrame $sectionFrame -side top
2116: pack $randomFrame $specificFrame -side top
2117: pack configure $specificFrame -expand true -fill both
2118:
2119: radiobutton $randomAnyFrame.random -text "Randomly select a student" \
2120: -value "RandomAny" -variable gStudentSelection(type)
2121: pack $randomAnyFrame.random
2122:
2123: radiobutton $randomFrame.random -text "Randomly select one student \
2124: from section:" -value "Random" -variable gStudentSelection(type)
2125: entry $randomFrame.entry -textvariable gStudentSelection(random) -width 3
2126: pack $randomFrame.random $randomFrame.entry -side left
2127:
2128: radiobutton $specificFrame.specific -text "Specify the student by:" \
2129: -value "Specific" -variable gStudentSelection(type)
2130: set studentNumber [frame $specificFrame.studentNumber]
2131: set fullName [frame $specificFrame.fullName]
2132: pack $specificFrame.specific $studentNumber $fullName -side top
2133: pack configure $specificFrame.specific -anchor w
2134: pack configure $studentNumber $fullName -anchor e
2135:
2136: radiobutton $sectionFrame.section
2137: message $studentNumber.msg -text "Student Number: " -aspect 10000
2138: entry $studentNumber.entry -textvariable gStudentSelection(studentNumber) \
2139: -width 9 -validate key -validatecommand "limitEntry %W 9 any %P"
2140: pack $studentNumber.msg $studentNumber.entry -side left
2141:
2142: message $fullName.msg -text "Student Name: " -aspect 10000
2143: entry $fullName.msg2 -textvariable gStudentSelection(studentName) -width 35 \
2144: -validate key -validatecommand "limitEntry %W 35 any %P"
2145: pack $fullName.msg $fullName.msg2 -side left
2146:
2147: trace variable gStudentSelection(studentNumber) w \
2148: "global gStudentSelection; set gStudentSelection(type) Specific ;#"
2149: trace variable gStudentSelection(studentName) w \
2150: "global gStudentSelection; set gStudentSelection(type) Specific ;#"
2151:
2152: bind $studentNumber.entry <KeyPress-Return> \
2153: "fillInStudent gStudentSelection(studentName) gStudentSelection(studentNumber) 0"
2154: bind $fullName.msg2 <KeyPress-Return> \
2155: "fillInStudent gStudentSelection(studentName) gStudentSelection(studentNumber) 1"
2156: # $specificFrame.specific configure -command \
2157: "$studentNumber.entry configure -state normal"
2158: # $randomFrame.random configure -command \
2159: "$studentNumber.entry configure -state disabled"
2160:
2161: Centre_Dialog $student default
2162: }
2163:
2164: ###########################################################
2165: # selectStudentPreview
2166: ###########################################################
2167: ###########################################################
2168: ###########################################################
2169: proc selectStudentPreview { student followupCommand} {
2170: global gStudentSelection
2171: destroy $student
2172: if { $gStudentSelection(type) == "Specific" } {
2173: if {$gStudentSelection(studentNumber) == ""} {
2174: fillInStudent gStudentSelection(studentName) \
2175: gStudentSelection(studentNumber) 1
2176: } else {
2177: fillInStudent gStudentSelection(studentName) \
2178: gStudentSelection(studentNumber) 0
2179: }
2180: if {$gStudentSelection(studentNumber) == ""} { return }
2181: }
2182: removeWindowEntry SelectStudent
2183: $followupCommand
2184: }
2185:
2186: ###########################################################
2187: # createPreviewWindow
2188: ###########################################################
2189: ###########################################################
2190: ###########################################################
2191: proc createPreviewWindow {} {
2192: global gPreviewMode gPreviewText gPrefs gSetNumberText gStudentSelection
2193: global gWindowMenu gNumberParsedText gNumber
2194: global gLoadHeaderSet gHeaderQCount gControlDates
2195:
2196: if { ![winfo exists .preview] } {
2197:
2198: set previewWindow [toplevel .preview]
2199: $gWindowMenu add command -label "Preview" -command \
2200: "capaRaise $previewWindow"
2201: wm title $previewWindow "Preview"
2202: addFindList -1
2203:
2204: set windowFrame [frame $previewWindow.windowFrame]
2205: set buttonFrame [frame $previewWindow.buttonFrame]
2206:
2207: pack $windowFrame $buttonFrame -side bottom
2208: pack configure $windowFrame -expand true -fill both
2209: pack configure $buttonFrame -anchor e
2210:
2211: scrollbar $windowFrame.scroll -orient vertical -command \
2212: "$windowFrame.text yview"
2213: set gPreviewText [text $windowFrame.text -yscrollcommand \
2214: "$windowFrame.scroll set" -wrap char -height 40]
2215:
2216: pack $windowFrame.scroll $gPreviewText -side left -expand 0
2217: pack configure $windowFrame.scroll -expand 0 -fill y
2218: pack configure $gPreviewText -expand true -fill both
2219:
2220: button $buttonFrame.ok -text Dismiss -command "destroy $previewWindow
2221: removeWindowEntry Preview
2222: removeFindList -1"
2223: bind $previewWindow <Destroy> "removeWindowEntry Preview
2224: removeFindList -1"
2225: button $buttonFrame.save -text "Save Output" -command "saveText $gPreviewText"
2226: button $buttonFrame.stop -text "Stop Parser" -command "stopParser"
2227: button $buttonFrame.print -text "Print Output" -command "printText $gPreviewText"
2228: pack $buttonFrame.print $buttonFrame.save $buttonFrame.stop \
2229: $buttonFrame.ok -side left
2230:
2231: Centre_Dialog $previewWindow default
2232: wm withdraw $previewWindow
2233: update idletasks
2234: set win_width [winfo reqwidth $previewWindow]
2235: set win_height [winfo reqheight $previewWindow]
2236: wm geometry $previewWindow +[expr [winfo rootx $previewWindow] - \
2237: 100]+[winfo rooty $previewWindow]
2238: wm deiconify $previewWindow
2239: update
2240: } else {
2241: set previewWindow .preview
2242: $gPreviewText delete 0.0 end
2243: update
2244: }
2245:
2246: switch $gPrefs(info) {
2247: Problem { set type 0 }
2248: ProblemAnswer { set type 1 }
2249: Answer { set type 2 }
2250: }
2251: grab .preview
2252: if { [catch {
2253: switch $gPreviewMode {
2254: Enscript
2255: {
2256: set numberParsed [enscriptParse $type $gSetNumberText \
2257: $gStudentSelection(type) $gStudentSelection(random) \
2258: $gStudentSelection(studentNumber) \
2259: $gStudentSelection(studentName) gPreviewText]
2260: }
2261: TeX
2262: {
2263: set numberParsed [texParse $type $gSetNumberText \
2264: $gStudentSelection(type) $gStudentSelection(random) \
2265: $gStudentSelection(studentNumber) \
2266: $gStudentSelection(studentName) gPreviewText]
2267: }
2268: Web
2269: {
2270: set numberParsed [webParse $type $gSetNumberText \
2271: $gStudentSelection(type) $gStudentSelection(random) \
2272: $gStudentSelection(studentNumber) \
2273: $gStudentSelection(studentName) gPreviewText]
2274: }
2275: } }]} { return }
2276: grab release .preview
2277: if { $numberParsed == -1 } {
2278: destroy $previewWindow
2279: removeWindowEntry Preview
2280: return
2281: }
2282: checkHeader $numberParsed
2283: $gPreviewText tag configure problem
2284: $gPreviewText tag configure answer
2285: capaRaise $previewWindow
2286:
2287: set gNumberParsedText $numberParsed
2288: showParseErrors
2289: }
2290:
2291: ###########################################################
1.6 albertel 2292: # openError
2293: ###########################################################
2294: ###########################################################
2295: ###########################################################
2296: proc openError { file line type} {
2297: global gRefLine gLineNumberGoto gTextWindow
2298: if { $type == 2 } {
2299: set gLineNumberGoto $line
2300: gotoLine
2301: capaRaise [winfo toplevel $gTextWindow]
2302: } else {
2303: if {[set num [openReferenceFile $file]]} {
2304: update idletasks
2305: set gRefLine($num) $line
2306: gotoRefLine $num
2307: }
2308: }
2309: }
2310:
2311: ###########################################################
2312: # showParseErrors
1.1 albertel 2313: ###########################################################
2314: ###########################################################
2315: ###########################################################
2316: proc showParseErrors {} {
1.6 albertel 2317: global gParseErrorsText gWindowMenu gUniqueNumber gCapaConfig
1.1 albertel 2318:
2319: set parseErrors [getParseErrors]
2320:
2321: if { $parseErrors != "" } {
2322:
2323: if { ![winfo exists .parseErrors] } {
2324:
2325: set parseErrorsWindow [toplevel .parseErrors]
2326: $gWindowMenu add command -label "ParseErrors" -command "capaRaise \
2327: $parseErrorsWindow"
2328: wm title $parseErrorsWindow "Parse Errors"
2329: addFindList -2
2330:
2331: set windowFrame [frame $parseErrorsWindow.windowFrame]
2332: set buttonFrame [frame $parseErrorsWindow.buttonFrame]
2333:
2334: pack $windowFrame $buttonFrame -side bottom
2335: pack configure $windowFrame -expand true -fill both
2336: pack configure $buttonFrame -anchor e
2337:
2338: scrollbar $windowFrame.scroll -orient vertical -command \
2339: "$windowFrame.text yview"
2340: set gParseErrorsText [text $windowFrame.text -yscrollcommand \
2341: "$windowFrame.scroll set" -wrap char -height 40]
2342:
2343: pack $windowFrame.scroll $gParseErrorsText -side left -expand 0
2344: pack configure $windowFrame.scroll -expand 0 -fill y
2345: pack configure $gParseErrorsText -expand true -fill both
2346:
2347: button $buttonFrame.ok -text Dismiss -command \
2348: "destroy $parseErrorsWindow
2349: removeWindowEntry ParseErrors
2350: removeFindList -2"
2351: bind $parseErrorsWindow <Destroy> "removeWindowEntry ParseErrors
2352: removeFindList -2"
2353: button $buttonFrame.save -text "Save Output" \
2354: -command "saveText $gParseErrorsText"
2355: button $buttonFrame.print -text "Print Output" \
2356: -command "printText $gParseErrorsText"
2357: pack $buttonFrame.print $buttonFrame.save \
2358: $buttonFrame.ok -side left
2359:
2360: Centre_Dialog $parseErrorsWindow default
2361: update
2362: capaRaise $parseErrorsWindow
2363: } else {
2364: $gParseErrorsText delete 0.0 end
2365: capaRaise .parseErrors
2366: }
1.5 albertel 2367: foreach line [split $parseErrors "\n"] {
1.6 albertel 2368: set tag 0
2369: if { [regexp -indices {File:.+->(.+), Line ([0-9]+): ERROR:} $line result file linenum]} {
2370: set tag 1
1.5 albertel 2371: } else {
1.6 albertel 2372: if { [regexp -indices {File:(.+), Line ([0-9]+): ERROR:} $line result file linenum]} {
2373: set tag 2
1.5 albertel 2374: }
2375: }
1.6 albertel 2376: if { $tag } {
2377: set tagnum [incr gUniqueNumber]
2378: set linenum [eval [list string range $line] $linenum]
2379: set filename [eval [list string range $line] $file]
2380: set i [expr [lindex [split [$gParseErrorsText index end] .] 0] - 1]
2381: }
2382: $gParseErrorsText insert end "$line\n"
2383: if { $tag } {
2384: $gParseErrorsText tag add error.$tagnum $i.[lindex $file 0] $i.[expr [lindex $file 1] + 1]
2385: $gParseErrorsText tag configure error.$tagnum -foreground $gCapaConfig(IMP_color)
2386: $gParseErrorsText tag bind error.$tagnum <Double-ButtonPress> \
2387: "eval openError $filename $linenum $tag"
2388: }
1.5 albertel 2389: }
1.1 albertel 2390: } else {
2391: if { [winfo exists .parseErrors] } { $gParseErrorsText delete 0.0 end }
2392: }
2393:
2394: return $parseErrors
2395: }
2396:
2397: ###########################################################
2398: # printText
2399: ###########################################################
2400: # prints the contents of the text window, creates a temp file named
2401: # quiztemp.txt
2402: ###########################################################
2403: # Arguments: window (name of text window to print the contents of.
2404: # Returns : nothing
2405: # Globals :
2406: ###########################################################
2407: proc printText { window } {
2408:
2409: if { ![winfo exists $window] } {
2410: return
2411: }
2412: set lprCommand [getLprCommand quiztemp.txt]
2413:
2414: if {$lprCommand == "Cancel"} {
2415: return
2416: }
2417:
2418: set fileId [open "quiztemp.txt" w]
2419: puts -nonewline $fileId "[ $window get 0.0 end ]"
2420: close $fileId
2421:
2422: set errorMsg ""
2423: set error [catch {set output [ eval "exec $lprCommand" ] } errorMsg ]
2424:
2425: if { $error == 1 } {
2426: displayError "An error occurred while printing: $errorMsg"
2427: } else {
2428: displayMessage "Print job sent to the printer.\n $output"
2429: }
2430: exec rm -f quiztemp.txt
2431: }
2432:
2433: ###########################################################
2434: # saveText
2435: ###########################################################
2436: # saves the contents of the text window
2437: ###########################################################
2438: # Arguments: window (name of text window to save the contents of.
2439: # saveAs (whether to ask to save)
2440: # refNum (if supplied reference file unique number
2441: # that is being saved)
2442: # Returns : name of the file saved
2443: # Globals :
2444: ###########################################################
2445: proc saveText { window {saveAs 1} {refNum 0} } {
2446: global gWindowMenu gRefFile gRefChanged gCapaConfig gFile
2447:
2448: if { ![winfo exists $window] } {return}
2449: if { $refNum } {
2450: if {$saveAs} {
2451: set dir [file dirname $gRefFile($refNum)]
2452: set file ""
2453: } else {
2454: set dir [file dirname $gRefFile($refNum)]
2455: set file [file tail $gRefFile($refNum)]
2456: }
2457: } else { set dir [ set file "" ] }
2458: # if { $dir == "" || $dir == "."} { set dir [pwd] }
2459: if { $file == "" } {
2460: set file [tk_getSaveFile -title "Enter the name to Save As" \
2461: -initialdir "$dir" ]
2462: if { $file == "" } {
2463: displayError "File not saved"
2464: return
2465: }
2466: } else {
2467: set file [file join $dir $file]
2468: }
2469:
2470: if { $refNum } {
2471: catch {removeWindowEntry "Reference $gRefFile($refNum)*" }
2472: catch {removeFindList $refNum}
2473: set gRefFile($refNum) $file
2474: addFindList $refNum
2475: wm title [winfo toplevel $window] $file
2476: $gWindowMenu add command -label "Reference $file" \
2477: -command "capaRaise [winfo toplevel $window]"
2478: if { !$saveAs } {
2479: if { ([array name gCapaConfig quizzerBackupRef] == "") ||
2480: ($gCapaConfig(quizzerBackupRef)!="off") } {
2481: if { [catch {file copy -force $file $file.bak} ] } {
2482: displayError "Unable to create backup for $file"
2483: }
2484: }
2485: }
2486: }
2487: set fileId [open $file w]
2488: puts -nonewline $fileId [$window get 0.0 end]
2489: close $fileId
2490: if { $refNum } { set gRefChanged($refNum) 0 }
2491: if { ([file tail $file] == "capa.config") && ($dir == [file dirname $gFile]) } {
2492: if { [makeSure "Reread capa.config settings into Quizzer?"] != "Cancel" } {
2493: rereadCapaConfig
2494: }
2495: }
2496:
2497: return $file
2498: }
2499:
2500: ###########################################################
2501: # deleteFile
2502: ###########################################################
2503: ###########################################################
2504: ###########################################################
2505: proc deleteFile { which } {
2506: global gFile gRefFile
2507: if { $which } { set file $gRefFile($which) } else { set file $gFile }
2508: if { [makeSure "Do you wish to Delete $file"] == "Cancel" } { return }
2509: if { $which } { closeRefFile $which 1 0 } else { closeDocument 1 0 }
2510: file delete -- $file
2511: }
2512:
2513: ###########################################################
2514: ###########################################################
2515: ###########################################################
2516: ###########################################################
2517: proc rereadCapaConfig { } {
2518: global gCapaConfig
2519: set printer_option $gCapaConfig(printer_option)
2520: unset gCapaConfig(printer_option)
2521: set error [parseCapaConfig]
2522: if { $error != "OK" } {
2523: displayError "Invalid capa.config file"
2524: set gCapaConfig(printer_option) $printer_option
2525: }
1.5 albertel 2526: setDefaultValues
1.1 albertel 2527: updateColors
2528: }
2529:
2530: ###########################################################
2531: ###########################################################
2532: ###########################################################
2533: ###########################################################
2534: proc pickCapaConfig { } {
2535: set error NOTOK
2536: while { $error != "OK" } {
2537: set file [tk_getOpenFile -title "Pick a capa.config file" \
2538: -filetypes { { {CAPA configuration} {capa.config} } \
2539: { {All Files} {*} } }]
2540: if { $file == "" } { break }
2541: set oldDir [pwd]
2542: cd [file dirname $file]
2543: set error [parseCapaConfig]
2544: if { $error != "OK" } { displayError "Invalid capa.config file"; cd $oldDir }
1.5 albertel 2545: setDefaultValues
1.1 albertel 2546: }
2547: }
2548:
1.5 albertel 2549: proc setDefaultValues {} {
2550: global gProbVal gTryVal gHintVal gCapaConfig
2551: catch {set gProbVal $gCapaConfig(default_prob_val)}
2552: catch {set gTryVal $gCapaConfig(default_try_val)}
2553: catch {set gHintVal $gCapaConfig(default_hint_val)}
2554: }
2555:
1.1 albertel 2556: ###########################################################
2557: # openDocument
2558: ###########################################################
2559: ###########################################################
2560: ###########################################################
2561: proc openDocument {} {
1.5 albertel 2562: global gFile gTextWindow gSetNumberText gPrefs gChanged gQuizTemp gUndo
1.1 albertel 2563:
2564: if { $gChanged } { if { [askToSave 0 0] == "Cancel" } { return } }
2565: if { ![catch {set gTextWindow}] } {
2566: if { [winfo exists $gTextWindow] } { return }
2567: }
2568:
2569: # the event generation is because of a bug in tk_getOpenFile
2570: # After double cliking the mouse Button one is thought to be left down.
2571: # this only seems to happen when a toplevel window is created
2572: # after getting the file
2573: set gFile [tk_getOpenFile -filetypes \
2574: { { {Quizzer} {"*.qz"} } { {All Files} {"*"} } } \
2575: -title "Select the proper file" -initialdir "[pwd]" ]
2576: # event generate .main <ButtonRelease-1>
2577: if { $gFile == "" } { return }
2578: if { [file isdirectory $gFile] } {
2579: displayError "You attempted to open $gFile which is a directory not a file."
2580: return
2581: }
2582:
2583: set error [ catch {set fileId [open $gFile r] } ]
2584:
2585: if { $error } {
2586: displayError "Unable to read $gFile"
2587: return
2588: }
2589:
2590: set oldDir [pwd]
2591:
2592: cd [file dirname $gFile]
2593:
2594: set tempfiles ""
2595: catch {set tempfiles [glob quiztemp.*]}
2596: if { $tempfiles == "" } {
2597: set gQuizTemp true
2598: }
2599: foreach quiztempFile $tempfiles {
2600: if { ! ( [file isfile $quiztempFile] &&
2601: [file writable $quiztempFile] ) } {
2602: if { [makeSure "There are old quiztemp files in this directory that can not be overwritten. If you continue editing you will be unable to print or Create .dvi. You can still preview and save."] == "Cancel" } {
2603: cd $oldDir
2604: set gQuizTemp true
2605: return
2606: } else {
2607: set gQuizTemp false
2608: break
2609: }
2610: }
2611: }
2612:
2613: if { $tempfiles == "" } {
2614: if { ! [file writable $gFile] } {
2615: if { [makeSure "You do not have permission to write to this directory. If you continue editing you will be unable to save, print, or create .dvi"] == "Cancel" } {
2616: cd $oldDir
2617: set gQuizTemp true
2618: return
2619: } else {
2620: set gQuizTemp false
2621: }
2622: }
2623: }
2624:
2625: set error [parseCapaConfig]
2626:
2627: if { $error != "OK" } {
2628: cd $oldDir
2629: set gQuizTemp true
2630: return
2631: }
1.5 albertel 2632: setDefaultValues
2633:
1.1 albertel 2634: createEditingWindow 0
2635: $gTextWindow delete 0.0 end
2636: $gTextWindow insert 0.0 [read $fileId [file size $gFile]]
2637: $gTextWindow delete end-1c
2638:
2639: rename $gTextWindow .$gTextWindow
2640: trackChanges $gTextWindow 0
2641: set gUndo(0) 0
2642: set gUndo(0.cur) 0
2643:
2644: createImportLinks 0 0.0 end
2645: focus -force $gTextWindow
2646: set coord [$gTextWindow bbox 0.0]
2647: event generate $gTextWindow <1> -x [lindex $coord 0] -y [lindex $coord 1]
2648: event generate $gTextWindow <ButtonRelease-1>
2649: update
2650: close $fileId
2651:
2652: updatePrefsWindow
2653:
2654: set gSetNumberText [string range [file rootname [file tail $gFile]] 3 end ]
2655: checkIfValidFilename
2656: set gChanged 0
2657: }
2658:
2659: ###########################################################
2660: # includeReferenceFile
2661: ###########################################################
2662: ###########################################################
2663: ###########################################################
2664: proc includeReferenceFile { file num window } {
2665: set index [$window index "file.$num.first linestart"]
2666: if { ![file readable $file] } {
2667: displayError "Unable to read file $file"
2668: return
2669: }
2670: set impline [$window get $index "$index lineend"]
2671: set fileId [open $file r]
2672: $window insert $index /
2673: update idletasks
2674: if { [$window index end] == [$window index "$index + 1 lines"] } {
2675: $window insert "$index + 1 lines" "\n[read $fileId [file size $file]]"
2676: } else {
2677: $window insert "$index + 1 lines" [read $fileId [file size $file]]
2678: }
2679: close $fileId
2680: }
2681:
2682: ###########################################################
2683: # impMenuSaveAs
2684: ###########################################################
2685: ###########################################################
2686: ###########################################################
2687: proc impMenuSaveAs { file num window } {
2688: set index [$window index "file.$num.first linestart"]
2689: if { ![file readable $file] } {
2690: displayError "Unable to read file $file"
2691: return
2692: }
2693: set dir [file dirname $file]
2694: if { $dir != "." } {
2695: set dest [tk_getSaveFile -title "Enter the name to Save As" -initialdir $dir]
2696: } else {
2697: set dest [tk_getSaveFile -title "Enter the name to Save As" -initialdir [pwd]]
2698: }
2699: if { $dest == "" } {
2700: displayError "File not saved"
2701: return
2702: }
2703: if { [catch {file copy -force -- $file $dest} errorMsg ] } {
2704: displayError "Unable to copy $file to $dest: $errorMsg"
2705: return
2706: }
2707: $window delete $index "$index lineend"
2708: if { $dir != "." } {
2709: $window insert $index "/IMP \"$dest\""
2710: } else {
2711: $window insert $index "/IMP \"[file tail $dest]\""
2712: }
2713: }
2714:
2715: ###########################################################
2716: # createImpMenu
2717: ###########################################################
2718: ###########################################################
2719: ###########################################################
2720: proc createImpMenu { file num window } {
2721: set menuFrame [menu .impmenu -tearoff 0 -type tearoff ]
2722:
2723: # wm title $menuFrame "Quizzer"
2724: wm overrideredirect $menuFrame 1
2725: wm positionfrom $menuFrame program
2726: $menuFrame post [winfo pointerx .] [winfo pointery .]
2727: $menuFrame add command -label "Open" -command "openReferenceFile $file"
2728: $menuFrame add command -label "Include" -command \
2729: "includeReferenceFile $file $num $window"
2730: $menuFrame add command -label "saveAs" -command "impMenuSaveAs $file $num $window"
2731: grab $menuFrame
2732: bind all <ButtonRelease> "grab release $menuFrame;destroy $menuFrame"
2733: }
2734:
2735: ###########################################################
2736: # registerCreateImportLinks
2737: ###########################################################
2738: ###########################################################
2739: ###########################################################
2740: proc registerCreateImportLinks { num start end} {
2741: global gDoCreateImportLinks gCreateImportLinks
2742:
2743: if { $gCreateImportLinks && !$gDoCreateImportLinks($num) } {
2744: after idle "createImportLinks $num $start $end"
2745: set gDoCreateImportLinks($num) 1
2746: }
2747: }
2748:
2749: ###########################################################
2750: # createImportLinks
2751: ###########################################################
2752: ###########################################################
2753: ###########################################################
2754: proc createImportLinks { num start end } {
2755: global gTextWindow gUniqueNumber gDoCreateImportLinks gRefText gCapaConfig
2756:
2757: set gDoCreateImportLinks($num) 0
2758: if { $num } { set window $gRefText($num) } else { set window $gTextWindow }
2759: if { ![winfo exists $window] } { return }
2760: set end [$window index $end]
2761: set start [$window index $start]
2762: set lastline [lindex [split $end .] 0]
2763: set startline [lindex [split $start .] 0]
2764: foreach tag [$window tag names] {
2765: if { [regexp {file\..+} $tag ] } {
2766: if { [$window tag nextrange $tag "$start linestart" "$end lineend"] != "" } {
2767: $window tag delete $tag
2768: }
2769: }
2770: }
2771: for { set i $startline } { $i <= $lastline } { incr i } {
2772: set aline [$window get $i.0 "$i.0 lineend"]
2773: if { [regexp -nocase {(^[ ]*)(//.*)} $aline matchVar match1 match2] } {
2774: set tagnum [incr gUniqueNumber]
2775: set start [string length $match1]
2776: set end [expr $start + [string length $match2]]
2777: $window tag add file.$tagnum $i.$start $i.$end
2778: $window tag configure file.$tagnum -foreground $gCapaConfig(comment_color)
2779: } elseif { [regexp -nocase {(^.*/let.*[ ]+)(//.*)} $aline matchVar \
2780: match1 match2] } {
2781: set tagnum [incr gUniqueNumber]
2782: set start [string length $match1]
2783: set end [expr $start + [string length $match2]]
2784: $window tag add file.$tagnum $i.$start $i.$end
2785: $window tag configure file.$tagnum -foreground $gCapaConfig(comment_color)
2786: }
2787: if { [regexp -nocase "(.*/imp +)(\"\[^\"\]+\")(.*)" $aline matchVar \
2788: match1 match2 match3] } {
2789: set tagnum [incr gUniqueNumber]
2790: set start [string length $match1]
2791: set end [expr $start + [string length $match2]]
2792: $window tag add file.$tagnum $i.$start $i.$end
2793: $window tag configure file.$tagnum -foreground $gCapaConfig(IMP_color)
2794: $window tag bind file.$tagnum <Double-ButtonPress> \
2795: "eval openReferenceFile $match2"
2796: $window tag bind file.$tagnum <ButtonPress-3> \
2797: "eval createImpMenu $match2 $tagnum $window"
2798: }
2799: }
2800: }
2801:
2802: ###########################################################
2803: # isReferenceFileOpen
2804: ###########################################################
2805: ###########################################################
2806: ###########################################################
2807: proc isReferenceFileOpen { file } {
2808: global gWindowMenu
2809: # if { [catch {set index [$gWindowMenu index "Reference $file"]} ] } { return "" }
2810: set last [$gWindowMenu index end]
2811: # puts $last
2812: for { set index 1 } { $index <= $last } { incr index } {
2813: # puts $index
2814: catch {set entry [$gWindowMenu entrycget $index -label]}
2815: if { "Reference" == [set entryfile [lindex $entry 0]] } {
2816: set entryfile [lindex $entry 1]
2817: }
2818: # puts $entryfile
1.6 albertel 2819: if { [catch {file stat $entryfile a1}] } { continue }
1.1 albertel 2820: file stat $file a2
2821: # puts "$a2(ino) == $a1(ino)"
2822: if { $a2(ino) == $a1(ino) } {
2823: # puts "seems right"
2824: return [lindex [$gWindowMenu entrycget $index -command] 1]
2825: }
2826: }
2827: # puts "failed $index"
2828: return ""
2829: # puts $index
2830: # puts [$gWindowMenu entrycget $index -command]
2831: # return [lindex [$gWindowMenu entrycget $index -command] 1]
2832: }
2833:
2834: ###########################################################
2835: # newReferenceFile
2836: ###########################################################
2837: ###########################################################
2838: ###########################################################
2839: proc newReferenceFile { } {
2840: global gDir
2841: # if { $gDir(reference) == "." } { set gDir(reference) [pwd] }
2842: set file [tk_getSaveFile -title "Enter the name of the New reference file" \
2843: -initialdir "$gDir(reference)" ]
2844: event generate .main <ButtonRelease-1>
2845: if { $file == "" } { return }
2846: set gDir(reference) [file dirname $file]
2847: if { [file isdirectory $file] } {
2848: displayError "You attempted to create $file which is already a directory."
2849: return
2850: }
2851: openReferenceFile $file 1
2852: }
2853:
2854: ###########################################################
2855: # openReferenceFile
2856: ###########################################################
2857: ###########################################################
2858: ###########################################################
2859: proc openReferenceFile { {file ""} {new 0}} {
2860: global gUniqueNumber gWindowMenu gDir
2861:
2862: set num [incr gUniqueNumber]
2863: global gRefCurLine gRefLine gRefText gRefChanged gRefFile gRefClosed \
2864: gUndo gRefChangedLast
2865: # the event generation is because of a bug in tk_getOpenFile
2866: # After double cliking the mouse Button one is thought to be left down.
2867: # this only seems to happen when a toplevel window is created
2868: # after getting the file
2869: if { $file == "" } {
2870: # if { $gDir(reference) == "." } { set gDir(reference) [pwd] }
2871: set file [tk_getOpenFile -filetypes \
2872: { { {All Files} {"*"} } { {Quizzer} {"*.qz"} } } \
2873: -title "Select the proper file" \
2874: -initialdir "$gDir(reference)" ]
2875: event generate .main <ButtonRelease-1>
1.6 albertel 2876: if { $file == "" } { return 0 }
1.1 albertel 2877: set gDir(reference) [file dirname $file]
2878:
2879: if { [file isdirectory $file] } {
2880: displayError "You attempted to open $file which is a directory not a file."
1.6 albertel 2881: return 0
1.1 albertel 2882: }
2883: } else {
2884: if { !$new } {
2885: if { [set window [isReferenceFileOpen $file] ] != "" } {
1.6 albertel 2886: set num [lindex [split [lindex [split $window .] 1] e] end]
1.1 albertel 2887: capaRaise $window
1.6 albertel 2888: return $num
1.1 albertel 2889: }
2890: # specifically opening the capa.config file
2891: if { $file == "capa.config" } {
2892: global gTextWindow gFile
2893: if { [catch {set gTextWindow}] } {
2894: set file [tk_getOpenFile -filetypes \
2895: {{{Capa.config file} {"capa.config"}}
2896: { {All Files} {"*"} } } \
2897: -title "Select the proper file" \
2898: -initialdir "$gDir(reference)" ]
1.6 albertel 2899: if { $file == "" } { return 0 }
1.1 albertel 2900: } else {
2901: set file [file join [file dirname $gFile] capa.config]
2902: }
2903: } else {
2904: if { ![file isfile $file] && ![file readable $file] } {
2905: displayError "Unable to find $file"
1.6 albertel 2906: return 0
1.1 albertel 2907: }
2908: if { [file isdirectory $file] } {
2909: displayError "You attempted to open $file which is a directory not a file."
1.6 albertel 2910: return 0
1.1 albertel 2911: }
2912: }
2913: }
2914: }
2915:
2916: set gRefFile($num) $file
2917: set referenceFile [toplevel .reference$num]
2918: wm title $referenceFile "$file"
2919:
2920: $gWindowMenu add command -label "Reference $file" \
2921: -command "capaRaise $referenceFile"
2922:
2923: set menuFrame [frame $referenceFile.menu -borderwidth 3 -relief raised]
2924: set lineFrame [frame $referenceFile.lineFrame]
2925: set windowFrame [frame $referenceFile.windowFrame]
2926: pack $menuFrame $lineFrame $windowFrame
2927: pack configure $windowFrame -expand 1 -fill both
2928: pack configure $menuFrame -fill x
2929:
2930: label $lineFrame.msg -text "Current Line:"
2931: label $lineFrame.current -textvariable gRefCurLine($num)
2932: entry $lineFrame.line -width 8 -textvariable gRefLine($num)
2933: bind $lineFrame.line <KeyPress-Return> "+gotoRefLine $num"
2934: button $lineFrame.button -text "Goto" -command \
2935: "gotoRefLine $num"
2936: pack $lineFrame.msg $lineFrame.current $lineFrame.line \
2937: $lineFrame.button -side left
2938:
2939: set infoFrame [frame $windowFrame.infoFrame]
2940: set textFrame [frame $windowFrame.textFrame]
2941: pack $infoFrame $textFrame -side top
2942: pack configure $textFrame -expand 1 -fill both
2943:
2944: scrollbar $textFrame.scroll -orient vertical -command \
2945: "$textFrame.text yview"
2946: set textWindow [text $textFrame.text -yscrollcommand \
2947: "$textFrame.scroll set" -wrap char]
2948: pack $textFrame.scroll $textWindow -side left -expand 0
2949: pack configure $textFrame.scroll -expand 0 -fill y
2950: pack configure $textWindow -expand true -fill both
2951:
2952: # label $infoFrame.label -textvariable gRefFile($num)
2953: # pack $infoFrame.label -side left
2954:
2955: menubutton $menuFrame.file -text File -menu $menuFrame.file.m
2956: menubutton $menuFrame.edit -text Edit -menu $menuFrame.edit.m
2957: pack $menuFrame.file $menuFrame.edit -side left
2958:
2959: set fileMenu [ menu $menuFrame.file.m ]
2960: set editMenu [ menu $menuFrame.edit.m ]
2961:
2962: $fileMenu add command -label Save -command \
2963: "saveText $textWindow 0 $num" -accelerator "Alt+s"
2964: bind $referenceFile <Alt-s> \
2965: "saveText $textWindow 0 $num"
2966: $fileMenu add command -label "Save As" -command \
2967: "saveText $textWindow 1 $num" -accelerator "Alt+S"
2968: bind $referenceFile <Alt-Shift-s> "saveText $textWindow 1 $num"
2969: $fileMenu add command -label Delete -command "deleteFile $num"
2970: $fileMenu add command -label Print -command "printText $textWindow"
2971: $fileMenu add command -label Close -command "closeRefFile $num" \
2972: -accelerator "Alt+w"
2973: bind $referenceFile <Alt-w> "closeRefFile $num"
2974: # bind $referenceFile <Destroy> "closeRefFile $num 1"
2975: wm protocol $referenceFile WM_DELETE_WINDOW "closeRefFile $num 1"
2976: $editMenu add command -label "Cut" -command "tk_textCut $textWindow" \
2977: -accelerator "Alt+x"
2978: bind $referenceFile <Alt-x> "tk_textCut $textWindow"
2979: $editMenu add command -label "Copy" -command "tk_textCopy $textWindow" \
2980: -accelerator "Alt+c"
2981: bind $referenceFile <Alt-c> "tk_textCopy $textWindow"
2982: $editMenu add command -label "Paste" -command "tk_textPaste $textWindow" \
2983: -accelerator "Alt+v"
2984: bind $referenceFile <Alt-v> "tk_textPaste $textWindow"
2985: $editMenu add command -label "Select All " -command \
2986: "selectAll $num " -accelerator "Alt+a"
2987: bind $referenceFile <Alt-a> "selectAll $num"
2988: $editMenu add separator
2989: $editMenu add command -label "Undo" -command "undo $num" \
2990: -accelerator "Alt+u"
2991: bind $referenceFile <Alt-u> "undo $num"
2992: # $editMenu add command -label "Redo" -command "redo $num"
2993: $editMenu add separator
2994: $editMenu add command -label "Find" -command "createFindWindow $num" \
2995: -accelerator "Alt+f"
2996:
2997:
2998: if { !$new } {
2999: set fileId [open $file r]
3000: $textWindow insert 0.0 [read $fileId [file size $file]]
3001: $textWindow delete end-1c
3002: close $fileId
3003: }
3004:
3005: set gRefText($num) $textWindow
3006: rename $textWindow .$textWindow
3007: trackChanges $textWindow $num
3008: set gUndo($num) 0
3009: set gUndo($num.cur) 0
3010:
3011: createImportLinks $num 0.0 end
3012: focus -force $textWindow
3013: # update
3014: set coord [$textWindow bbox 0.0]
3015: event generate $textWindow <1> -x [lindex $coord 0] -y [lindex $coord 1]
3016: # update
3017: event generate $textWindow <ButtonRelease-1>
3018: # update
3019: # capaRaise $referenceFile
3020: after 1 "catch \{focus $textWindow;raise $referenceFile\}"
3021: selection clear
3022: #order is important here since gRefChanged has a trace on it the references
3023: #gRefChangedLast
3024: set gRefChangedLast($num) 0
3025: set gRefChanged($num) 0
3026: set gRefClosed($num) 0
3027: addFindList $num
1.6 albertel 3028: return $num
1.1 albertel 3029: }
3030:
3031: ###########################################################
3032: ###########################################################
3033: ###########################################################
3034: ###########################################################
3035: proc trackChanges { procName num } {
3036: eval "proc $procName args {
3037: global gUndo gRefChanged gChanged
3038: if {\[regexp {^(ins|del).*} \[lindex \$args 0\]\]} {
3039: #puts \"\$args\"
3040: if { \$gUndo($num.cur) != \$gUndo($num) } {
3041: set i \[expr \$gUndo($num.cur) + 1 \]
3042: while { \[ info exists gUndo($num.\$i) \] } {
3043: unset gUndo($num.\$i)
3044: incr i
3045: }
3046: set gUndo($num) \$gUndo($num.cur)
3047: }
3048: set gUndo($num.cur) \$gUndo($num)
3049: set insertindex \[.$procName index \[lindex \$args 1 \] \]
3050: set numChange \[set gUndo($num.cur) \[incr gUndo($num) \] \]
3051: if { $num == 0 } { set gChanged 1 } else { set gRefChanged($num) 1 }
3052: }
3053: if {\[regexp {^(ins).*} \[lindex \$args 0\]\]} {
3054: set index2 \$insertindex+\[string length \[lindex \$args 2 \] \]chars
3055: set gUndo($num.\$numChange) \"delete \$insertindex \$index2 \"
3056: if {\[regexp {.*\[\"/\].*} \$args\] || \
3057: \[regexp {.*\[\"/\].*} \[.$procName get \"\$insertindex linestart\" \"\$index2 lineend\"\]\]} {
3058: registerCreateImportLinks $num \$insertindex \$index2
3059: }
3060: } elseif {\[regexp {^(del).*} \[lindex \$args 0\]\]} {
3061: if { \[catch { set insertindex2 \[.$procName index \
3062: \[lindex \$args 2 \] \] } \] } {
3063: set chars \[ .$procName get \$insertindex \]
3064: set insertindex2 \$insertindex+1c
3065: } else {
3066: set chars \[ .$procName get \$insertindex \$insertindex2 \]
3067: }
3068: set gUndo($num.\$numChange) \"insert \$insertindex \[list \$chars\] \"
1.11 albertel 3069: if { \[string length \$chars\] > 100 } {
3070: registerCreateImportLinks $num \$insertindex-1line \$insertindex2+1line
3071: } else {
3072: if {\[regexp \{.*\[\"/\].*\} \$chars\] || \
3073: \[regexp \{.*\[\"/\].*\} \[.$procName get \"\$insertindex linestart\" \"\$insertindex2 lineend\"\]\]} {
3074: registerCreateImportLinks $num \$insertindex \$insertindex2
3075: }
1.1 albertel 3076: }
1.11 albertel 3077: }
1.1 albertel 3078: set result \[uplevel .$procName \$args\]
3079: updateLocation $num
3080: return \$result
3081: }"
3082: }
3083:
3084: ###########################################################
3085: ###########################################################
3086: ###########################################################
3087: ###########################################################
3088: proc undo { num } {
1.6 albertel 3089: global gUndo gRefText gTextWindow gChanged gRefChanged
1.1 albertel 3090: if { $gUndo($num.cur) == 0 } { return }
3091: set undoInfo $gUndo($num.$gUndo($num.cur))
3092: if { [regexp {.*[\"/].*} $undoInfo] } {
3093: registerCreateImportLinks $num [lindex $undoInfo 1] end
3094: }
3095: if { [regexp {.*delete.*} $undoInfo] } {
3096: registerCreateImportLinks $num [lindex $undoInfo 1] [lindex $undoInfo 2]
3097: }
3098: if { $num == 0 } {
3099: if {[catch {eval ".$gTextWindow $gUndo($num.$gUndo($num.cur))"}]} { return }
1.6 albertel 3100: set gChanged 1
1.1 albertel 3101: } else {
3102: if {[catch {eval ".$gRefText($num) $gUndo($num.$gUndo($num.cur))"}]} { return }
1.6 albertel 3103: set gRefChanged($num) 1
1.1 albertel 3104: }
3105: incr gUndo($num.cur) -1
3106: }
3107:
3108: ###########################################################
3109: ###########################################################
3110: ###########################################################
3111: ###########################################################
3112: proc redo { num } {
3113: global gUndo gRefText
3114: }
3115:
3116: ###########################################################
3117: ###########################################################
3118: ###########################################################
3119: ###########################################################
3120: proc gotoRefLine { number } {
3121: global gRefLine gRefText
3122: if { [catch {set gRefText($number)}] } { return }
3123: if { ![winfo exists $gRefText($number)] } { return }
3124:
3125: if { $gRefLine($number) == "" } {
3126: return
3127: } else {
3128: $gRefText($number) mark set insert $gRefLine($number).0
3129: catch {$gRefText($number) tag remove sel sel.first sel.last}
3130: $gRefText($number) tag add sel "insert linestart" "insert lineend"
3131: $gRefText($number) see insert
3132: }
3133: }
3134:
3135: ###########################################################
3136: # updateLocation
3137: ###########################################################
3138: ###########################################################
3139: ###########################################################
3140: proc updateLocation { number } {
3141: global gRefCurLine gRefText gTextWindow gLineNumber gCharacterNumber
3142:
3143: if {$number} {set window $gRefText($number)} {set window $gTextWindow}
3144: # if {![winfo exists $gRefText($number)]} {return};#do I need this
3145: set spot [split [.$window index insert] "."]
3146: if { $number } {
3147: set gRefCurLine($number) [lindex $spot 0 ]
3148: } else {
3149: set gLineNumber [lindex $spot 0]
3150: set gCharacterNumber [lindex $spot 0]
3151: }
3152: }
3153:
3154: ###########################################################
3155: ###########################################################
3156: ###########################################################
3157: ###########################################################
3158: proc askToSave { refNum mustClose } {
3159: global gPrompt
3160:
3161: set dialog [toplevel .askToSavePrompt -borderwidth 10]
3162: wm title $dialog "Do you wish to Save"
3163: wm geo $dialog "+200+200"
3164: if { $refNum } {
3165: global gRefFile
3166: set msg "Reference File: $gRefFile($refNum) has changed. Do you wish to save?"
3167: } else {
3168: set msg "Source has changed do you wish to save?"
3169: }
3170: message $dialog.msg -text $msg -aspect 800
3171:
3172: set gPrompt(result) ""
3173: set buttonFrame [frame $dialog.buttons -bd 10]
3174: pack $dialog.msg $buttonFrame -side top -fill x
3175:
3176: bind $dialog <Destroy> {
3177: set gPrompt(result) Cancel
3178: set gPrompt(yes) 0
3179: }
3180:
3181: button $buttonFrame.yes -text Yes -underline 0 -command {
3182: set gPrompt(yes) 1
3183: }
3184: button $buttonFrame.no -text No -underline 0 -command {
3185: set gPrompt(yes) 0
3186: }
3187: if { !$mustClose } {
3188: button $buttonFrame.cancel -text Cancel -underline 0 -command {
3189: set gPrompt(yes) 0
3190: set gPrompt(result) Cancel
3191: }
3192: pack $buttonFrame.yes $buttonFrame.no $buttonFrame.cancel -side left
3193: } else {
3194: pack $buttonFrame.yes $buttonFrame.no -side left
3195: }
3196: bind $dialog <Alt-Key> break
3197:
3198: Centre_Dialog $dialog default
3199: update
3200:
3201: focus $dialog
3202: capaRaise $dialog
3203: capaGrab $dialog
3204: vwait gPrompt(yes)
3205: capaGrab release $dialog
3206: bind $dialog <Destroy> ""
3207: destroy $dialog
3208: if {$gPrompt(yes)} {
3209: if { $refNum } {
3210: global gRefText
3211: saveText $gRefText($refNum) 0 $refNum
3212: } else {
3213: saveDocument
3214: }
3215: } else {
3216: return $gPrompt(result)
3217: }
3218: }
3219:
3220: ###########################################################
3221: ###########################################################
3222: ###########################################################
3223: ###########################################################
3224: proc saveDocument { {saveAs 0} } {
3225: global gFile gTextWindow gSetNumberText gChanged gEditWindow gWindowMenu \
3226: gCapaConfig
3227: if { [catch {set gTextWindow}] } { return }
3228: if { ![winfo exists $gTextWindow] } { return }
3229: if { $gFile == "" } { set saveAs 1 }
3230: if {$saveAs == 1} {
3231: set temp [tk_getSaveFile -title "Enter the name to Save As" \
3232: -initialdir "[pwd]" ]
3233: if { $temp == "" } {
3234: displayError "File not saved"
3235: return
3236: }
3237:
3238: catch {removeWindowEntry "$gFile*"}
3239: catch {removeFindList}
3240: set gFile $temp
3241: addFindList
3242: cd [file dirname $gFile]
3243: set gSetNumberText [string range [file rootname [file tail $gFile]] \
3244: 3 end ]
3245: checkIfValidFilename
3246: wm title [winfo toplevel $gEditWindow] $gFile
3247:
3248: $gWindowMenu add command -label "$gFile" -command \
3249: "capaRaise $gEditWindow"
3250: } else {
3251: if { ([array name gCapaConfig quizzerBackupQZ] == "") ||
3252: ($gCapaConfig(quizzerBackupQZ)!="off") } {
3253: if { [catch {file copy -force $gFile $gFile.bak} ] } {
3254: displayError "Unable to create backup for $gFile"
3255: }
3256: }
3257: }
3258:
3259: set fileId [open $gFile w]
3260:
3261: puts -nonewline $fileId [$gTextWindow get 0.0 end]
3262:
3263: close $fileId
3264:
3265: savePrefs
3266: set gChanged 0
3267: }
3268:
3269: ###########################################################
3270: ###########################################################
3271: ###########################################################
3272: ###########################################################
3273: proc closeDocument { { mustClose 0 } { save 1 } } {
3274: global gFile gEditWindow gChanged gPrefs \
3275: gPutLine gTryVal gProbVal gHintVal gQuizTemp \
3276: gNumberParsedText gSetNumberText gClosedDocument gTextWindow
3277: if { [catch {set gEditWindow}] } { return }
3278: if { ![winfo exists $gEditWindow] } { return }
3279: if { $gClosedDocument } { return }
3280: if { $save && $gChanged } {
3281: if { [askToSave 0 $mustClose] == "Cancel" && (! $mustClose ) } { return }
3282: }
3283: if {(!$mustClose)&&[makeSure "Are you sure you wish to stop editing?"]=="Cancel"} {
3284: return
3285: }
3286: set gClosedDocument 1
3287: removeFindList
3288: destroy $gEditWindow
3289: removeWindowEntry "$gFile*"
3290: set gFile ""
3291: set gChanged 0
3292: set gPrefs(info) "Problem"
3293: set gPrefs(TeXHeader) ""
3294: set gPrefs(TeXFooter) ""
3295: set gPutLine 1
3296: set gTryVal 99
3297: set gHintVal 1
3298: set gProbVal 1
3299: set gQuizTemp "true"
3300: set gNumberParsedText ""
3301: set gSetNumberText ""
3302: }
3303:
3304: ###########################################################
3305: ###########################################################
3306: ###########################################################
3307: ###########################################################
3308: proc closeRefFile { refNum { mustClose 0 } { save 1 } } {
3309: global gRefChanged gRefText gRefFile gRefClosed gRefCurLine gRefLine gRefChangedLast
3310: if { [catch {set gRefText($refNum)}] } { return }
3311: if { ![winfo exists $gRefText($refNum)] } { return }
3312: if { $gRefClosed($refNum) } { return }
3313: if { $save && $gRefChanged($refNum) } {
3314: if { [askToSave $refNum $mustClose] == "Cancel" && ( ! $mustClose ) } { return }
3315: }
3316:
3317: if { ( ! $mustClose ) && ( [makeSure "Are you sure you wish to stop editing $gRefFile($refNum)?"] == "Cancel" ) } {
3318: return
3319: }
3320: set gRefClosed($refNum) 1
3321: removeFindList $refNum
3322: destroy [winfo toplevel $gRefText($refNum)]
3323: removeWindowEntry "Reference $gRefFile($refNum)*"
3324: unset gRefText($refNum) gRefChanged($refNum) gRefClosed($refNum) gRefFile($refNum) \
3325: gRefCurLine($refNum) gRefLine($refNum) gRefChangedLast($refNum)
3326: }
3327:
3328: ###########################################################
3329: # quit
3330: ###########################################################
3331: # called when the quit option is selected on the menu, unmaps
3332: # all keys.
3333: ###########################################################
3334: # Arguments: None
3335: # Returns: Nothing
3336: # Globals: gChanged - whether or not the file has been modified
3337: ###########################################################
3338: proc quit { { mustClose 0 } } {
3339: global gChanged gRefChanged gRefText
3340:
3341: if { (! $mustClose ) && [makeSure "Are you sure you wish to quit?"] == "Cancel" } {
3342: return
3343: }
3344:
3345: if { $gChanged } {
3346: if { [askToSave 0 $mustClose] == "Cancel" && ( ! $mustClose ) } {
3347: return
3348: }
3349: }
3350:
3351: foreach refNum [array names gRefChanged] {
3352: if { $gRefChanged($refNum) == 1 } {
3353: if { [winfo exists $gRefText($refNum)] } {
3354: if { [askToSave $refNum $mustClose ] == "Cancel" && (! $mustClose ) } {
3355: return
3356: }
3357: }
3358: }
3359: }
3360:
3361: exec /bin/rm -f quiztemp.ps
3362: exec /bin/rm -f quiztemp.dvi
3363: exec /bin/rm -f quiztemp.tex
3364: exec /bin/rm -f quiztemp.log
3365: exec /bin/rm -f quiztemp.aux
3366: exec /bin/rm -f quiztemp.txt
3367:
3368: unmapAllKeys
3369:
3370: exit
3371: }
3372:
3373: ###########################################################
3374: # createStopButton
3375: ###########################################################
3376: ###########################################################
3377: ###########################################################
3378: proc createStopButton {} {
3379: global gStopStatus
3380: if {[winfo exists .stopbutton]} {destroy .stopbutton}
3381: set top [toplevel .stopbutton]
3382: button $top.stop -text "Stop Parser" -command "stopParser"
1.4 albertel 3383: label $top.status -textvariable gStopStatus -width 35 -anchor w
1.1 albertel 3384: pack $top.stop $top.status
3385: set gStopStatus ""
3386: grab $top
3387: Centre_Dialog $top default
3388: update
3389: }
3390:
3391: ###########################################################
3392: # destroyStopButton
3393: ###########################################################
3394: ###########################################################
3395: ###########################################################
3396: proc destroyStopButton {} {
3397: grab release .stopbutton
3398: destroy .stopbutton
3399: }
3400:
3401: ###########################################################
3402: # createDvi
3403: ###########################################################
3404: ###########################################################
3405: ###########################################################
3406: proc createDvi { {showXdvi 1} {showStopButton 0} {useqzparse 0}} {
3407: global gPreviewMode gCreateDviText gPrefs gSetNumberText \
3408: gStudentSelection gFile gWindowMenu gLatexId gParseErrorsText \
3409: gEditWindow gCreateDviTextTemp gXdviOpt \
3410: gLoadHeaderSet gCapaConfig gControlDates gNumberParsedText \
3411: gDonePrinting
3412:
3413: if { [catch {set gEditWindow}] } { return }
3414: if { ![winfo exists $gEditWindow] } { return }
3415:
3416: catch { destroy .createDviText }
3417: set gCreateDviTextTemp [text .createDviText]
3418:
3419: switch $gPrefs(info) {
3420: Problem { set type 0 }
3421: ProblemAnswer { set type 1 }
3422: Answer { set type 2 }
3423: }
3424:
3425: if { $useqzparse } {
3426: set gDonePrinting 0
3427: switch $gPrefs(info) {
3428: Problem { set type "-T" }
3429: Answer { set type "-Ta" }
3430: ProblemAnswer { set type "-Tb" }
3431: default { set type "-T" }
3432: }
3433: createCreateDviWin
3434: grab .createDvi
3435: $gCreateDviText delete 0.0 end
3436: if { [setupSetsToPrint set start end 0] == 1 } { return 1 }
3437: if { [set gStopPrinting [expr 2 == [runLatex \
3438: "echo [pwd] | $gCapaConfig(qzparse_command) \
3439: -stu $gStudentSelection(studentNumber) -set $set \
3440: -d [pwd] -c [pwd] $type " gCreateDviText] ] ] } {
3441: exec rm -f $gStudentSelection(studentNumber).tex quiztemp.tex
3442: if {$showStopping} {
3443: displayMessage "Printing has been stopped."
3444: set gDonePrinting 1
3445: set gStopPrinting 0
3446: }
3447: return 1
3448: }
3449: exec mv $gStudentSelection(studentNumber).tex quiztemp.tex
3450: exec /bin/rm -f quiztemp.dvi
3451: } else {
3452: createStopButton
3453: if { [catch {
3454: set numberParsed [ texParse $type $gSetNumberText \
3455: $gStudentSelection(type) $gStudentSelection(random) \
3456: $gStudentSelection(studentNumber) \
3457: $gStudentSelection(studentName) \
3458: gCreateDviTextTemp 1 ] }]} {
3459: return
3460: }
3461: destroyStopButton
3462: checkHeader $numberParsed
3463:
3464: if { [showParseErrors] != "" } {
3465: if { [makeSure "There were errors when parsing the .qz file, \
3466: continue to create the .dvi?"] =="Cancel" } {
3467: destroy $gCreateDviTextTemp
3468: return
3469: }
3470: }
3471:
3472: set error [catch { set fileId [open quiztemp.tex w] } ]
3473: if { $error } {
3474: displayError "Unable to create neccessary temp files, delete all the\
3475: quiztemp file from the class directory."
3476: return
3477: }
3478:
3479: set filename [file join [file dirname $gFile] TeXheader ]
3480: set texfileId [open $filename r]
3481: puts -nonewline $fileId [read $texfileId [file size $filename]]
3482: close $texfileId
3483:
3484: puts -nonewline $fileId "[$gCreateDviTextTemp get 0.0 end]"
3485:
3486: set filename [file join [file dirname $gFile] TeXfooter ]
3487: set texfileId [open $filename r]
3488: puts $fileId [read $texfileId [file size $filename]]
3489: close $texfileId
3490:
3491: close $fileId
3492: }
3493:
3494: destroy $gCreateDviTextTemp
3495:
3496: if { ![winfo exists .createDvi] } {
3497: set createDviWindow [toplevel .createDvi]
3498: $gWindowMenu add command -label "CreateDvi" -command \
3499: "capaRaise $createDviWindow"
3500: wm title $createDviWindow "LaTeX Output"
3501: addFindList -3
3502:
3503: set windowFrame [frame $createDviWindow.windowFrame]
3504: set buttonFrame [frame $createDviWindow.buttonFrame]
3505:
3506: pack $windowFrame $buttonFrame -side bottom
3507: pack configure $windowFrame -expand true -fill both
3508: pack configure $buttonFrame -anchor e
3509:
3510: scrollbar $windowFrame.scroll -orient vertical -command \
3511: "$windowFrame.text yview"
3512: set gCreateDviText [text $windowFrame.text -yscrollcommand \
3513: "$windowFrame.scroll set" -wrap char -height 40]
3514:
3515: pack $windowFrame.scroll $gCreateDviText -side left -expand 0
3516: pack configure $windowFrame.scroll -expand 0 -fill y
3517: pack configure $gCreateDviText -expand true -fill both
3518:
3519: set appearingFrame [frame $buttonFrame.appearingFrame]
3520: button $buttonFrame.ok -text Dismiss -command \
3521: "trace vdelete gFile w updateCreateDvi
3522: destroy $createDviWindow
3523: removeWindowEntry CreateDvi
3524: removeFindList -3"
3525: bind $createDviWindow <Destroy> \
3526: "trace vdelete gFile w updateCreateDvi
3527: removeWindowEntry CreateDvi
3528: removeFindList -3"
3529: pack $appearingFrame $buttonFrame.ok -side left
3530:
3531: button $appearingFrame.stop -text "Stop Creating Print Jobs"\
3532: -command "stopPrinting"
3533: set name [file rootname [file tail $gFile ] ].dvi
3534: button $appearingFrame.print -text \
3535: "Save.dvi file to $name" \
3536: -command saveDvi
3537: trace variable gFile w updateCreateDvi
3538:
3539: if { $showStopButton } {
3540: pack $appearingFrame.stop $appearingFrame.print -side left
3541: pack forget $appearingFrame.print
3542: } else {
3543: pack $appearingFrame.stop $appearingFrame.print -side left
3544: pack forget $appearingFrame.stop
3545: }
3546:
3547: Centre_Dialog $createDviWindow default
3548: update
3549: } else {
3550: if { $showStopButton } {
3551: pack forget .createDvi.buttonFrame.appearingFrame.print
3552: pack .createDvi.buttonFrame.appearingFrame.stop
3553: } else {
3554: pack forget .createDvi.buttonFrame.appearingFrame.stop
3555: pack .createDvi.buttonFrame.appearingFrame.print
3556: }
3557: if { !$useqzparse } { $gCreateDviText delete 0.0 end }
3558: }
3559:
3560: exec /bin/rm -f quiztemp.dvi
3561: $gCreateDviText insert end "$gCapaConfig(latex_command)\n"
3562: $gCreateDviText see end
3563: set createdDvi [ runLatex "pwd ; $gCapaConfig(latex_command) quiztemp.tex < \
3564: [file join / dev null ]" gCreateDviText]
3565:
3566: if { ($showXdvi == 1) && ( $createdDvi == 1 ) } {
3567: eval "exec $gCapaConfig(xdvi_command) $gXdviOpt quiztemp.dvi >& /dev/null & "
3568: }
3569:
3570: catch { capaRaise $gParseErrorsText }
3571: set gDonePrinting 1
3572: return $createdDvi
3573: }
3574:
3575: ###########################################################
3576: ###########################################################
3577: ###########################################################
3578: ###########################################################
3579: proc stopPrinting {} {
3580: global gStopPrinting
3581: set gStopPrinting 1
3582: }
3583:
3584: ###########################################################
3585: ###########################################################
3586: ###########################################################
3587: ###########################################################
3588: proc saveDvi { } {
3589: global gFile
3590:
3591: set name [file rootname [ file tail $gFile]].dvi
3592: catch { exec rm -f $name }
3593:
3594: if { [ catch { exec cp quiztemp.dvi $name } ] } {
3595: displayMessage "Unable to create $name "
3596: } else {
3597: displayMessage "Created $name "
3598: }
3599: }
3600:
3601:
3602: ###########################################################
3603: ###########################################################
3604: ###########################################################
3605: ###########################################################
3606: proc updateCreateDvi { name1 name2 op } {
3607: global gFile
3608:
3609: set name [file rootname [file tail $gFile ] ].dvi
3610: catch { .createDvi.buttonFrame.appearingFrame.print configure \
3611: -text "Save.dvi file to $name" }
3612: }
3613: ###########################################################
3614: ###########################################################
3615: ###########################################################
3616: ###########################################################
3617: proc printWindow {} {
3618: global gPrintSelection gWindowMenu gEditWindow gStopPrinting\
3619: gSetNumberText gMaxSet gFile gChanged
3620:
3621: set gStopPrinting 0
3622: if { [catch {set gEditWindow}] } { return }
3623: if { ![winfo exists $gEditWindow] } { return }
3624:
3625: if { [winfo exists .print] } {
3626: capaRaise .print
3627: return
3628: }
3629: if { $gChanged } { if { [askToSave 0 0] == "Cancel" } { return } }
3630:
3631: set print [toplevel .print]
3632: $gWindowMenu add command -label "Print" -command "capaRaise $print"
3633: wm title $print "Select a Print Method"
3634: message $print.msg -text "Please specify a print method." -aspect 10000
3635: set oneSetFrame [frame $print.frame1 -relief groove -borderwidth 4]
3636: set moreSetFrame [frame $print.frame2 -relief groove -borderwidth 4]
3637: set buttonFrame [frame $print.buttons]
3638: pack $print.msg $oneSetFrame $moreSetFrame $buttonFrame -side top
3639: pack configure $oneSetFrame $moreSetFrame -anchor w -fill x
3640:
3641: set infoFrame [frame $moreSetFrame.frame1]
3642: set setFrame [frame $moreSetFrame.frame2 -relief solid -borderwidth 1]
3643: pack $infoFrame $setFrame
3644: pack configure $infoFrame $setFrame -anchor w
3645:
3646: if {[catch {set gPrintSelection(sets)}]} {set gPrintSelection(sets) printCur}
3647: if {[catch {set gPrintSelection(type)}]} {set gPrintSelection(type) printSpecific}
3648: if {[catch {set gPrintSelection(setend)}]} {set gPrintSelection(setend) $gSetNumberText}
3649: radiobutton $setFrame.specific -text "Print Current Set ($gSetNumberText)" \
3650: -value "printCur" -variable gPrintSelection(sets)
3651: set scaleFrame [frame $setFrame.scales]
3652: pack $setFrame.specific $scaleFrame -anchor w
3653:
3654: for { set i 1 } { $i <= $gMaxSet } { incr i } {
3655: if { ! [file exists [file join [file dirname $gFile] records "set$i.db"]] } { break }
3656: }
3657: incr i -1
3658: set gPrintSelection(setend) $gSetNumberText
3659: radiobutton $scaleFrame.range -text "Print Set Range:" \
3660: -value "printRange" -variable gPrintSelection(sets)
3661: scale $scaleFrame.start -from 1 -to $i -variable gPrintSelection(setstart) \
3662: -orient h
3663: label $scaleFrame.msg -text "to"
3664: scale $scaleFrame.end -from 1 -to $i -variable gPrintSelection(setend) \
3665: -orient h
3666: pack $scaleFrame.range $scaleFrame.start $scaleFrame.msg \
3667: $scaleFrame.end -side left
3668:
3669: button $buttonFrame.ok -text "Select" -command selectedPrintMethod
3670: button $buttonFrame.cancel -text "Cancel" -command \
3671: "destroy .print
3672: removeWindowEntry Print"
3673: bind $print <Destroy> "removeWindowEntry Print"
3674: pack $buttonFrame.ok $buttonFrame.cancel -side left
3675:
3676: set currentDviFrame [frame $oneSetFrame.currentDvi]
3677: set currentPreviewFrame [frame $oneSetFrame.currentPreview]
3678: set randomFrame [frame $oneSetFrame.random]
3679: set specificFrame [frame $infoFrame.specific]
3680: set sectionFrame [frame $infoFrame.section]
3681: set multSectionFrame [frame $infoFrame.multsection]
3682: set wholeClassFrame [frame $infoFrame.wholeClass]
3683: pack $currentDviFrame $currentPreviewFrame $randomFrame $specificFrame \
3684: $sectionFrame $multSectionFrame $wholeClassFrame -anchor w \
3685: -side top
3686: pack configure $specificFrame -expand true -fill both
3687:
3688: radiobutton $currentDviFrame.currentDvi -text "Print current .dvi" \
3689: -value "printCurrentDvi" -variable gPrintSelection(type)
3690: pack $currentDviFrame.currentDvi -side left
3691:
3692: radiobutton $randomFrame.random -text \
3693: "Randomly select one student from section:" \
3694: -value "printRandom" -variable gPrintSelection(type)
3695: entry $randomFrame.entry -textvariable gPrintSelection(random) -width 3 \
3696: -validate key -validatecommand "limitEntry %W 3 number %P"
3697: pack $randomFrame.random $randomFrame.entry -side left
3698:
3699: radiobutton $specificFrame.specific -text "Specify the student by:" \
3700: -value "printSpecific" -variable gPrintSelection(type)
3701: set studentNumber [frame $specificFrame.studentNumber]
3702: set fullName [frame $specificFrame.fullName]
3703: pack $specificFrame.specific $studentNumber $fullName -side top
3704: pack configure $specificFrame.specific -anchor w
3705: pack configure $studentNumber $fullName -anchor e
3706:
3707: radiobutton $sectionFrame.section -text "Print section" \
3708: -value "printSection" -variable gPrintSelection(type)
3709: entry $sectionFrame.entry -textvariable gPrintSelection(section) -width 3 \
3710: -validate key -validatecommand "limitEntry %W 3 number %P"
3711: pack $sectionFrame.section $sectionFrame.entry -side left
3712:
3713: radiobutton $multSectionFrame.section -text "Print multiple sections" \
3714: -value "printMultipleSections" -variable gPrintSelection(type)
3715: pack $multSectionFrame.section -side left
3716:
3717: radiobutton $wholeClassFrame.wholeClass -text "Print whole class." \
3718: -value "printWholeClass" -variable gPrintSelection(type)
3719: pack $wholeClassFrame.wholeClass -side left
3720:
1.10 albertel 3721: message $studentNumber.msg -text "Student Number: " -aspect 10000
1.1 albertel 3722: entry $studentNumber.entry -textvariable gPrintSelection(studentNumber) -width 9 \
3723: -validate key -validatecommand "limitEntry %W 9 any %P"
3724: pack $studentNumber.msg $studentNumber.entry -side left
3725:
3726: message $fullName.msg -text "Student Name: " -aspect 10000
3727: entry $fullName.entry -textvariable gPrintSelection(studentName) -width 30 \
3728: -validate key -validatecommand "limitEntry %W 30 any %P"
3729: pack $fullName.msg $fullName.entry -side left
3730:
3731: trace variable gPrintSelection(studentNumber) w \
3732: "global gPrintSelection; set gPrintSelection(type) printSpecific ;#"
3733: trace variable gPrintSelection(studentName) w \
3734: "global gPrintSelection; set gPrintSelection(type) printSpecific ;#"
3735:
3736: # puts "trace info:[trace vinfo gPrintSelection(studentNumber)]"
3737:
3738: bind $studentNumber.entry <KeyPress-Return> \
3739: "fillInStudent gPrintSelection(studentName) gPrintSelection(studentNumber) 0"
3740: bind $fullName.entry <KeyPress-Return> \
3741: "fillInStudent gPrintSelection(studentName) gPrintSelection(studentNumber) 1"
3742:
3743:
3744: #Disable the entry boxes that are not selected, and enable the
3745: #ones that are
3746: # $specificFrame.specific configure -command "
3747: # $studentNumber.entry configure -state normal
3748: # $fullName.entry configure -state normal"
3749: # $randomFrame.random configure -command "
3750: # $studentNumber.entry configure -state disabled
3751: # $fullName.entry configure -state disabled"
3752:
3753: #If the window had been called up before we need to check the state
3754: #of the variable and disable/enable the correct enry boxes
3755: # if { $gPrintSelection(type) == "printSpecific" } {
3756: # $studentNumber.entry configure -state normal
3757: # $fullName.entry configure -state normal
3758: # }
3759: # if { $gPrintSelection(type) == "printRandom" } {
3760: # $studentNumber.entry configure -state disabled
3761: # $fullName.entry configure -state disabled
3762: # }
3763:
3764: Centre_Dialog $print default
3765: }
3766:
3767: proc selectedPrintMethod {} {
3768: global gStopPrinting gPrintSelection gStudentSelection
3769:
3770: switch $gPrintSelection(type) {
3771: printSpecific {
3772: if { $gPrintSelection(studentNumber) == "" } {
3773: displayError "You must specify a student number."
3774: return
3775: }
3776: }
3777: printSection {
3778: if { $gPrintSelection(section)== "" } {
3779: displayError "You must specify a section."
3780: return
3781: }
3782: }
3783: default {}
3784: }
3785:
3786: destroy .print
3787: removeWindowEntry Print
3788: [set gPrintSelection(type)]
3789: set gStopPrinting 0
3790: }
3791:
3792: ###########################################################
3793: # createCreateDviWin
3794: ###########################################################
3795: ###########################################################
3796: ###########################################################
3797: proc createCreateDviWin {} {
3798: global gWindowMenu gFile gCreateDviText
3799: if { ![winfo exists .createDvi] } {
3800: set createDviWindow [toplevel .createDvi]
3801: $gWindowMenu add command -label "CreateDvi" -command \
3802: "capaRaise $createDviWindow"
3803: wm title $createDviWindow "LaTeX Output"
3804:
3805: set windowFrame [frame $createDviWindow.windowFrame]
3806: set buttonFrame [frame $createDviWindow.buttonFrame]
3807:
3808: pack $windowFrame $buttonFrame -side bottom
3809: pack configure $windowFrame -expand true -fill both
3810: pack configure $buttonFrame -anchor e
3811:
3812: scrollbar $windowFrame.scroll -orient vertical -command \
3813: "$windowFrame.text yview"
3814: set gCreateDviText [text $windowFrame.text -yscrollcommand \
3815: "$windowFrame.scroll set" -wrap char -height 40]
3816:
3817: pack $windowFrame.scroll $gCreateDviText -side left -expand 0
3818: pack configure $windowFrame.scroll -expand 0 -fill y
3819: pack configure $gCreateDviText -expand true -fill both
3820:
3821: set appearingFrame [frame $buttonFrame.appearingFrame]
3822: button $buttonFrame.ok -text Dismiss -command \
3823: "checkDestroyPrint $createDviWindow"
3824: wm protocol $createDviWindow WM_DELETE_WINDOW \
3825: "checkDestroyPrint $createDviWindow"
3826: pack $appearingFrame $buttonFrame.ok -side left
3827:
3828: button $appearingFrame.stop -text "Stop Creating Print Jobs"\
3829: -command "stopPrinting"
3830: set name [file rootname [file tail $gFile ] ].dvi
3831: button $appearingFrame.print -text \
3832: "Save.dvi file to $name" \
3833: -command saveDvi
3834: trace variable gFile w updateCreateDvi
3835:
3836: pack $appearingFrame.stop $appearingFrame.print -side left
3837: pack forget $appearingFrame.print
3838:
3839: Centre_Dialog $createDviWindow default
3840: update
3841: } else {
3842: pack forget .createDvi.buttonFrame.appearingFrame.print
3843: pack .createDvi.buttonFrame.appearingFrame.stop
3844: }
3845: }
3846:
3847: ###########################################################
3848: # printBody
3849: ###########################################################
3850: # sends the file quiztemp.ps to the printer through lpr using
3851: # the option foud in gLprCommand
3852: ###########################################################
1.10 albertel 3853: # Arguments: lprCommand - actual command to be run to print
3854: # showCompletionMessage - (defaults to 1 true)
3855: # controls whether the print complete
3856: # message gets shown
1.1 albertel 3857: # Returns: Nothing
3858: # Globals: gCapaConfig -
3859: # gStopPrinting -
3860: # Files: quiztemp.ps - file containg info to print (removed)
3861: ###########################################################
1.10 albertel 3862: proc printBody { lprCommand { showCompletionMessage 1 } } {
1.1 albertel 3863: global gCapaConfig gStopPrinting gDonePrinting
3864:
3865: set errorMsg ""
3866: set error [ catch {exec $gCapaConfig(dvips_command) quiztemp.dvi \
3867: -o quiztemp.ps >& /dev/null} errorMsg ]
3868: if { $error } {
3869: displayError \
1.12 albertel 3870: "When attempting to run dvips an error occurred : $errorMsg"
1.1 albertel 3871: return 1
3872: }
3873:
3874: if { $gStopPrinting } {
3875: displayMessage "Printing has been stopped."
3876: set gStopPrinting 0
3877: set gDonePrinting 1
3878: return 1
3879: }
3880:
3881: set errorMsg
3882: set error [catch {set returnMessage [eval "exec $lprCommand"] } errorMsg ]
3883:
3884: if { $error == 1 } {
1.12 albertel 3885: displayError "When attempting to print an error occurred : $errorMsg"
1.1 albertel 3886: return 1
3887: } else {
3888: if { $showCompletionMessage } {
3889: displayMessage "Print job sent to the printer.\n $returnMessage"
3890: }
3891: }
3892:
3893: return 0
3894: }
3895:
3896:
3897:
3898: ###########################################################
3899: ###########################################################
3900: ###########################################################
3901: ###########################################################
3902: proc printCurrentDvi {} {
3903:
3904: set lprCommand [getLprCommand quiztemp.ps]
3905:
3906: if {$lprCommand == ""} {
3907: displayError "You must at least specify a print queue for lpr. \
3908: Nothing printed."
3909: return
3910: }
3911:
3912: if {$lprCommand == "Cancel"} {
3913: return
3914: }
3915:
3916: printBody $lprCommand
3917:
3918: return 0
3919: }
3920:
3921: ###########################################################
3922: ###########################################################
3923: ###########################################################
3924: ###########################################################
3925: proc printCurrentPreview {} {
3926:
3927: set lprCommand [getLprCommand quiztemp.ps]
3928:
3929: if {$lprCommand == ""} {
3930: displayError "You must at least specify a print queue for lpr. \
3931: Nothing printed."
3932: return
3933: }
3934:
3935: if {$lprCommand == "Cancel"} {
3936: return
3937: }
3938:
3939: if { [createDvi 0] == 2 } {
3940: displayMessage "Printing has been stopped"
3941: }
3942:
3943: printBody $lprCommand
3944:
3945: return 0
3946: }
3947:
3948: ###########################################################
3949: ###########################################################
3950: ###########################################################
3951: ###########################################################
3952: proc printRandom {} {
3953: global gStudentSelection gPrintSelection
3954:
3955: set lprCommand [getLprCommand quiztemp.ps]
3956:
3957: if {$lprCommand == ""} {
3958: displayError "You must at least specify a print queue for lpr. \
3959: Nothing printed."
3960: return
3961: }
3962:
3963: if {$lprCommand == "Cancel"} {
3964: return
3965: }
3966:
3967: set type $gStudentSelection(type)
3968: set random $gStudentSelection(random)
3969:
3970: set gStudentSelection(type) Random
3971: set gStudentSelection(random) $gPrintSelection(random)
3972:
3973: if { [createDvi 0 1] == 2 } {
3974: displayMessage "Printing has been stopped"
3975: }
3976:
3977: printBody $lprCommand
3978:
3979: set gStudentSelection(type) $type
3980: set gStudentSelection(random) $random
3981:
3982: return 0
3983: }
3984:
3985: ###########################################################
3986: ###########################################################
3987: ###########################################################
3988: ###########################################################
3989: proc printSpecific {} {
3990: global gStudentSelection gPrintSelection
3991:
3992: set lprCommand [getLprCommand quiztemp.ps]
3993:
3994: if {$lprCommand == ""} {
3995: displayError "You must at least specify a print queue for lpr. \
3996: Nothing printed."
3997: return
3998: }
3999:
4000: if {$lprCommand == "Cancel"} {
4001: return
4002: }
4003:
4004: set type $gStudentSelection(type)
4005: set studentNumber $gStudentSelection(studentNumber)
4006:
4007: set gStudentSelection(type) Specific
4008: set gStudentSelection(studentNumber) $gPrintSelection(studentNumber)
4009:
4010: if { [createDvi 0 1 1] == 2 } {
4011: displayMessage "Printing has been stopped"
4012: }
4013:
4014: printBody $lprCommand
4015:
4016: set gStudentSelection(type) $type
4017: set gStudentSelection(studentNumber) $studentNumber
4018:
4019: return 0
4020: }
4021:
4022: ###########################################################
4023: ###########################################################
4024: ###########################################################
4025: ###########################################################
4026: proc printStudent { studentNumber } {
4027: global gStudentSelection gStopPrinting gDonePrinting
4028:
4029: set type $gStudentSelection(type)
4030: set studentNumberOld $gStudentSelection(studentNumber)
4031:
4032: set gStudentSelection(type) Specific
4033: set gStudentSelection(studentNumber) $studentNumber
4034:
4035: set createdDvi [createDvi 0 1]
4036:
4037: if { $createdDvi == 1 } { printBody } else {
4038: displayMessage "Printing has been stopped"
4039: set gStopPrinting 0
4040: set gDonePrinting 1
4041: }
4042:
4043: set gStudentSelection(type) $type
4044: set gStudentSelection(studentNumber) $studentNumberOld
4045:
4046: return 0
4047: }
4048:
4049: proc checkDestroyPrint { createDviWindow } {
4050: global gDonePrinting
4051: if { !$gDonePrinting } {
4052: if { [makeSure "Do you really wish to stop printing?"] == "Yes" } {
4053: global gStopPrinting
4054: set gStopPrinting 1
4055: after 1000 "destroyPrint $createDviWindow"
4056: }
4057: return
4058: }
4059: destroyPrint $createDviWindow
4060: }
4061:
4062: proc destroyPrint { createDviWindow } {
4063: trace vdelete gFile w updateCreateDvi
4064: destroy $createDviWindow
4065: removeWindowEntry CreateDvi
4066: }
4067:
4068: ###########################################################
4069: ###########################################################
4070: ###########################################################
4071: ###########################################################
4072: proc setupSetsToPrint { setVar startVar endVar {checkForHeader 1}} {
4073: global gPrintSelection gSetNumberText gLoadHeaderSet
4074: upvar $setVar set $startVar start $endVar end
4075: if { $gPrintSelection(sets) == "printRange" } {
4076: set start $gPrintSelection(setstart)
4077: set end $gPrintSelection(setend)
4078: set set "$start:$end"
4079: set errors ""
4080: for {set i $start} {$i <= $end} {incr i} {
4081: set gLoadHeaderSet $i
4082: if {[catch {getHeaderInfo}]} { append errors ", $i" }
4083: }
4084: if { $checkForHeader && $errors != "" } {
4085: set errors [string range $errors 1 end]
4086: if { [llength $errors] > 1 } {
4087: set errors "s$errors"
4088: set errors [linsert $errors [expr [llength $errors] - 1] and]
4089: }
4090: displayError "DB header has not yet been set for set$errors. Please set the DB Header before printing Sections."
4091: return 1
4092: }
4093: } else {
4094: set start [set end [set set $gSetNumberText]]
4095: set gLoadHeaderSet $gSetNumberText
4096: if {$checkForHeader && [catch {getHeaderInfo}]} {
4097: displayError "DB header has not yet been set. Please set the DB Header before printing Sections."
4098: return 1
4099: }
4100: }
4101: }
4102:
4103: ###########################################################
4104: ###########################################################
4105: ###########################################################
4106: ###########################################################
4107: proc printSection { { lprCommand "" } } {
4108: global gPrintSelection gCapaConfig gSetNumberText gWindowMenu \
4109: gCreateDviText gStopPrinting gPrefs gFile gDonePrinting \
4110: gLoadHeaderSet
4111:
4112: set gDonePrinting 0
4113: set showStopping 0
4114:
4115: if { [setupSetsToPrint set start end] == 1 } { return 1}
4116: if { $lprCommand == "" } {
4117: set showStopping 1
4118: set lprCommand [getLprCommand quiztemp.ps]
4119: if { $lprCommand == "" } {
4120: displayError "Print command was empty, unable to print."
4121: return 1
4122: }
4123: if {$lprCommand == "Cancel" } {
4124: return 1
4125: }
4126: }
4127:
4128: createCreateDviWin
4129:
4130: grab .createDvi
4131:
4132: $gCreateDviText delete 0.0 end
4133:
4134: switch $gPrefs(info) {
4135: Problem { set type "-T" }
4136: Answer { set type "-Ta" }
4137: ProblemAnswer { set type "-Tb" }
4138: default { set type "-T" }
4139: }
4140:
1.8 albertel 4141: set prSection [string trimleft $gPrintSelection(section) 0]
4142:
1.1 albertel 4143: if { [set gStopPrinting [expr 2 == [runLatex \
4144: "echo [pwd] | $gCapaConfig(qzparse_command) \
1.8 albertel 4145: -sec $prSection -set $set \
1.1 albertel 4146: -d [pwd] -c [pwd] $type " gCreateDviText] ] ] } {
4147: for {set i $start} { $i <= $end} { incr i } {
1.8 albertel 4148: exec rm -f section$prSection-set$i.tex
1.1 albertel 4149: }
4150: if {$showStopping} {
4151: displayMessage "Printing has been stopped."
4152: set gDonePrinting 1
4153: set gStopPrinting 0
4154: }
4155: return 1
4156: }
4157: if { $gStopPrinting } {
4158: displayMessage "Printing has been stopped."
4159: set gDonePrinting 1
4160: set gStopPrinting 0
4161: return 1
4162: }
4163:
4164: for { set i $start} { $i <= $end } { incr i } {
1.8 albertel 4165: if { ! [file exists section$prSection-set$i.tex] } {
1.1 albertel 4166: if {$showStopping} {
4167: displayError "The qzparse command: $gCapaConfig(qzparse_command), was unable to produce the expected output. Printing stopped"
4168: set gStopPrinting 0
4169: set gDonePrinting 1
4170: }
4171: return 2
4172: }
4173:
1.8 albertel 4174: exec mv section$prSection-set$i.tex quiztemp.tex
1.1 albertel 4175: exec /bin/rm -f quiztemp.dvi
4176:
4177: $gCreateDviText insert end "$gCapaConfig(latex_command)\n"
4178: $gCreateDviText see end
4179:
4180: if { [set gStopPrinting [ expr 2 == [runLatex \
4181: "pwd ; $gCapaConfig(latex_command) \
4182: quiztemp.tex < [file join / dev null ]" gCreateDviText ] ] ] } {
4183: if {$showStopping} {
4184: displayError "The LaTeX command: $gCapaConfig(latex_command), was unable to produce the expected output. Printing stopped"
4185: set gStopPrinting 0
4186: set gDonePrinting 1
4187: }
4188: return 1
4189: }
4190:
4191: if { $gStopPrinting } {
4192: displayMessage "Printing has been stopped."
4193: set gDonePrinting 1
4194: set gStopPrinting 0
4195: return 1
4196: }
4197:
4198: set a [expr ($showStopping) && ($end == $i)]
4199: if { [set gStopPrinting [printBody $lprCommand $a ] ] } {
4200: if {$showStopping} {
4201: displayMessage "Printing has been stopped."
4202: set gDonePrinting 1
4203: set gStopPrinting 0
4204: }
4205: return 1
4206: }
4207: if { $gStopPrinting } {
4208: displayMessage "Printing has been stopped."
4209: set gDonePrinting 1
4210: set gStopPrinting 0
4211: return 1
4212: }
4213: }
4214:
4215: set gDonePrinting 1
4216: return 0
4217: }
4218:
4219: ###########################################################
4220: ###########################################################
4221: ###########################################################
4222: ###########################################################
4223: proc printMultipleSections { } {
4224: global gPrintSelection gCapaConfig gSetNumberText gWindowMenu \
4225: gCreateDviText gStopPrinting gPrefs gDonePrinting
4226:
4227: #checks if the DB Header is set
4228: if { [setupSetsToPrint set start end] == 1 } { return 1}
4229:
4230: set sectionList [ getExistingSections ]
4231: set sectionsToPrint [ pickSections $sectionList "Select Sections to Print:" ]
4232:
4233: if { $sectionsToPrint == "" } {
4234: displayMessage "No sections selected, therefore nothing was printed."
4235: return 1
4236: }
4237: if { $sectionsToPrint == "Cancel" } {
4238: return 1
4239: }
4240:
4241: set lprCommand [getLprCommand quiztemp.ps]
4242: if { $lprCommand == "" } {
4243: displayError "Print command was empty, unable to print."
4244: return 1
4245: }
4246: if {$lprCommand == "Cancel" } {
4247: return 1
4248: }
4249:
4250: if { [makeSure "You have selected to print $gPrefs(info)s for sections: [string trim $sectionsToPrint], using the print command \"$lprCommand\", continue?"] == "Cancel" } {
4251: return 1
4252: }
4253:
4254: foreach section $sectionsToPrint {
4255: set gDonePrinting 0
4256: set gPrintSelection(section) $section
4257: if { [set gStopPrinting [printSection $lprCommand] ] } {
4258: set gDonePrinting 0
4259: if { $gStopPrinting == 2 } {
4260: displayError "The qzparse command: $gCapaConfig(qzparse_command), was unable to produce the expected output. Printing stopped"
4261: } else {
4262: displayMessage "Printing has been stopped."
4263: }
4264: set gDonePrinting 1
4265: return 1
4266: }
4267: if { $gStopPrinting } {
4268: displayMessage "Printing has been stopped."
4269: set gStopPrinting 0
4270: set gDonePrinting 1
4271: return 1
4272: }
4273: }
4274: set gDonePrinting 1
4275: displayMessage "Print jobs sent to the printer."
4276: return 0
4277: }
4278:
4279: ###########################################################
4280: ###########################################################
4281: ###########################################################
4282: ###########################################################
4283: proc printWholeClass { } {
4284: global gPrintSelection gCapaConfig gSetNumberText gWindowMenu \
4285: gCreateDviText gStopPrinting gPrefs gDonePrinting
4286:
4287: if {[catch {getHeaderInfo}]} {
4288: displayError "DB header has not yet been set, Please set DB Header before printing Sections."
4289: return 1
4290: }
4291: set sectionsToPrint [ getExistingSections ]
4292:
4293: if { $sectionsToPrint == "" } {
4294: displayMessage "No sections exist, therefore nothing was printed."
4295: return 1
4296: }
4297:
4298: set lprCommand [getLprCommand quiztemp.ps]
4299:
4300: if { $lprCommand == "" } {
4301: displayError "Print command was empty, unable to print."
4302: return 1
4303: }
4304: if {$lprCommand == "Cancel" } {
4305: return 1
4306: }
4307:
4308: if { [makeSure "You have selected to print $gPrefs(info)s for the entire class of [llength $sectionsToPrint] sections, using the print command $lprCommand, continue?"] == "Cancel" } {
4309: return 1
4310: }
4311:
4312: foreach section $sectionsToPrint {
4313: set section [lindex $section 0]
4314: set gPrintSelection(section) $section
4315: set gStopPrinting [printSection $lprCommand]
4316: if { $gStopPrinting } {
4317: if { $gStopPrinting == 2 } {
4318: displayError "$gCapaConfig(qzparse_command) was unable to produce the expected output. Printing stopped"
4319: } else {
4320: displayMessage "Printing has been stopped."
4321: }
4322: set gDonePrinting 1
4323: set gStopPrinting 0
4324: return 1
4325: }
4326: }
4327: set gDonePrinting 1
4328: displayMessage "Print jobs sent to the printer."
4329: return 0
4330: }
4331:
4332: ###########################################################
4333: # analyzeSet
4334: ###########################################################
4335: ###########################################################
4336: ###########################################################
4337: proc analyzeSet {} {
4338: global gChanged gWindowMenu gEditWindow gAnalyze gSetNumberText gNumberParsedText
4339:
4340: if { [catch {winfo exists $gEditWindow}] } { return }
4341: if { ![ winfo exists $gEditWindow ] } { return }
4342: if { $gChanged } { if { [askToSave 0 0] == "Cancel" } { return } }
4343: if { [winfo exists .analyzeSet] } {
4344: capaRaise .analyzeSet
4345: return
4346: }
4347:
4348: set analyze [toplevel .analyzeSet]
4349: $gWindowMenu add command -label "AnalyzeSet" \
4350: -command "capaRaise $analyze"
4351: wm title $analyze "Analyze Set"
4352:
4353: set settingsFrame [frame $analyze.settingsFrame]
4354: set dataFrame [frame $analyze.dataFrame]
4355: pack $settingsFrame $dataFrame -side top
4356:
4357: set classFrame [frame $settingsFrame.classFrame]
4358: set setFrame [frame $settingsFrame.setFrame]
4359: set probFrame [frame $settingsFrame.probFrame]
4360: set statusFrame [frame $settingsFrame.statusFrame]
4361: set statusBar [frame $settingsFrame.statusBar]
4362: set buttonFrame [frame $settingsFrame.buttonFrame]
4363: pack $classFrame $setFrame $probFrame $statusFrame $statusBar $buttonFrame \
4364: -side top
4365:
4366: set canvasFrame [frame $dataFrame.canvasFrame]
4367: set numberFrame [frame $dataFrame.numberFrame]
4368: pack $canvasFrame $numberFrame -side top
4369:
4370: set gAnalyze(class) [pwd]
4371: label $classFrame.label -textvariable gAnalyze(class)
4372: pack $classFrame.label
4373:
4374: set gAnalyze(set) $gSetNumberText
4375: label $setFrame.lbl -text "Set number:"
4376: label $setFrame.set -textvariable gAnalyze(set)
4377: # button $setFrame.change -text "Change" -command analyzeChangeSet
4378: pack $setFrame.lbl $setFrame.set -side left
4379:
4380: if { [set gAnalyze(maxprob) $gNumberParsedText] == "" } { set gAnalyze(maxprob) 1 }
4381:
4382: label $probFrame.label -text "Problem Number :"
4383: set gAnalyze(scale) [scale $probFrame.problem \
4384: -from 1 -to $gAnalyze(maxprob) \
4385: -variable gAnalyze(prob) -command analyzeUpdate \
4386: -orient h -length 150 -tickinterval 1]
4387: pack $probFrame.label $probFrame.problem -side left
4388:
4389: set gAnalyze(status) ""
4390: label $statusFrame.label -text "Status:"
4391: label $statusFrame.status -textvariable gAnalyze(status)
4392: pack $statusFrame.label $statusFrame.status -side left
4393:
4394: set gAnalyze(statcanvas) [canvas $statusBar.canvas -width 200 -height 20]
4395: pack $statusBar.canvas
4396: $gAnalyze(statcanvas) create rectangle 1 1 199 19 -outline black
4397: set gAnalyze(bar) [$gAnalyze(statcanvas) create rectangle 1 1 1 19 -fill red -outline black]
4398:
4399: button $buttonFrame.class -text "Run Class" -command "analyzeClass 1"
4400: button $buttonFrame.random -text "Run Random" -command analyzeRandom
4401: button $buttonFrame.stop -text "Stop" -command analyzeStop
4402: button $buttonFrame.close -text "Dismiss" -comman analyzeClose
4403: pack $buttonFrame.class $buttonFrame.random $buttonFrame.stop \
4404: $buttonFrame.close -side left
4405:
4406: set gAnalyze(canvaswidth) 600
4407: set gAnalyze(canvas) [canvas $canvasFrame.canvas -width $gAnalyze(canvaswidth) \
4408: -height 100]
4409: pack $gAnalyze(canvas)
4410:
4411: set hiFrame [frame $numberFrame.hiFrame]
4412: set lowFrame [frame $numberFrame.lowFrame]
4413: set uniqFrame [frame $numberFrame.uniqFrame]
4414: pack $lowFrame $hiFrame $uniqFrame -side left
4415: pack configure $hiFrame -anchor e
4416: pack configure $lowFrame -anchor w
4417:
4418: label $hiFrame.label -text "High End:"
4419: label $hiFrame.num -textvariable gAnalyze(highnum)
4420: pack $hiFrame.label $hiFrame.num -side left
4421:
4422: label $lowFrame.label -text "Low End:"
4423: label $lowFrame.num -textvariable gAnalyze(lownum)
4424: pack $lowFrame.label $lowFrame.num -side left
4425:
4426: label $uniqFrame.label -text "Num. Unique:"
4427: label $uniqFrame.num -textvariable gAnalyze(numuniq)
4428: pack $uniqFrame.label $uniqFrame.num -side left
4429:
4430: set gAnalyze(studentNumbers) [getStudentNumbers]
4431: set gAnalyze(exit) 0
4432: }
4433:
4434: ###########################################################
4435: # analyzeClass
4436: ###########################################################
4437: ###########################################################
4438: ###########################################################
4439: proc analyzeClass { {start 1} } {
4440: global gAnalyze gCapaConfig
4441: if { $gAnalyze(studentNumbers)=="" } { return }
4442: if { $start } {
4443: set gAnalyze(toprocess) $gAnalyze(studentNumbers)
4444: set gAnalyze(stop) 0
4445: set gAnalyze(update) 1
4446: set gAnalyze(done) 0
4447: set gAnalyze(total) [expr [llength $gAnalyze(toprocess)]/3]
4448: foreach name [array names gAnalyze *.\[alhu\]*] { unset gAnalyze($name) }
4449: }
4450: set number [lindex $gAnalyze(toprocess) 0]
4451: set name [lindex $gAnalyze(toprocess) 1]
4452: set section [lindex $gAnalyze(toprocess) 2]
4453: set gAnalyze(toprocess) [lrange $gAnalyze(toprocess) 3 end]
1.11 albertel 4454: set command "$gCapaConfig(answers_command) $number \"$name\" 0 $gAnalyze(set)"
1.1 albertel 4455: set fileId [open "|$command" "r"]
4456: set gAnalyze(pid) [pid $fileId]
4457: fconfigure $fileId -blocking 0
4458: fileevent $fileId readable "analyzeLine $fileId"
4459: set gAnalyze(status) "Processing $number"
4460: incr gAnalyze(done)
4461: $gAnalyze(statcanvas) coords $gAnalyze(bar) 1 1 [expr 200*($gAnalyze(done)/double($gAnalyze(total)))] 19
4462: update idletasks
4463: }
4464:
4465: ###########################################################
4466: # analyzeEatQuestion
4467: ###########################################################
4468: ###########################################################
4469: ###########################################################
4470: proc analyzeEatQuestion { fileId } {
4471: global gAnalyze
4472: if { $gAnalyze(exit) } {
4473: fileevent $fileId readable ""
4474: catch {close $fileId}
4475: return
4476: }
4477: set aline [gets $fileId]
4478: if { $aline != "" } {
4479: switch -- [lindex [split $aline :] 0] {
4480: EQES { fileevent $fileId readable "analyzeLine $fileId" }
4481: }
4482: }
4483: if { [eof $fileId] } { analyzeEnd $fileId }
4484: }
4485:
4486: ###########################################################
4487: # analyzeLine
4488: ###########################################################
4489: ###########################################################
4490: ###########################################################
4491: proc analyzeLine { fileId } {
4492: global gAnalyze
4493:
4494: if { $gAnalyze(exit) } {
4495: fileevent $fileId readable ""
4496: catch {close $fileId}
4497: return
4498: }
4499: set aline [gets $fileId]
4500: if { $aline != "" } {
4501: switch [lindex [split $aline :] 0] {
4502: ANS {
4503: incr gAnalyze(problemNum)
4504: set ans [string range $aline 4 end]
4505: set length [llength $ans]
4506: lappend gAnalyze($gAnalyze(problemNum).ans) \
4507: [lindex $ans 0]
4508: if { ($length == 2) || ($length == 4)} {
4509: lappend gAnalyze($gAnalyze(problemNum).unit) \
4510: [lindex $ans end]
4511: }
4512: if { ($length == 3) || ($length == 4) } {
4513: lappend gAnalyze($gAnalyze(problemNum).low) \
4514: [lindex $ans 1]
4515: lappend gAnalyze($gAnalyze(problemNum).high) \
4516: [lindex $ans 2]
4517: }
4518: }
4519: SET { set gAnalyze(problemNum) 0 }
4520: DONE {
4521: set gAnalyze(maxprob) $gAnalyze(problemNum)
4522: $gAnalyze(scale) configure -to $gAnalyze(maxprob)
4523: }
4524: ERROR {
4525: fileevent $fileId readable ""
4526: displayError "Answers returned invalid message: $aline"
4527: fileevent $fileId readable "analyzeLine $fileId"
4528: }
4529: BQES { fileevent $fileId readable "analyzeEatQuestion $fileId" }
4530: default {
4531: }
4532: }
4533: }
4534: if { [eof $fileId] } { analyzeEnd $fileId }
4535: }
4536:
4537: ###########################################################
4538: # analyzeEnd
4539: ###########################################################
4540: ###########################################################
4541: ###########################################################
4542: proc analyzeEnd { fileId } {
4543: global gAnalyze
4544: if { [eof $fileId] } {
4545: fileevent $fileId readable ""
4546: catch {close $fileId}
4547: if { $gAnalyze(stop) } { return }
4548: if { [llength $gAnalyze(toprocess)] > 0 } {
4549: analyzeClass 0
4550: } else {
4551: analyzeUpdate
4552: set gAnalyze(status) "Done"
4553: }
4554: if { !$gAnalyze(update) } {
4555: incr gAnalyze(update)
4556: analyzeUpdate
4557: } else {
4558: incr gAnalyze(update)
4559: if { $gAnalyze(update) == 10 } {
4560: set gAnalyze(update) 0
4561: }
4562: }
4563: }
4564: }
4565:
4566: ###########################################################
4567: # analyzeRandom
4568: ###########################################################
4569: ###########################################################
4570: ###########################################################
4571: proc analyzeRandom { } {
4572: global gAnalyze
4573: set numToRun [getString . "How many random students should be run?"]
4574: if { $numToRun == "" } { return }
4575: if { [catch {incr numToRun} ] } {
4576: displayMessage "Invalid number."
4577: }
4578: incr numToRun -1
4579: set gAnalyze(total) $numToRun
4580: catch {unset gAnalyze(toprocess)}
4581: for { set i 0 } { $i < $numToRun } { incr i } {
4582: append gAnalyze(toprocess) "[format "%09d" $i] Random 999 "
4583: }
4584: set gAnalyze(stop) 0
4585: set gAnalyze(update) 1
4586: set gAnalyze(done) 0
4587: foreach name [array names gAnalyze *.\[alhu\]*] { unset gAnalyze($name) }
4588: analyzeClass 0
4589: }
4590:
4591: ###########################################################
1.4 albertel 4592: # analyzeStrings
4593: ###########################################################
4594: ###########################################################
4595: ###########################################################
4596: proc analyzeStrings { prob window create} {
4597: global gAnalyze
4598:
4599: if { ![winfo exists $window.analyzestrings] } { if {!$create} { return } }
4600: if { ![catch {set setWin [toplevel $window.analyzestrings]}] } {
4601: set msgFrame [frame $setWin.msgFrame]
4602: set valFrame [frame $setWin.valFrame]
4603: set buttonFrame [frame $setWin.buttonFrame]
4604: pack $msgFrame $valFrame $buttonFrame
4605: pack configure $valFrame -expand 1 -fill both
4606:
4607: message $msgFrame.msg -text "Correct Answers" -aspect 3000
4608: pack $msgFrame.msg
4609:
4610: set maxWidth 1
4611: foreach choice $gAnalyze($prob.ans) {
4612: if {[string length $choice]>$maxWidth} {set maxWidth [string length $choice]}
4613: }
4614: set maxStringWidth $maxWidth
4615: incr maxWidth 6
4616:
4617: set selectMode none
4618: listbox $valFrame.val -width [expr $maxWidth + 2] \
4619: -yscrollcommand "$valFrame.scroll set" -selectmode $selectMode
4620: scrollbar $valFrame.scroll -command "$valFrame.val yview"
4621: pack $valFrame.val $valFrame.scroll -side left
4622: pack configure $valFrame.val -expand 1 -fill both
4623: pack configure $valFrame.scroll -expand 0 -fill y
4624: button $buttonFrame.cancel -text "Dismiss" -command "destroy $setWin"
4625: pack $buttonFrame.cancel
4626: } else {
4627: set maxWidth 1
4628: set valFrame $window.analyzestrings.valFrame
4629: $valFrame.val delete 0 end
4630: foreach choice $gAnalyze($prob.ans) {
4631: if {[string length $choice]>$maxWidth} {set maxWidth [string length $choice]}
4632: }
4633: set maxStringWidth $maxWidth
4634: incr maxWidth 6
4635: }
4636: set lastchoice [lindex $gAnalyze($gAnalyze(prob).ans) 0]
4637: set num 1
4638: foreach choice [lsort $gAnalyze($gAnalyze(prob).ans)] {
4639: if { $lastchoice != $choice } {
4640: $valFrame.val insert end \
4641: "[format %-[set maxStringWidth]s $lastchoice] [format %5d $num]"
4642: set lastchoice $choice
4643: set num 1
4644: } else {
4645: incr num
4646: }
4647: }
4648: $valFrame.val insert end \
4649: "[format %-[set maxStringWidth]s $lastchoice] [format %5d $num]"
4650: }
4651:
4652: ###########################################################
1.1 albertel 4653: # analyzeUpdate
4654: ###########################################################
4655: ###########################################################
4656: ###########################################################
4657: proc analyzeUpdate { {newProbNumber 0} } {
4658: global gAnalyze
4659:
4660: if {[catch {set gAnalyze($gAnalyze(prob).ans)}]} { return }
4661: foreach problem [array names gAnalyze *.\[alh\]*] {
4662: if { [catch {set gAnalyze($problem) [lsort -real $gAnalyze($problem)]}]} {
4663: set gAnalyze($problem) [lsort $gAnalyze($problem)]
4664: }
4665: }
4666:
4667: set c $gAnalyze(canvas)
4668: $c delete all
4669: set gAnalyze(lownum) [set low [lindex $gAnalyze($gAnalyze(prob).ans) 0]]
4670: set gAnalyze(highnum) [set high [lindex $gAnalyze($gAnalyze(prob).ans) end]]
4671: set gAnalyze(numuniq) [llength [lunique $gAnalyze($gAnalyze(prob).ans)]]
4672: #don't draw anything if the answers aren't numbers
1.4 albertel 4673: if { [catch {expr $low + 1}]} {
4674: catch {destroy $c.button}
4675: update idletask
4676: button $c.button -text "List of strings" -command \
4677: "analyzeStrings $gAnalyze(prob) $c 1"
4678: $c create window [expr $gAnalyze(canvaswidth)/2.0] 40 -window $c.button
4679: analyzeStrings $gAnalyze(prob) $c 0
4680: return
4681: }
1.1 albertel 4682:
4683: $c create line 25 50 [expr $gAnalyze(canvaswidth) - 25] 50
4684: set diff [expr double($high-$low)]
4685: if { $diff == 0 } {
4686: set center [expr $gAnalyze(canvaswidth)/2.0]
1.4 albertel 4687: $c create rectangle [expr $center - 2] 48 [expr $center + 2] 52 -fill green
1.1 albertel 4688: update idletasks
4689: return
4690: }
4691: set delta [format "%1.e" [expr ($diff)/15.0]]
4692: set start [expr double(int($low/$delta)+1)*$delta]
4693: while { $start < $high } {
4694: set center [expr ($gAnalyze(canvaswidth)-50)*(($start-$low)/$diff)]
4695: set center [expr $center+25]
4696: $c create line $center 40 $center 60
4697: set start [expr $start + $delta]
4698: }
4699: if { ($low < 0) && ($high > 0) } {
4700: set center [expr ($gAnalyze(canvaswidth)-50)*((0-$low)/$diff)]
4701: set center [expr $center+25]
4702: $c create rectangle [expr $center - 1] 40 [expr $center + 1] 60
4703: }
1.3 albertel 4704: set lastpoint [lindex $gAnalyze($gAnalyze(prob).ans) 0]
4705: set num 0
1.1 albertel 4706: foreach point $gAnalyze($gAnalyze(prob).ans) {
1.3 albertel 4707: if { $lastpoint != $point } {
4708: set center [expr ($gAnalyze(canvaswidth)-50)*(($lastpoint-$low)/$diff)]
4709: set center [expr $center+25]
1.4 albertel 4710: $c create rectangle [expr $center - 2] [expr 48-$num] \
4711: [expr $center + 2] [expr 52+$num] -fill green
1.3 albertel 4712: set lastpoint $point
4713: set num 0
4714: } else {
4715: incr num
4716: }
1.1 albertel 4717: }
1.4 albertel 4718: set center [expr ($gAnalyze(canvaswidth)-50)*(($lastpoint-$low)/$diff)]
4719: set center [expr $center+25]
4720: $c create rectangle [expr $center - 2] [expr 48-$num] \
4721: [expr $center + 2] [expr 52+$num] -fill green
1.1 albertel 4722:
4723: update idletasks
4724: }
4725:
4726: ###########################################################
4727: # analyzeStop
4728: ###########################################################
4729: ###########################################################
4730: ###########################################################
4731: proc analyzeStop {} {
4732: global gAnalyze
4733: set gAnalyze(stop) 1
4734: set gAnalyze(status) "Stopped"
1.9 albertel 4735: catch {exec kill -SIGKILL $gAnalyze(pid)}
1.1 albertel 4736: }
4737:
4738: ###########################################################
4739: # analyzeClose
4740: ###########################################################
4741: ###########################################################
4742: ###########################################################
4743: proc analyzeClose { } {
4744: global gAnalyze
4745: destroy [winfo toplevel $gAnalyze(canvas)]
4746: unset gAnalyze
4747: global gAnalyze
4748: set gAnalyze(exit) 1
4749: }
4750:
4751: ###########################################################
4752: # checkIfValidFilename
4753: ###########################################################
4754: ###########################################################
4755: ###########################################################
4756: proc checkIfValidFilename {} {
4757: global gSetNumberText gPreviewButton
4758: if { [regexp \[^0-9\]+ $gSetNumberText] } {
4759: displayError "This file is not properly named. \n\nA main assignment file must be named setX.qz, where X is replaced by a number between 1 and 99 inclusive. \n\nPlease do a \"Save .qz As\". \n\nUntil the file is properly named you will not be able to Preview, Create .dvi, or Print."
4760: $gPreviewButton configure -state disabled
4761: .main entryconfigure 5 -state disabled
4762: .main entryconfigure 7 -state disabled
4763: return 0
4764: }
4765: $gPreviewButton configure -state normal
4766: .main entryconfigure 5 -state normal
4767: .main entryconfigure 7 -state normal
4768: return 1
4769: }
4770:
4771: ###########################################################
4772: # updateChangeStatus
4773: ###########################################################
4774: ###########################################################
4775: ###########################################################
4776: proc updateChangeStatus { name1 name2 op } {
4777: global gChanged gRefChanged gRefText gChangedLast gRefChangedLast \
4778: gEditWindow gWindowMenu gRefFile
4779: if { $name1 == "gChanged" } {
4780: if { $gChanged != $gChangedLast } {
4781: set gChangedLast $gChanged
4782: global gFile
4783: if { [catch {set gEditWindow}] } { return }
4784: if { ![winfo exists $gEditWindow] } { return }
4785: if { $gChanged } {
4786: catch {removeWindowEntry "$gFile*"}
4787: wm title [winfo toplevel $gEditWindow] "$gFile (Modified)"
4788: $gWindowMenu add command -label "$gFile (Modified)" -command \
4789: "capaRaise $gEditWindow"
4790: } else {
4791: catch {removeWindowEntry "$gFile*"}
4792: wm title [winfo toplevel $gEditWindow] "$gFile"
4793: $gWindowMenu add command -label "$gFile" -command \
4794: "capaRaise $gEditWindow"
4795: }
4796: }
4797: } else {
4798: if { $gRefChanged($name2) != $gRefChangedLast($name2) } {
4799: if { [catch {set gRefText($name2)}] } { return }
4800: if { ![winfo exists $gRefText($name2)] } { return }
4801: if { $gRefChanged($name2) } {
4802: catch {removeWindowEntry "Reference $gRefFile($name2)*" }
4803: wm title [winfo toplevel $gRefText($name2)] "$gRefFile($name2) (Modified)"
4804: $gWindowMenu add command -label "Reference $gRefFile($name2) (Modified)" \
4805: -command "capaRaise [winfo toplevel $gRefText($name2)]"
4806: } else {
4807: catch {removeWindowEntry "Reference $gRefFile($name2)*" }
4808: wm title [winfo toplevel $gRefText($name2)] "$gRefFile($name2)"
4809: $gWindowMenu add command -label "Reference $gRefFile($name2)" \
4810: -command "capaRaise [winfo toplevel $gRefText($name2)]"
4811: }
4812: }
4813: }
4814: }
4815: ###########################################################
4816: # main
4817: ###########################################################
4818: # sets up the auto_path variable, some globals and adds some
4819: # options then calls createControlWindow to give the user something
4820: # to do
4821: ###########################################################
4822: # Arguments: None
4823: # Returns: Nothing
4824: # Globals:
4825: ###########################################################
4826:
4827: source quizzer.templates.tcl
4828:
4829: if { [lindex $auto_path 0] == "./lib/tcl7.5" } {
4830: set auto_path ""
4831: lappend auto_path [pwd]/lib/tcl7.5
4832: lappend auto_path [pwd]/lib/tk4.1
4833: }
4834:
4835: lappend auto_path /usr/local/lib/CAPA45/Quizzer
4836: lappend auto_path [pwd]
4837:
4838: set font 8x13bold
4839: catch {
4840: if { $argc > 0 } {
4841: switch -glob -- [lindex $argv 0] {
4842: {-[Ll]*} { set font 9x15bold }
4843: {-[Mm]*} -
4844: {-[Nn]*} { set font 8x13bold }
4845: {-[Ss]*} { set font fixed }
4846: }
4847: }
4848: }
4849: option add *font $font
4850: createControlWindow
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>