# -*- coding: utf-8 -*- import gtk import pygtk import pango import random import copy from sugar.graphics import style #from settings import Settings #WN.100112 remove with "treeView-Kollektion" #from coach import Coach from collection import Collection from task import Task from exercises.exaddsimp import ExAddSimp from exercises import * from exercises.exercise import Exercise class ExStore: """ Holds all exercises avaiable in RP in a tree and stores them on disk. The tree ist presented looking like a filebrowser, see Display.treeview. The Learner starts an Exercise by selecting an item of the tree. The Author creates new Exercises copying certain Exercises by drag-and-drop andself.imagecollection = gtk.gdk.pixbuf_new_from_file( "./img/collection.png") self.imageexercise = gtk.gdk.pixbuf_new_from_file( "./img/exercise.png") then editing the title, the description and the settings. """ _root = None #hold the tree with root of Collection and leafs of Task def __init__(self, display, coach): self._dis = display self._coach = coach self._active_exerc = None #Provisorium für impl. "treeView-Kollektion" vvvvvvvvvvvvvvvvvvvv ####### _c1 ################################################################## ####### _c1c1c1t ############################################################# _sett = {'topic' : 'times_div', 'title' : '99-er Reihe', 'descript' : 'settings: series (2,4,8 is possible!) of *, "in" and : with remainder, series 11..19 (left bar),series 10..90 (right long bar), separate shuffling or operands.', 'icon' : None, 'calclines' : 1, 'MAX' : 50, 'MIN' : 10, '*' : True, '*commute' : False, ':' : False, 'in' : False, 'remainder' : False, 'vadd' : 0, 'vmult' : 1, 'factors' : [99], 'shuffle_all' : True, 'shuffle_inner': True, 'cut-max' : True } _sett['factors'] = [2]; _sett['title'] = '2-er Reihe' _c1c1c1t2 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [3]; _sett['title'] = '3-er Reihe' _c1c1c1t3 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [4]; _sett['title'] = '4-er Reihe' _c1c1c1t4 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [5]; _sett['title'] = '5-er Reihe' _c1c1c1t5 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [6]; _sett['title'] = '6-er Reihe' _c1c1c1t6 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [7]; _sett['title'] = '7-er Reihe' _c1c1c1t7 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [8]; _sett['title'] = '8-er Reihe' _c1c1c1t8 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [9]; _sett['title'] = '9-er Reihe' _c1c1c1t9 = Task(copy.deepcopy(_sett), []) ####### _c1c1c2t ############################################################# _sett['factors'] = [2,4]; _sett['title'] = '2,4-er Reihe' _c1c1c2t1 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [2,4,8]; _sett['title'] = '2,4,8-er Reihe' _c1c1c2t2 = Task(copy.deepcopy(_sett), []) #_sett['factors'] = [5,10]; _sett['title'] = '-er Reihe' #_c1c1c2t2 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [3,6]; _sett['title'] = '3,6-er Reihe' _c1c1c2t3 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [3,6,9]; _sett['title'] = '3,6,9-er Reihe' _c1c1c2t4 = Task(copy.deepcopy(_sett), []) ####### _c1c1c3t ############################################################# _sett['factors'] = [2,3,4,5,6,7,8,9]; _sett['title'] = 'nur *' _c1c1c3t1 = Task(copy.deepcopy(_sett), []) _sett['*'] = False; _sett['in'] = True; _sett['title'] = "nur 'in'" _c1c1c3t2 = Task(copy.deepcopy(_sett), []) _sett['*'] = True; _sett['in'] = False; _sett['vadd'] = 10; _sett['vmult'] = 10; _sett['title'] = "grosse Zahlen" _c1c1c3t3 = Task(copy.deepcopy(_sett), []) ####### _c1c2c1c1 ############################################################ _sett['*'] = False; _sett['in'] = False; _sett[':'] = True; _sett['vadd'] = 0; _sett['vmult'] = 1; _sett['factors'] = [2]; _sett['title'] = "2-er Reihe" _c1c2c1c1t1 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [3]; _sett['title'] = "3-er Reihe" _c1c2c1c1t2 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [4]; _sett['title'] = "4-er Reihe" _c1c2c1c1t3 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [5]; _sett['title'] = "5-er Reihe" _c1c2c1c1t4 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [6]; _sett['title'] = "6-er Reihe" _c1c2c1c1t5 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [7]; _sett['title'] = "7-er Reihe" _c1c2c1c1t6 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [8]; _sett['title'] = "8-er Reihe" _c1c2c1c1t7 = Task(copy.deepcopy(_sett), []) _sett['factors'] = [9]; _sett['title'] = "9-er Reihe" _c1c2c1c1t8 = Task(copy.deepcopy(_sett), []) #_sett['factors'] = [10]; _sett['title'] = "3-er Reihe" #_c1c2c1c1t9 = Task(copy.deepcopy(_sett), []) ####### _c2 ################################################################## ####### _c3 ################################################################## _c3t1 = Task({'topic' : 'addsub_simp', 'title' : 'Template: + - within 10', 'descript' : 'settings: range of result, input at 3 positions, swap around =', 'icon' : None, # for quick reference of the exercise 'calclines': 1, # no. of lines for calc to be input. 'MAX' : 100, # maximum of calcs generated. # Generate fills up by varying input. 'MIN' : 20, # minimum of calcs generated UNUSED 'min' : 0, # minimum in size of a number in a calc 'max' : 1, # maximum in size of a number in a calc # 0 <= min <= max <= 10 '+' : True, # make all additions min..max '-' : False, # make all subtactions min..max '_+_=_' : True, # = is _right_ from operator, e.g. 1+2=3 'input=' : [5],# list of positions in calc: 1 | 3 | 5 # where input is possible; # actual positions chosen by Generate. '_=_+_' : False, # = is _left_ from operator, e.g. 3=1+2 '=input' : [1,3,5],# analogous to '_+_=_' 'shuffle' : False, # shuffle _all_ the calcs 'cut-max' : True # cut set of all calcs down to MAX }, []) _c3t2 = Task({'topic' : 'passten', 'title' : 'Template: + - with carry', 'descript' : 'settings: range of 1st operand, input left and right from =, input intermediate result, separate shuffling of operands.', 'icon' : None, # for quick reference of the exercise 'calclines' : 1, # or 2 iff 'newline' : True. 'MAX' : 150, # maximum of calcs generated; # TODO: Generate fills up by varying input. 'MIN' : 10, # minimum of calcs generated 090416WN:UNUSED '+' :True, # + crossing the ten barrier!! '-' :False, # - goes below the ten barrier!!! #(i.e. iteration on left arg. is "outer" loop) 'min' : 2, # +: minimum in size of number in left argument 'max' : 2, # +: maximum in size of number in left argument 'input' :[3], # list of positions in calc 3 | 5 # where input is possible. 'newline' : True, # display 2nd line for intermediate results 'shuffle_all' : False,# shuffle all calcs 'shuffle_inner': False,# shuffle only 1st (inner) iteration 'cut-max' : True # cut set of all calcs down to MAX }, []) _c3t3 = Task({'topic' : 'times_div', #for programmers only 'title' : 'Template: * : "in" series', 'descript' : 'settings: series (2,4,8 is possible!) of *, "in" and : with remainder, series 11..19 (left bar),series 10..90 (right long bar), separate shuffling or operands.', 'icon' : None, # for quick reference of the exercise 'calclines' : 1, # no. of lines for calc to be input.2 'MAX' : 50, # maximum of calcs generated; # TODO: Generate fills up by varying input. 'MIN' : 10, # minimum of calcs generated 090416WN:UNUSED '*' : False, # eg. 7 . 2 =_ '*commute' : False, # commute the operands 2 . 7 = _ ':' : True, # 14 : 2 = _ 'in' : False, # 2 in 14 = _ 'remainder' : False, # : | in ... with remainder 'vadd' : 0, # 0 or 10, for 1.11 ... 1.19 'vmult' : 1, # 1 or 10, for 1.10 ... 1.90 'factors' : [2,4], # Liste mit ausgewählten zahlen zur berechnung 'shuffle_all' : False, # shuffle all calcs 'shuffle_inner': False, # shuffle only 1st (inner) iteration 'cut-max' : True # cut set of all calcs down to MAX }, []) _c3t4 = Task({'topic' : 'exaddsub', 'title' : 'Template: +- in a column', 'descript' : 'TODO', 'icon' : None, # for quick reference of the exercise 'calclines': 4, # no. of lines for calc to be input. 'MAX' : 10, # maximum of calcs generated. 'MIN' : 10, # minimum of calcs generated UNUSED 'length' : 3, # max number of digits in summands # _max_length =< 6 because of Display 'args' : 2, # FIXED due to constraints in # _generate_calcs and format 'carry' : False,# the calculation might involve carries 'ops' : ["+", "-"],#["+", "-"] are the only options 'shuffle' : True, 'cut-max' : True # cut set of all calcs down to MAX }, []) _c3t5 = Task({'topic' : 'exmult', 'title' : 'Template: * with large numbers', 'descript': 'TODO', 'icon' : None, # for quick reference of the exercise 'calclines': 4, # no. of lines for calc to be input. 'MAX' : 10, # maximum of calcs generated. 'MIN' : 10, # minimum of calcs generated UNUSED 'fact1' : 5, # number of digits of left factor 'fact2' : 1, # FIXED due to constraints in # _generate_calcs and format 'cut-max': True # cut set of all calcs down to MAX }, []) self._root = \ Collection("root = invisible node","required by tree structure", None, [Collection("Praxis Volksschule PHSt", #_c1 "Rechenuebungen fuer die 1. und 2.Klasse, festgelegt am 16.Dez.09 mit Nina Jaklitsch und Arndt Stoeckl .", None, [Collection("Uebungen . und 'in' ", #_c1c1 " ", None, [Collection("Einzelne Reihen . und 'in'", #_c1c1c1 " ", None, [_c1c1c1t2, _c1c1c1t3, _c1c1c1t4, _c1c1c1t5, _c1c1c1t6, _c1c1c1t7, _c1c1c1t8, _c1c1c1t9 ]), Collection("Mehrere Reihen .", "Wir ueben zusammengehoerende Reihen.", None, [_c1c1c2t1, _c1c1c2t2, _c1c1c2t3, _c1c1c2t4 ]), Collection("Alle Reihen gemischt", " ", None, [_c1c1c3t1, _c1c1c3t2, _c1c1c3t3 ]) ]), Collection("Uebungen :", #_c1c2 " ", None, [Collection(": ohne Rest", #_c1c2c1 " ", None, [Collection("Reihen einzeln", #_c1c2c1c1 " ", None, [_c1c2c1c1t1, _c1c2c1c1t2, _c1c2c1c1t3, _c1c2c1c1t4, _c1c2c1c1t5, _c1c2c1c1t6, _c1c2c1c1t7, _c1c2c1c1t8 ]) ]) ]), Collection("Uebungen + und - ", #_c1c3 " ", None, [ ]) ]), Collection("Mini course", #_c2 "Most efficient introduction to the four basic arithmetic \ operations as taught in the last century in Upper Austria.", None, [ ]), Collection("Templates", #_c3 "These are the (classes of) exercises all others are derived \ from. Thus, please, do not deletem them. \ For testing exercises disabling of @ is recommended.", None, [_c3t1, _c3t2, _c3t3, _c3t4, _c3t5]) ]) # comment to save changes (order of the items) till the next start self._root.set_data_in_pickle(self._root) #Provisorium für impl. "treeView-Kollektion" ^^^^^^^^^^^^^^^^^^^^ def reload(self): self._root = self._root.get_data_from_pickle() def offer_coll_to_learner(self): """Show Collection to Learner and hand over control to Display (gtk)""" data = self._root.get_data() self._dis.offer_coll_to_learner(data) def get_exercise(self, obj): """ Loads the proper exercise class for the given object and returns it as a new exercise object """ exercise_label = obj.get_object_name() if not Exercise.EXERCISES.has_key(exercise_label): raise Exception('Collection#select: Wrong pos. To register an exercise see exercises/__init__.py') class_name = Exercise.EXERCISES[exercise_label] package = __import__("exercises." + class_name.lower()) module = getattr(package, class_name.lower()) return getattr(module, class_name)(self._dis, (obj.get_settings(), obj.get_eval()))