1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# -*- 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 import *
from exercises.exercise import Exercise
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)
module = getattr(package, klass)
return getattr(module, klass)(self._display, (_sett, _errors))
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 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))
|