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

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

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