diff options
Diffstat (limited to 'ReckonPrimer.activity/collection.py')
-rw-r--r-- | ReckonPrimer.activity/collection.py | 204 |
1 files changed, 116 insertions, 88 deletions
diff --git a/ReckonPrimer.activity/collection.py b/ReckonPrimer.activity/collection.py index adc6f2e..a90d82d 100644 --- a/ReckonPrimer.activity/collection.py +++ b/ReckonPrimer.activity/collection.py @@ -1,95 +1,123 @@ # -*- coding: utf-8 -*- -import gtk -import pygtk -import pango -import random -import copy -from sugar.graphics import style - -from settings import Settings -from coach import Coach - -from exercises.exaddsimp import ExAddSimp -from exercises import * -from exercises.exercise import Exercise - +''' +date: 07.01.2010 +description: test class "collection" to test our new idea for saving all tasks +''' -class Collection: - - def __init__(self, display, coach): - self._sett = Settings() - #WN.LV diese Daten via pickle.load(...) holen ############ - self._data = [(self._sett.get_setting('addsub_simp'), []), - (self._sett.get_setting('passten'), []), - (self._sett.get_setting('times_div'), [])] - #WN.LV [] ist die vorlaeufige Liste der errors ########### - self._display = display - self._coach = coach - self._active_exerc = None - - 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)) +import gtk +import pickle +import os +class CollectionTest: +# __data = None +# __title = None +# __description = None + #__pic = None - def define_coll_gui(self): - """ Define gui-elements for presenting the collection. - TODO: define once at startup of RP ?""" - #WN.LV diesen Code ersetzen: collection_table.attach(self.colldata,... - self.topic_box = gtk.HBox(True, 0) - #self._display.collection_table.attach(self.topic_box, 0, 6, 0, 1) - self._display.collection_table.attach(self.topic_box, 0, 9, 5, 6) + def __init__(self): + self.__data = [] + self.__title = "Collection" + self.__description = "Description" + #self.__pic = gtk.gdk.pixbuf_new_from_file("collection.png") - 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") + ''' + def __init__(self, title, description, pic): + self.__data = [] + self.__title = title + self.__description = description + self.__pic = pic + ''' - 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)) - +# 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) +# +# # 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 |