Annotation of capa/capa51/GUITools/ideas/of5tool/multiplechoice.tcl, revision 1.1.1.1

1.1       albertel    1: proc MCinit {} {
                      2:     global problem
                      3: 
                      4:     set problem(MCeditleaf) 0
                      5: }
                      6: 
                      7: proc MCadd {} {
                      8:     global problem MCchoiceList
                      9:     
                     10:     set addMultiple [toplevel .mcaddMultiple]
                     11:     
                     12:     if { $problem(editing) == 0 } {
                     13: 	set probnum $problem(num)
                     14: 	set problem(prob.$problem(num).numleaf) 0
                     15: 	set problem(prob.$problem(num).type) "Multiple Choice"
                     16: 	set problem(prob.$problem(num).val) 1
                     17:     } else {
                     18: 	set probnum $problem(editing)
                     19:     }
                     20: 
                     21:     set labelFrame [frame $addMultiple.labelFrame ]
                     22:     set probValFrame [frame $addMultiple.probValFrame ]
                     23:     set hintFrame [frame $addMultiple.hintFrame ]
                     24:     set explFrame [frame $addMultiple.explFrame ]
                     25:     set questFrame [frame $addMultiple.questFrame ]
                     26:     set listFrame [frame $addMultiple.listFrame ]
                     27:     set buttonFrame [frame $addMultiple.buttonFrame]
                     28:     pack $labelFrame $probValFrame $questFrame $hintFrame $explFrame \
                     29: 	$listFrame $buttonFrame -side top
                     30:     pack config $probValFrame -anchor w
                     31: 
                     32:     label $labelFrame.probLabel -text "Problem $probnum"
                     33:     pack $labelFrame.probLabel
                     34: 
                     35:     label $probValFrame.label -text "Problem Value\n"
                     36:     scale $probValFrame.value -variable problem(prob.$probnum.val) -from 1 -to 9 -orient h
                     37:     pack $probValFrame.label $probValFrame.value -side left
                     38: 
                     39:     label $questFrame.label -text "Question:"
                     40:     entry $questFrame.entry -textvariable problem(prob.$probnum.quest) \
                     41: 	-width 80 -xscrollcommand "$questFrame.scroll set"
                     42:     scrollbar $questFrame.scroll -command "$questFrame.entry xview" \
                     43: 	-orient h
                     44:     pack $questFrame.label $questFrame.entry $questFrame.scroll -side top
                     45:     pack configure $questFrame.label -anchor w
                     46:     pack configure $questFrame.scroll -fill x
                     47: 
                     48:     label $hintFrame.label -text "Hint:"
                     49:     entry $hintFrame.entry -textvariable problem(prob.$probnum.hint) \
                     50: 	-width 80 -xscrollcommand "$hintFrame.scroll set"
                     51:     scrollbar $hintFrame.scroll -command "$hintFrame.entry xview" \
                     52: 	-orient h
                     53:     pack $hintFrame.label $hintFrame.entry $hintFrame.scroll -side top
                     54:     pack configure $hintFrame.label -anchor w
                     55:     pack configure $hintFrame.scroll -fill x
                     56: 
                     57:     label $explFrame.label -text "Explanation:"
                     58:     entry $explFrame.entry -textvariable problem(prob.$probnum.expl) \
                     59: 	-width 80 -xscrollcommand "$explFrame.scroll set"
                     60:     scrollbar $explFrame.scroll -command "$explFrame.entry xview" \
                     61: 	-orient h
                     62:     pack $explFrame.label $explFrame.entry $explFrame.scroll -side top
                     63:     pack configure $explFrame.label -anchor w
                     64:     pack configure $explFrame.scroll -fill x
                     65: 
                     66:     set MCchoiceList [ listbox $listFrame.list \
                     67: 			 -yscrollcommand "$listFrame.scroll set" \
                     68: 			 -width 80 -height 10 ]
                     69:     scrollbar $listFrame.scroll -command "$listFrame.list yview" \
                     70: 	-orient v
                     71:     pack $listFrame.list $listFrame.scroll -side left
                     72:     pack configure $listFrame.scroll -fill y
                     73: 
                     74:     button $buttonFrame.leaf -text "Add leaf" -command MCaddLeaf
                     75:     button $buttonFrame.edit -text "Edit leaf" -command MCeditLeafOptions
                     76:     button $buttonFrame.done -text "Done" -command "
                     77:         if { [ MCcheckIfDone $probnum ] } {
                     78: 	   destroy $addMultiple
                     79: 	   set problem(adding) 0
                     80:            set problem(editing) 0
                     81:            set problem(editleaf) 0
                     82:            updateProblemList $probnum
                     83:         } else {
                     84:            tk_messageBox -icon error \
                     85:                -message "At least one leaf needs all options to be correct."
                     86:                -type ok
                     87:         }
                     88:     "
                     89:     button $buttonFrame.cancel -text "Cancel" -command "
                     90: 	destroy $addMultiple
                     91: 	incr problem(num) -1
                     92: 	#(FIXME) unset possible set vars dealing with this problem
                     93:     "
                     94:     pack $buttonFrame.done $buttonFrame.leaf $buttonFrame.edit \
                     95: 	$buttonFrame.cancel -side left
                     96: }
                     97: 
                     98: proc MCaddLeaf {} {
                     99:     global problem
                    100: 
                    101:     if { $problem(editing) == 0 } {
                    102: 	set probnum $problem(num)
                    103:     } else {
                    104: 	set probnum $problem(editing)
                    105:     }
                    106: 
                    107:     if { $problem(MCeditleaf) == 0 } { 
                    108: 	set leaf [incr problem(prob.$probnum.numleaf)]
                    109: 	set problem(prob.$probnum.leaf.$leaf.numoptions) 1
                    110:     } else {
                    111: 	set leaf $problem(MCeditleaf)
                    112:     }
                    113: 
                    114:     set addLeaf [toplevel .mcaddleaf]
                    115:     
                    116:     set labelFrame [frame $addLeaf.label]
                    117:     set buttonFrame [frame $addLeaf.button]
                    118:     pack $labelFrame $buttonFrame -side top
                    119:     pack configure $buttonFrame -anchor s
                    120: 
                    121:     label $labelFrame.label -text "Adding options for leaf $leaf"
                    122:     pack $labelFrame.label -side top
                    123: 
                    124: 
                    125:     for { set i 1 } { $i <= $problem(prob.$probnum.leaf.$leaf.numoptions) } { incr i } {	
                    126: 	set leafFrame [frame $addLeaf.frame$i]
                    127: 	label $leafFrame.label -text "Leaf $leaf Option $i:"
                    128: 	checkbutton $leafFrame.correct -text Correct -offvalue 2 \
                    129: 	    -variable problem(prob.$probnum.leaf.$leaf.option.$i.correct)
                    130: 	entry $leafFrame.entry \
                    131: 	    -textvariable problem(prob.$probnum.leaf.$leaf.option.$i) \
                    132: 	    -width 80 -xscrollcommand "$leafFrame.scroll set"
                    133: 	scrollbar $leafFrame.scroll -command "$leafFrame.entry xview" \
                    134: 	    -orient h
                    135: 	pack $leafFrame -before $buttonFrame
                    136: 	pack $leafFrame.label $leafFrame.correct $leafFrame.entry \
                    137: 	    $leafFrame.scroll -side top -anchor w
                    138: 	pack configure $leafFrame.scroll -fill x
                    139:     }
                    140: 
                    141:     button $buttonFrame.add -text "Add option" -command {
                    142: 	if { $problem(editing) == 0 } { set probnum $problem(num)
                    143: 	} else { set probnum $problem(editing) }
                    144: 	
                    145: 	if { $problem(MCeditleaf) == 0 } { set leaf $problem(prob.$probnum.numleaf)
                    146: 	} else { set leaf $problem(MCeditleaf) }
                    147: 	set optnum [incr problem(prob.$probnum.leaf.$leaf.numoptions)] 
                    148: 	set leafFrame [frame .mcaddleaf.frame$optnum]
                    149: 	pack $leafFrame -before .mcaddleaf.button
                    150: 
                    151: 	label $leafFrame.label -text "Leaf $leaf Option $optnum:"
                    152: 	checkbutton $leafFrame.correct -text Correct -offvalue 2 \
                    153: 	    -variable problem(prob.$probnum.leaf.$leaf.option.$optnum.correct)
                    154: 	entry $leafFrame.entry \
                    155: 	    -textvariable problem(prob.$probnum.leaf.$leaf.option.$optnum) \
                    156: 	    -width 80 -xscrollcommand "$leafFrame.scroll set"
                    157: 	scrollbar $leafFrame.scroll \
                    158: 	    -command "$leafFrame.entry xview" \
                    159: 	    -orient h
                    160: 	pack $leafFrame.label $leafFrame.correct $leafFrame.entry \
                    161: 	    $leafFrame.scroll -side top -anchor w
                    162: 	pack configure $leafFrame.scroll -fill x
                    163:     }
                    164:     button $buttonFrame.cancel -text "Cancel" -command "
                    165: 	destroy $addLeaf
                    166: 	#(FIXME) this needs to do alot more
                    167:     "
                    168:     button $buttonFrame.done -text "Done" \
                    169: 	-command "
                    170: 	          destroy .mcaddleaf
                    171: 	          MCupdateLeafList $leaf $probnum 
                    172:                   set problem(MCeditleaf) 0"
                    173:     pack $buttonFrame.add $buttonFrame.cancel $buttonFrame.done -side left
                    174: }
                    175: 
                    176: proc MCcheckIfDone { probnum } {
                    177:     global problem
                    178: 
                    179:     set found 0
                    180:     for { set i 1 } { i <= $problem(prob.$probnum.numleaf } { incr i } {
                    181: 	set found 1
                    182: 	for { set j 1 } { j <= $problem(prob.$probnum.leaf.$i.numoptions) } { incr j } {
                    183: 	    catch {
                    184: 		if { $problem(prob.$probnum.leaf.$i.option.$j.correct) != 1 } {
                    185: 		    set found 0
                    186: 		}
                    187: 	    }
                    188: 	}
                    189:     }
                    190:     return $found
                    191: }
                    192: 
                    193: 
                    194: proc MCeditLeafOptions {} {
                    195:     global problem MCchoiceList
                    196: 
                    197:     set leaf [$MCchoiceList curselection]
                    198:     if { $leaf == "" } { return }
                    199:     incr leaf
                    200:     set problem(MCeditleaf) $leaf
                    201: 
                    202:     if { $problem(editing) == 0 } {
                    203: 	set probnum $problem(num)
                    204:     } else {
                    205: 	set probnum $problem(editing)
                    206:     }
                    207: 
                    208:     MCaddLeaf
                    209: }
                    210: 
                    211: proc MCupdateLeafList { leaf probnum } {
                    212:     global problem MCchoiceList
                    213: 
                    214:     set numLeafs [$MCchoiceList size]
                    215:     set numOpt $problem(prob.$probnum.leaf.$leaf.numoptions)
                    216: 
                    217:     if { $numLeafs < $leaf } {
                    218:     } else {
                    219: 	$MCchoiceList delete  [ expr $leaf - 1 ]
                    220:     }
                    221: 
                    222:     set string "Leaf $leaf, $numOpt options"
                    223:     
                    224:     $MCchoiceList insert [ expr $leaf - 1 ] "$string"
                    225: }
                    226: 
                    227: proc MCexportHeader { fileid probnum } {
                    228:     global problem
                    229: 
                    230:     puts $fileid "//****************************"
                    231:     puts $fileid "/LET prob_val=$problem(prob.$probnum.val)"
                    232:     if { $problem(prob.$probnum.hint) != "" } {
                    233: 	puts $fileid "/HIN $problem(prob.$probnum.hint)"
                    234:     } else {
                    235: 	puts $fileid "//HIN No hint unless this line is uncommented and modified"
                    236:     }
                    237:     if { $problem(prob.$probnum.expl) != "" } {
                    238: 	puts $fileid "/EXP $problem(prob.$probnum.expl)"
                    239:     } else {
                    240: 	puts $fileid "//EXP No explanation unless this line is uncommented and modified"
                    241:     }
                    242:     puts $fileid "/IMP \"../Tools/Problem\#\""
                    243:     puts $fileid "$problem(prob.$probnum.quest)"
                    244:     puts $fileid "//----------------------------"
                    245: }
                    246: 
                    247: proc MCexportLeafs { fileid probnum } {
                    248:     global problem
                    249: 
                    250:     #(FIXME) need to put out same number of Opts?
                    251:     #(FIXME) extra char at begging of alphabet so as to get rid of the expr?
                    252:     set alphabet abcdefghijklmnopqrstuvwxyz
                    253: 
                    254:     for { set i 1 } { $i <= $problem(prob.$probnum.numleaf) } { incr i } {
                    255: 	for { set j 1 } { $j <= $problem(prob.$probnum.leaf.$i.numoptions) } { incr j } {
                    256: 	    set var ""
                    257: 	    append var s $i [string index $alphabet [ expr $j - 1 ] ]
                    258: 	    puts $fileid "/LET $var=\"$problem(prob.$probnum.leaf.$i.option.$j)\""
                    259: 	}
                    260: 	puts $fileid "/LET mix$i=random(1,$problem(prob.$probnum.leaf.$i.numoptions),1)"
                    261: 	for { set j 1 } { $j <= $problem(prob.$probnum.leaf.$i.numoptions) } { incr j } {
                    262: 	    set var ""
                    263: 	    append var a $i [string index $alphabet [ expr $j - 1 ] ]
                    264: 	    puts $fileid "/LET $var=$problem(prob.$probnum.leaf.$i.option.$j.correct)"
                    265: 	}
                    266: 	puts $fileid "//"
                    267:     }
                    268:     puts $fileid "//Nof5aux follows"
                    269: }
                    270: 
                    271: proc MCexportAns { fileid probnum } {
                    272:     global problem
                    273: 
                    274:     #(FIXME) need to put out same number of Opts?
                    275:     #(FIXME) extra char at begging of alphabet so as to get rid of the expr?
                    276:     set alphabet abcdefghijklmnopqrstuvwxyz
                    277:     set ALPHABET ABCDEFGHIJKLMNOPQRSTUVWXYZ
                    278: 
                    279:     for { set i 1 } { $i <= $problem(prob.$probnum.numleaf) } { incr i } {
                    280: 	set questStr "/LET s$i=choose(mix$i"
                    281: 	set ansStr "/LET a$i=choose(mix$i"
                    282: 	for { set j 1 } { $j <= $problem(prob.$probnum.leaf.$i.numoptions) } { incr j } {
                    283: 	    append questStr ",s$i"
                    284: 	    append questStr [string index $alphabet [ expr $j - 1 ] ]
                    285: 	    append ansStr ",a$i"
                    286: 	    append ansStr [string index $alphabet [ expr $j - 1 ] ]
                    287: 	}
                    288: 	append questStr ")"
                    289: 	append ansStr ")"
                    290: 	puts $fileid "$questStr"
                    291: 	puts $fileid "$ansStr"
                    292:     }    
                    293:     puts $fileid "/LET seed=random(1,300,1)"
                    294:     set line "/MAP(seed;"
                    295:     set end ";"
                    296:     for { set i 1 } { $i <= $problem(prob.$probnum.numleaf) } { incr i } {
                    297: 	if { $i != $problem(prob.$probnum.numleaf) } {
                    298: 	    append line "M$i,"
                    299: 	    append end "s$i,"
                    300: 	} else {
                    301: 	    append line "M$i"
                    302: 	    append end "s$i)"
                    303: 	}
                    304:     }
                    305:     append line $end
                    306:     puts $fileid "$line"
                    307:     puts $fileid "/LET it=tex(\"\\item\[\] \",\"\")"
                    308:     puts $fileid "/DIS(tex(\"\\begin\{choicelist\}\",\"\"))"
                    309:     for { set i 1 } { $i <= $problem(prob.$probnum.numleaf) } { incr i } {
                    310: 	puts $fileid "/DIS(it) [string index $ALPHABET [expr $i - 1] ]) /DIS (M$i)"
                    311:     }
                    312:     puts $fileid "/DIS(tex(\"\\end\{choicelist\}\",\"\"))"
                    313:     set line "/MAP(seed;"
                    314:     set end ";"
                    315:     for { set i 1 } { $i <= $problem(prob.$probnum.numleaf) } { incr i } {
                    316: 	if { $i != $problem(prob.$probnum.numleaf) } {
                    317: 	    append line "b$i,"
                    318: 	    append end "a$i,"
                    319: 	} else {
                    320: 	    append line "b$i"
                    321: 	    append end "a$i)"
                    322: 	}
                    323:     }
                    324:     append line $end
                    325:     puts $fileid "$line"
                    326:     for { set i 1 } { $i <= $problem(prob.$probnum.numleaf) } { incr i } {
                    327: 	puts $fileid "/LET NM$i=b$i*(b$i==1)+1"
                    328:     }
                    329:     for { set i 1 } { $i <= $problem(prob.$probnum.numleaf) } { incr i } {
                    330: 	puts $fileid "/LET lett$i=choose(NM$i,\"\",\"[string index $ALPHABET [expr $i -1 ] ]\")"
                    331:     }
                    332:     set line "/LET Nof5right=lett1"
                    333:     for { set i 2 } { $i <= $problem(prob.$probnum.numleaf) } { incr i } {
                    334: 	append line "+lett$i"
                    335:     }
                    336:     puts $fileid "$line"
                    337:     puts $fileid "//**************************"
                    338:     puts $fileid "/DIS(stdline)"
                    339:     puts $fileid "/ANS(Nof5right,wgt=prob_val,str=mc)"
                    340:     puts $fileid "//**************************"
                    341: }
                    342: 

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