diff options
Diffstat (limited to 'ReckonPrimer.activity/exstore.py')
-rw-r--r-- | ReckonPrimer.activity/exstore.py | 172 |
1 files changed, 59 insertions, 113 deletions
diff --git a/ReckonPrimer.activity/exstore.py b/ReckonPrimer.activity/exstore.py index 48da7f7..562ce65 100644 --- a/ReckonPrimer.activity/exstore.py +++ b/ReckonPrimer.activity/exstore.py @@ -9,6 +9,8 @@ from sugar.graphics import style from settings import Settings from coach import Coach +from collection import Collection +from task import Task from exercises.exaddsimp import ExAddSimp from exercises import * @@ -24,12 +26,65 @@ class ExStore: (self._sett.get_setting('passten'), []), (self._sett.get_setting('times_div'), [])] #WN.LV [] ist die vorlaeufige Liste der errors ########### + _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) + + #xxxxxxxxxxxxxxxxxxxxxxxx self._display = display self._coach = coach self._active_exerc = None - self.__data = [] - self.__title = "Collection" - self.__description = "Description" + #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( @@ -100,115 +155,6 @@ class ExStore: 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)) - - - def fill_store(self, ts, parent, list): - """ Fill treestore with data from disk. """ - #c = CollectionTest() - root = self.get_data_from_pickle() - - if list == None: - list = root.getData() - - for i in range(len(list)): - if isinstance(list[i], CollectionTest): - olditer = ts.append(parent, [self.imagecollection, list[i].getTitle()]) - c_list = list[i].getData() - self.fill_store(ts, olditer, c_list) - else: - text = list[i].getTitle() + ": " + list[i].getDescription() - iter = ts.append(parent, [self.imageexercise, text]) - - def getData(self): - return self.__data - - def setData(self, data): - self.__data = data - - def getTitle(self): - return self.__title - - def setTitle(self, title): - self.__title = title - - def getDescription(self): - return self.__description - - def setDescription(self, description): - self.__description = description - - ''' keep for need, TODO icon reformatting icon to string - def getPic(self): - return self.__pic - - def setPic(self, pic): - self.__pic = pic - ''' - - def get_data_from_pickle(self): - path = os.path.join(os.getcwd(), "data/Collection.data") - f = open(path, "rb") - root = pickle.load(f) - f.close() - return root - - def set_data_in_pickle(self, root): - path = os.path.join(os.getcwd(), "data/Collection.data") - f = open(path, "wb") - pickle.dump(root, f) - f.close() - - - def insert_object(self, obj, pos): - root = self.get_data_from_pickle() - list = root.getData() - - if (pos == None): - list.append(obj) # sonderfall ganz hinten einfügen - else: - max = len(pos) - for i in range(len(pos)): - try: - if isinstance(list[pos[i]], CollectionTest): - list = list[pos[i]].getData() - if (i == (max - 1)): - list.append(obj) - else: - list.insert(pos[i], obj) - except IndexError: - list.append(obj) # wenn in eigener collection verschoben wird, wurde ja element schon gelöscht daher passt index nicht mehr - - self.set_data_in_pickle(root) - - - def get_object(self, pos): - root = self.get_data_from_pickle() - - list = root.getData() - - # find object and return it to insert it in collection - for i in range(len(pos)): - if isinstance(list[pos[i]], CollectionTest): - obj = list[pos[i]] - list = list[pos[i]].getData() - else: - obj = list[pos[i]] - - list = root.getData() - max = len(pos) + #self._coach.notify(('exerc-selected', coll_key)) - # find object and delete it in current collection - for i in range(len(pos)): - if isinstance(list[pos[i]], CollectionTest): - if (i == (max - 1)): - #collection löschen (evt. abfrage ob wirklich gelöscht werden soll inkl. kinder) - list.remove(obj) - else: - list = list[pos[i]].getData() - else: - #task löschen - list.remove(obj) - self.set_data_in_pickle(root) - return obj |