Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mayer <christian.mayer@student.tugraz.at>2010-01-07 05:06:29 (GMT)
committer Christian Mayer <christian.mayer@student.tugraz.at>2010-01-07 05:06:29 (GMT)
commit4545e74816fdbf60ff7f98ae4bb101eb106d935a (patch)
treebd7abaab179283721083362711a885351cbb2d40
parentdffa0c6d361ceb789265cb12a949c0cdd4f2d5de (diff)
* moved exercises into subfolderdevel
* dynamically create instance of exercise
-rw-r--r--ReckonPrimer.activity/collection.py35
-rw-r--r--ReckonPrimer.activity/exercises/__init__.py16
-rwxr-xr-xReckonPrimer.activity/exercises/exaddsimp.py (renamed from ReckonPrimer.activity/exaddsimp.py)0
-rw-r--r--ReckonPrimer.activity/exercises/exaddsub.py (renamed from ReckonPrimer.activity/exaddsub.py)0
-rwxr-xr-xReckonPrimer.activity/exercises/exercise.py (renamed from ReckonPrimer.activity/exercise.py)3
-rw-r--r--ReckonPrimer.activity/exercises/exmult.py (renamed from ReckonPrimer.activity/exmult.py)0
-rwxr-xr-xReckonPrimer.activity/exercises/expassten.py (renamed from ReckonPrimer.activity/expassten.py)218
-rw-r--r--ReckonPrimer.activity/exercises/extimesadd.py (renamed from ReckonPrimer.activity/extimesadd.py)0
-rwxr-xr-xReckonPrimer.activity/exercises/extimesdiv.py (renamed from ReckonPrimer.activity/extimesdiv.py)0
9 files changed, 142 insertions, 130 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.
diff --git a/ReckonPrimer.activity/exercises/__init__.py b/ReckonPrimer.activity/exercises/__init__.py
new file mode 100644
index 0000000..461e7d2
--- /dev/null
+++ b/ReckonPrimer.activity/exercises/__init__.py
@@ -0,0 +1,16 @@
+""" To register a new Exercise, append module name to EXERCISES """
+
+from exercise import Exercise
+
+
+""" TODO naming convention for 'topic' (aka exercise name) """
+
+Exercise.EXERCISES = { 'addsub_simp': "ExAddSimp", \
+ 'exaddsub': "ExAddSub", \
+ 'exmult': "ExMult", \
+ 'passten': "ExPassTen", \
+ 'extimesadd': "ExTimesAdd", \
+ 'times_div': "ExTimesDiv" }
+
+
+__all__ = Exercise.EXERCISES.values()
diff --git a/ReckonPrimer.activity/exaddsimp.py b/ReckonPrimer.activity/exercises/exaddsimp.py
index a774436..a774436 100755
--- a/ReckonPrimer.activity/exaddsimp.py
+++ b/ReckonPrimer.activity/exercises/exaddsimp.py
diff --git a/ReckonPrimer.activity/exaddsub.py b/ReckonPrimer.activity/exercises/exaddsub.py
index ed3d8d9..ed3d8d9 100644
--- a/ReckonPrimer.activity/exaddsub.py
+++ b/ReckonPrimer.activity/exercises/exaddsub.py
diff --git a/ReckonPrimer.activity/exercise.py b/ReckonPrimer.activity/exercises/exercise.py
index c824214..c3bfcc9 100755
--- a/ReckonPrimer.activity/exercise.py
+++ b/ReckonPrimer.activity/exercises/exercise.py
@@ -3,6 +3,9 @@ from functions import contain, collect_digits, make_line, make_input
from functions import make_line_remainder, make_input_remainder
class Exercise:
+
+ EXERCISES = {}
+
"""This is the base class for the individual exercises.
An exercise is characterized by a topic. A topic determines the
fields of the settings self._sett and public methods of Exercise.
diff --git a/ReckonPrimer.activity/exmult.py b/ReckonPrimer.activity/exercises/exmult.py
index fb6452f..fb6452f 100644
--- a/ReckonPrimer.activity/exmult.py
+++ b/ReckonPrimer.activity/exercises/exmult.py
diff --git a/ReckonPrimer.activity/expassten.py b/ReckonPrimer.activity/exercises/expassten.py
index b177cfa..6bac2f3 100755
--- a/ReckonPrimer.activity/expassten.py
+++ b/ReckonPrimer.activity/exercises/expassten.py
@@ -225,109 +225,109 @@ class ExPassTen(Exercise):
def define_buttons(self):
""" See comment in Exercies.define_buttons. """
- self.toggle_plus = gtk.ToggleButton("+")
- self.toggle_label = self.toggle_plus.get_child()
- self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
- self.toggle_plus.connect("toggled", self.toggle_plus_callback)
- self._display.settings_table.attach(self.toggle_plus, 1, 2, 10, 11 )
- self.toggle_plus.show()
-
- self.toggle_minus = gtk.ToggleButton("-")
- self.toggle_label = self.toggle_minus.get_child()
- self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
- self.toggle_minus.connect("toggled", self.toggle_minus_callback)
- self._display.settings_table.attach(self.toggle_minus, 1, 2, 9, 10 )
+ self.toggle_plus = gtk.ToggleButton("+")
+ self.toggle_label = self.toggle_plus.get_child()
+ self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
+ self.toggle_plus.connect("toggled", self.toggle_plus_callback)
+ self._display.settings_table.attach(self.toggle_plus, 1, 2, 10, 11 )
+ self.toggle_plus.show()
+
+ self.toggle_minus = gtk.ToggleButton("-")
+ self.toggle_label = self.toggle_minus.get_child()
+ self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
+ self.toggle_minus.connect("toggled", self.toggle_minus_callback)
+ self._display.settings_table.attach(self.toggle_minus, 1, 2, 9, 10 )
self.toggle_minus.show()
- self.label0 = gtk.Label("3")
- self.label0.modify_font(pango.FontDescription("sans 12"))
- self._display.settings_table.attach(self.label0, 2, 3, 10, 11 )
+ self.label0 = gtk.Label("3")
+ self.label0.modify_font(pango.FontDescription("sans 12"))
+ self._display.settings_table.attach(self.label0, 2, 3, 10, 11 )
self.label0.show()
- self.label1 = gtk.Label("=")
- self.label1.modify_font(pango.FontDescription("sans 12"))
- self._display.settings_table.attach(self.label1, 3, 4, 10, 11 )
+ self.label1 = gtk.Label("=")
+ self.label1.modify_font(pango.FontDescription("sans 12"))
+ self._display.settings_table.attach(self.label1, 3, 4, 10, 11 )
self.label1.show()
- self.label2 = gtk.Label("12")
- self.label2.modify_font(pango.FontDescription("sans 12"))
- self._display.settings_table.attach(self.label2, 4, 5, 10, 11 )
+ self.label2 = gtk.Label("12")
+ self.label2.modify_font(pango.FontDescription("sans 12"))
+ self._display.settings_table.attach(self.label2, 4, 5, 10, 11 )
self.label2.show()
- self.label3 = gtk.Label("1 + 2")
- self.label3.modify_font(pango.FontDescription("sans 12"))
- self._display.settings_table.attach(self.label3, 2, 3, 11, 12 )
+ self.label3 = gtk.Label("1 + 2")
+ self.label3.modify_font(pango.FontDescription("sans 12"))
+ self._display.settings_table.attach(self.label3, 2, 3, 11, 12 )
self.label3.show()
- self.label6 = gtk.Label(self._display._sett['MAX'])
- self.label6.modify_font(pango.FontDescription("sans 12"))
- self._display.settings_table.attach(self.label6, 5, 6, 1, 2 )
+ self.label6 = gtk.Label(self._display._sett['MAX'])
+ self.label6.modify_font(pango.FontDescription("sans 12"))
+ self._display.settings_table.attach(self.label6, 5, 6, 1, 2 )
self.label6.show()
- #self.label7 = gtk.Label(self._display._sess._gen.count((self._display._key, self._display._sett)))
- #self.label7.modify_font(pango.FontDescription("sans 12"))
- #self._display.settings_table.attach(self.label7, 5, 6, 2, 3 )
+ #self.label7 = gtk.Label(self._display._sess._gen.count((self._display._key, self._display._sett)))
+ #self.label7.modify_font(pango.FontDescription("sans 12"))
+ #self._display.settings_table.attach(self.label7, 5, 6, 2, 3 )
#self.label7.show()
- self.toggle_newline = gtk.ToggleButton("<")
- self.toggle_label = self.toggle_newline.get_child()
- self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
- self.toggle_newline.connect("toggled", self.toggle_newline_callback)
- self._display.settings_table.attach(self.toggle_newline, 5, 6, 11, 12)
+ self.toggle_newline = gtk.ToggleButton("<")
+ self.toggle_label = self.toggle_newline.get_child()
+ self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
+ self.toggle_newline.connect("toggled", self.toggle_newline_callback)
+ self._display.settings_table.attach(self.toggle_newline, 5, 6, 11, 12)
self.toggle_newline.show()
- self.toggle_shuffle_all = gtk.ToggleButton("@")
- self.toggle_shuffle_all_label = self.toggle_shuffle_all.get_child()
- self.toggle_shuffle_all_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
- self.toggle_shuffle_all.connect("toggled", self.toggle_shuffle_all_callback)
- self._display.settings_table.attach(self.toggle_shuffle_all, 0, 1, 13, 14 )
+ self.toggle_shuffle_all = gtk.ToggleButton("@")
+ self.toggle_shuffle_all_label = self.toggle_shuffle_all.get_child()
+ self.toggle_shuffle_all_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
+ self.toggle_shuffle_all.connect("toggled", self.toggle_shuffle_all_callback)
+ self._display.settings_table.attach(self.toggle_shuffle_all, 0, 1, 13, 14 )
self.toggle_shuffle_all.show()
- self.toggle_shuffle_inner = gtk.ToggleButton("@")
- self.toggle_shuffle_inner_label = self.toggle_shuffle_inner.get_child()
- self.toggle_shuffle_inner_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
- self.toggle_shuffle_inner.connect("toggled", self.toggle_shuffle_inner_callback)
- self._display.settings_table.attach(self.toggle_shuffle_inner, 2, 3, 13, 14 )
- self.toggle_shuffle_inner.show()
-
- self.toggle_pos3 = gtk.ToggleButton("--")
- self.toggle_label = self.toggle_pos3.get_child()
- self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
- self.toggle_pos3.connect("toggled", self.toggle_pos3_callback)
- self._display.settings_table.attach(self.toggle_pos3, 2, 3, 12, 13 )
- self.toggle_pos3.show()
-
- self.toggle_pos5 = gtk.ToggleButton("--")
- self.toggle_label = self.toggle_pos5.get_child()
- self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
- self.toggle_pos5.connect("toggled", self.toggle_pos5_callback)
- self._display.settings_table.attach(self.toggle_pos5, 4, 5, 12, 13 )
+ self.toggle_shuffle_inner = gtk.ToggleButton("@")
+ self.toggle_shuffle_inner_label = self.toggle_shuffle_inner.get_child()
+ self.toggle_shuffle_inner_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
+ self.toggle_shuffle_inner.connect("toggled", self.toggle_shuffle_inner_callback)
+ self._display.settings_table.attach(self.toggle_shuffle_inner, 2, 3, 13, 14 )
+ self.toggle_shuffle_inner.show()
+
+ self.toggle_pos3 = gtk.ToggleButton("--")
+ self.toggle_label = self.toggle_pos3.get_child()
+ self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
+ self.toggle_pos3.connect("toggled", self.toggle_pos3_callback)
+ self._display.settings_table.attach(self.toggle_pos3, 2, 3, 12, 13 )
+ self.toggle_pos3.show()
+
+ self.toggle_pos5 = gtk.ToggleButton("--")
+ self.toggle_label = self.toggle_pos5.get_child()
+ self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
+ self.toggle_pos5.connect("toggled", self.toggle_pos5_callback)
+ self._display.settings_table.attach(self.toggle_pos5, 4, 5, 12, 13 )
self.toggle_pos5.show()
- self.number_butts = []
-
- for i in range(1,9+1):
- self.toggle = gtk.ToggleButton(str(i))
- self.toggle_label = self.toggle.get_child()
- self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
- self.toggle.connect("toggled", self.toggle_number_callback, i)
- self._display.settings_table.attach(self.toggle, 0, 1, 1+i, 2+i)
- self.toggle.show()
+ self.number_butts = []
+
+ for i in range(1,9+1):
+ self.toggle = gtk.ToggleButton(str(i))
+ self.toggle_label = self.toggle.get_child()
+ self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
+ self.toggle.connect("toggled", self.toggle_number_callback, i)
+ self._display.settings_table.attach(self.toggle, 0, 1, 1+i, 2+i)
+ self.toggle.show()
self.number_butts.append(self.toggle)
def set_buttons(self, sett):
""" See comment in Exercies.set_buttons. """
- for i in range(sett['min'],sett['max']+1):
+ for i in range(sett['min'],sett['max']+1):
self.number_butts[i-1].set_active(True)
-
- if (sett['+'] == True):
- self.toggle_plus.set_active(True)
- else:
- self.toggle_plus.set_active(False)
-
- if (sett['-'] == True):
- self.toggle_minus.set_active(True)
- else:
+
+ if (sett['+'] == True):
+ self.toggle_plus.set_active(True)
+ else:
+ self.toggle_plus.set_active(False)
+
+ if (sett['-'] == True):
+ self.toggle_minus.set_active(True)
+ else:
self.toggle_minus.set_active(False)
if (sett['newline'] == True):
@@ -345,34 +345,34 @@ class ExPassTen(Exercise):
else:
self.toggle_shuffle_inner.set_active(False)
- for i in sett['input']:
- if( i == 1 ):
- self.toggle_pos1.set_active(True)
-
- if ( i == 3 ):
- self.toggle_pos3.set_active(True)
-
- if ( i == 5 ):
+ for i in sett['input']:
+ if( i == 1 ):
+ self.toggle_pos1.set_active(True)
+
+ if ( i == 3 ):
+ self.toggle_pos3.set_active(True)
+
+ if ( i == 5 ):
self.toggle_pos5.set_active(True)
#**** callbacks ********************************************************
def toggle_newline_callback(self, widget):
- if widget.get_active():
+ if widget.get_active():
self._display._sett['newline'] = True
else:
self._display._sett['newline'] = False
def toggle_shuffle_all_callback(self, widget):
- if widget.get_active():
+ if widget.get_active():
self._display._sett['shuffle_all'] = True
self.toggle_shuffle_inner.set_active(True)
else:
self._display._sett['shuffle_all'] = False
def toggle_shuffle_inner_callback(self, widget):
- if widget.get_active():
+ if widget.get_active():
self._display._sett['shuffle_inner'] = True
else:
if(self.toggle_shuffle_all.get_active()):
@@ -381,7 +381,7 @@ class ExPassTen(Exercise):
self._display._sett['shuffle_inner'] = False
def toggle_pos3_callback(self, widget):
- if widget.get_active():
+ if widget.get_active():
self._display._sett['input'] = list(set(self._display._sett['input']) | set([3]))
else:
if(self.toggle_pos5.get_active()):
@@ -390,31 +390,31 @@ class ExPassTen(Exercise):
widget.set_active(True)
def toggle_pos5_callback(self, widget):
- if widget.get_active():
- self._display._sett['input'] = list(set(self._display._sett['input']) | set([5]))
+ if widget.get_active():
+ self._display._sett['input'] = list(set(self._display._sett['input']) | set([5]))
else:
if(self.toggle_pos3.get_active()):
self._display._sett['input'] = list(set(self._display._sett['input']) - set([5]))
else:
widget.set_active(True)
- def toggle_plus_callback(self, widget):
- if widget.get_active():
- self._display._sett['+'] = True
-
- else:
- if( self.toggle_minus.get_active() ):
- self._display._sett['+'] = False
- else:
- widget.set_active(True)
-
- def toggle_minus_callback(self, widget):
- if widget.get_active():
- self._display._sett['-'] = True
- else:
- if( self.toggle_plus.get_active() ):
- self._display._sett['-'] = False
- else:
+ def toggle_plus_callback(self, widget):
+ if widget.get_active():
+ self._display._sett['+'] = True
+
+ else:
+ if( self.toggle_minus.get_active() ):
+ self._display._sett['+'] = False
+ else:
+ widget.set_active(True)
+
+ def toggle_minus_callback(self, widget):
+ if widget.get_active():
+ self._display._sett['-'] = True
+ else:
+ if( self.toggle_plus.get_active() ):
+ self._display._sett['-'] = False
+ else:
widget.set_active(True)
def toggle_number_callback(self, widget, i):
diff --git a/ReckonPrimer.activity/extimesadd.py b/ReckonPrimer.activity/exercises/extimesadd.py
index 060375b..060375b 100644
--- a/ReckonPrimer.activity/extimesadd.py
+++ b/ReckonPrimer.activity/exercises/extimesadd.py
diff --git a/ReckonPrimer.activity/extimesdiv.py b/ReckonPrimer.activity/exercises/extimesdiv.py
index 3383810..3383810 100755
--- a/ReckonPrimer.activity/extimesdiv.py
+++ b/ReckonPrimer.activity/exercises/extimesdiv.py