Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ReckonPrimer.activity/exstore.py
diff options
context:
space:
mode:
Diffstat (limited to 'ReckonPrimer.activity/exstore.py')
-rw-r--r--ReckonPrimer.activity/exstore.py215
1 files changed, 215 insertions, 0 deletions
diff --git a/ReckonPrimer.activity/exstore.py b/ReckonPrimer.activity/exstore.py
new file mode 100644
index 0000000..308c2e6
--- /dev/null
+++ b/ReckonPrimer.activity/exstore.py
@@ -0,0 +1,215 @@
+# -*- 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
+
+
+class ExStore:
+
+ 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._data =
+ 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))
+
+
+ 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)
+
+ # 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