# -*- 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 and then editing the title, the description and the settings. """ _data = None #hold the tree with root of Collection and leafs of Task def __init__(self, display, coach): self._sett = Settings() #Provisorium für die "3-Button-Version" vvvvvvvvvvvvvvvvvvvvvvvvv self._data = [(self._sett.get_setting('addsub_simp'), []), (self._sett.get_setting('passten'), []), (self._sett.get_setting('times_div'), [])] #Provisorium für die "3-Button-Version" ^^^^^^^^^^^^^^^^^^^^^^^^^ #Provisorium für impl. "treeView-Kollektion" vvvvvvvvvvvvvvvvvvvv _ex000 = Task({'topic' : 'times_div', #for programmers only 'title' : 'template extimesdiv', 'descript': 'multiplication, division and "in" \ from 2 to 19 and 20 to 190. ', 'icon' : None, # for quick reference of the exercise 'calclines' : 1, # no. of lines for calc to be input. 'MAX' : 100, # maximum of calcs generated; # TODO: Generate fills up by varying input. 'MIN' : 10, # minimum of calcs generated 090416WN:UNUSED '*' : True, # eg. 7 . 2 =_ '*commute' : True, # commute the operands 2 . 7 = _ ':' : False, # 14 : 2 = _ 'in' : True, # 2 in 14 = _ 'remainder' : False, # : | in ... with remainder 'min' : 2, # +: minimum number in right *operand # -: minimum result 'max' : 2, # +: maximum number in right *operand # -: maximum result 'shuffle_all' : False, # shuffle all calcs 'shuffle_inner': True, # shuffle only 1st (inner) iteration 'cut-max' : True # cut set of all calcs down to MAX }, []) _ex001 = Task({'topic' : 'times_div', #for programmers only 'title' : 'template extimesdiv', 'descript': 'multiplication, division and "in" \ from 2 to 19 and 20 to 190. ', 'icon' : None, # for quick reference of the exercise 'calclines' : 1, # no. of lines for calc to be input. 'MAX' : 100, # maximum of calcs generated; # TODO: Generate fills up by varying input. 'MIN' : 10, # minimum of calcs generated 090416WN:UNUSED '*' : True, # eg. 7 . 2 =_ '*commute' : True, # commute the operands 2 . 7 = _ ':' : False, # 14 : 2 = _ 'in' : True, # 2 in 14 = _ 'remainder' : False, # : | in ... with remainder 'min' : 3, # +: minimum number in right *operand # -: minimum result 'max' : 3, # +: maximum number in right *operand # -: maximum result 'shuffle_all' : False, # shuffle all calcs 'shuffle_inner': True, # shuffle only 1st (inner) iteration 'cut-max' : True # cut set of all calcs down to MAX }, []) _coll00 = Collection("einzeln * in", "hier sind alle 1x1-Reihen mit 'in'", None, [_ex000, _ex001]) _coll0 = Collection("'*' und 'in' Reihen", "hier sind alle 1x1-Reihen mit 'in'", None, [_coll00]) _coll0.set_data_in_pickle(_coll0) #WN.100112 remove asap #self._data = _coll0 #Provisorium für impl. "treeView-Kollektion" ^^^^^^^^^^^^^^^^^^^^ self._display = display self._coach = coach self._active_exerc = None #self.__data = [] #self.__title = "Collection" #self.__description = "Description" self.imagecollection = gtk.gdk.pixbuf_new_from_file( "./img/collection.png") self.imageexercise = gtk.gdk.pixbuf_new_from_file( "./img/exercise.png") def select(self, key): """ Select an exercise by key. return instance of an exercise. Errors are retrieved for (future) use by Coach. """ #WN.LV Code ersetzen: key ist dann fuer Listen von Listen !! (_sett, _errors) = self._data[key] exercise_label = _sett['topic'] if not Exercise.EXERCISES.has_key(exercise_label): raise Exception('Collection#select: Wrong key. To register an exercise see exercises/__init__.py') klass = Exercise.EXERCISES[exercise_label] package = __import__("exercises." + klass.lower()) module = getattr(package, klass.lower()) return getattr(module, klass)(self._display, (_sett, _errors)) #@# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv def define_coll_gui(self): """ Define gui-elements for presenting the collection. TODO: define once at startup of RP ?""" #WN.LV diesen Code ersetzen: exstore_table.attach(self.colldata,... self.topic_box = gtk.HBox(True, 0) #self._display.exstore_table.attach(self.topic_box, 0, 6, 0, 1) self._display.exstore_table.attach(self.topic_box, 0, 9, 5, 6) def set_coll_gui(self, coll_data): """ Set gui-elements according to Collection.data. """ #WN.LV diesen Code ersetzen !!!!! _i = 0 for _t in ['addsub_simp','passten','times_div']: self.button = gtk.Button() self.image = gtk.Image() if(_t == 'addsub_simp'): self.image.set_from_file("img/addsub_simp.jpg") elif(_t == 'passten'): self.image.set_from_file("img/passten.jpg") elif(_t == 'times_div'): self.image.set_from_file("img/times_div.jpg") self.button.set_image(self.image) self.button.connect("clicked", self.select_exerc_callback, _i) self.topic_box.pack_start(self.button) self.button.show() _i = _i + 1 self.topic_box.show() #@# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ def select_exerc_callback(self, widget, coll_key): """ Callback telling the item from the collection selected. """ #WN.LV diesen Code ersetzen> statt 1..n fuer Listen kommt coll_key print('in Collection.select_exerc_callback') if(self._active_exerc == None): # at startup self._active_exerc = coll_key self._display.set_select_exerc_semaphore(coll_key) #self._coach.notify(('exerc-selected', coll_key)) elif(self._active_exerc == coll_key): # hit the same button once more pass elif(self._active_exerc != coll_key): # switched to another exercise self._active_exerc = coll_key self._display.switch_exercise() # TODO rename self._display.set_select_exerc_semaphore(coll_key) #self._coach.notify(('exerc-selected', coll_key))