diff options
Diffstat (limited to 'ReckonPrimer.activity/collection.py')
-rw-r--r-- | ReckonPrimer.activity/collection.py | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/ReckonPrimer.activity/collection.py b/ReckonPrimer.activity/collection.py index 53ababe..4a45bd1 100644 --- a/ReckonPrimer.activity/collection.py +++ b/ReckonPrimer.activity/collection.py @@ -10,12 +10,9 @@ 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 +from exercises import * +from exercises.exercise import Exercise + class Collection: @@ -31,24 +28,20 @@ class Collection: self._active_exerc = None def select(self, key): - """ Select an exercise by 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] - 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() + 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) + module = getattr(package, klass) + return getattr(module, klass)(self._display, (_sett, _errors)) + def define_coll_gui(self): """ Define gui-elements for presenting the collection. |