# -*- 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 exaddsimp import ExAddSimp from exaddsub import ExAddSub from expassten import ExPassTen from exmult import ExMult from extimesdiv import ExTimesDiv from extimesadd import ExTimesAdd 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. Errors are retrieved for (future) use by Coach. """ #WN.LV Code ersetzen: key ist dann fuer Listen von Listen !! (_sett, _errors) = self._data[key] if _sett['topic'] == 'addsub_simp': return ExAddSimp(self._display, (_sett, _errors)) elif _sett['topic'] == 'exaddsub': return ExAddSub(self._display, (_sett, _errors)) elif _sett['topic'] == 'passten': return ExPassTen(self._display, (_sett, _errors)) elif _sett['topic'] == 'exmult': return ExMult(self._display, (_sett, _errors)) elif _sett['topic'] == 'times_div': return ExTimesDiv(self._display, (_sett, _errors)) elif _sett['topic'] == 'extimesadd': return ExTimesAdd(self._display, (_sett, _errors)) else: raise Exception() def define_coll_gui(self): """ Define gui-elements for presenting the collection. TODO: define once at startup of RP ?""" #WN.LV diesen Code ersetzen !!!!! 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, 6, 5, 6) def set_coll_gui(self): """ 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, exerc): """ Callback telling the item from the collection selected. """ if(self._active_exerc == None): # at startup self._active_exerc = exerc self._coach.notify(('exerc-selected', exerc)) elif(self._active_exerc == exerc): # hit the same button once more pass elif(self._active_exerc != exerc): # switched to another exercise self._active_exerc = exerc self._display.switch_exercise() self._coach.notify(('exerc-selected', exerc))