Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ReckonPrimer.activity/exstore.py
blob: a12a77ce82d3657e8cf2ceb1119edd63c39773ed (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# -*- coding: utf-8 -*-

import gtk
import pygtk
import pango
import random
import copy
from sugar.graphics import style
#from settings import Settings #WN.100112 remove with "treeView-Kollektion"
#from coach import Coach
from collection import Collection
from task import Task
from exercises.exaddsimp import ExAddSimp
from exercises import *
from exercises.exercise import Exercise

class ExStore:
    """ Holds all exercises avaiable in RP in a tree and stores them on disk.
    The tree ist presented looking like a filebrowser, see Display.treeview.
    The Learner starts an Exercise by selecting an item of the tree.
    The Author creates new Exercises copying certain Exercises by
    drag-and-drop andself.imagecollection = gtk.gdk.pixbuf_new_from_file(
            "./img/collection.png")
        self.imageexercise = gtk.gdk.pixbuf_new_from_file(
            "./img/exercise.png") then editing the title, the description and the settings.

    """
    _root = None #hold the tree with root of Collection and leafs of Task

    def __init__(self, display, coach):
        self._display = display
        self._coach = coach
        self._active_exerc = None
        #self._sett = Settings()
        #Provisorium für die "3-Button-Version" vvvvvvvvvvvvvvvvvvvvvvvvv
        #self._data = [(self._sett.get_setting('addsub_simp'), []),
        #              (self._sett.get_setting('passten'),     []),
        #              (self._sett.get_setting('times_div'),   [])]
        #Provisorium für die "3-Button-Version" ^^^^^^^^^^^^^^^^^^^^^^^^^
        #Provisorium für impl. "treeView-Kollektion" vvvvvvvvvvvvvvvvvvvv
        _ex010 = Task({'topic'  : 'addsub_simp',
         'title' : 'template exaddsimp',
         'descript': 'addition and subtraction without carry, \
                            i.e. without passing the 10 barrier. ',
         'icon' : None,     # for quick reference of the exercise      
         'calclines': 1,    # no. of lines for calc to be input.
         'MAX'    : 30,     # maximum of calcs generated.
                            # Generate fills up by varying input.
         'MIN'    : 20,     # minimum of calcs generated UNUSED
         'min'    : 0,      # minimum in size of a number in a calc
         'max'    : 1,      # maximum  in size of a number in a calc
                            # 0 <= min <= max <= 10
         '+'      : True,   # make all additions min..max
         '-'      : True,   # make all subtactions min..max
         '_+_=_'  : True,   # = is _right_ from operator, e.g. 1+2=3
         'input=' : [1,3,5],# list of positions in calc: 1 | 3 | 5
                            # where input is possible;
                            # actual positions chosen by Generate.
         '_=_+_'  : False,  # = is _left_ from operator, e.g. 3=1+2
         '=input' : [1,3,5],# analogous to '_+_=_'
         'shuffle': True,   # shuffle _all_ the calcs
         'cut-max': True    # cut set of all calcs down to MAX
        }, [])
        _ex011 = Task({'topic'        : 'passten',
         'title' : 'template expassten',
         'descript': 'addition and subtraction with carry, \
                            i.e. with passing the 10 barrier. ',
         'icon' : None,     # for quick reference of the exercise      
         'calclines'    : 1,      # or 2 iff 'newline' : True.
         'MAX'          : 150,    # maximum of calcs generated;
                                  # TODO: Generate fills up by varying input.
         'MIN'          : 10,     # minimum of calcs generated 090416WN:UNUSED
         '+'            :True,   # + crossing the ten barrier!!
         '-'            :False,   # - goes below the ten barrier!!!
                                  # (i.e. iteration on left arg. is "outer" loop)
         'min'          : 2,   # +: minimum in size of number in left argument
         #'min'          : 5,   # +: minimum in size of number in left argument
                                  # -: minimum in size of result
         'max'          : 2,   # +: maximum in size of number in left argument
                                  # -: maximum in size of result
         #'max'          : 9,   # +: maximum in size of number in left argument
         'input'        :[3],  # list of positions in calc 3 | 5
                                  # where input is possible; 
                                  # actual positions chosen by Generate.
         'newline'      : True,    # display 2nd line for intermediate results
         'shuffle_all'  : False,   # shuffle all calcs  
         'shuffle_inner': False,   # shuffle only 1st (inner) iteration
         'cut-max'      : True   # cut set of all calcs down to MAX
        }, [])
        _ex012 = Task({'topic'        : 'times_div', #for programmers only
         'title' : 'template extimesdiv',
         'descript': 'multiplication, division and "in" \
                            from 2 to 19 and 20 to 190. ',
         'icon' : None,     # for quick reference of the exercise      
         'calclines'    : 1,      # no. of lines for calc to be input.
         'MAX'          : 50,    # maximum of calcs generated;
                                  # TODO: Generate fills up by varying input.
         'MIN'          : 10,     # minimum of calcs generated 090416WN:UNUSED
         '*'            : False,   # eg.  7 . 2 =_
         '*commute'     : False,  # commute the operands 2 . 7 = _
         ':'            : True,  # 14 : 2 = _
         'in'           : False,  # 2 in 14 = _
         'remainder'    : False,  # : | in ... with remainder
         'vadd'         : 0,      # 0 or 10, for 1.11 ... 1.19
         'vmult'        : 1,      # 1 or 10, for 1.10 ... 1.90
         'min'          : 2,      # +: minimum number in right *operand
                                  # -: minimum result
         'max'          : 2,      # +: maximum number in right *operand
                                  # -: maximum result
	     'factors'	: [2,4], # Liste mit ausgewählten zahlen zur berechnung
         'shuffle_all'  : False,   # shuffle all calcs  
         'shuffle_inner': False,   # shuffle only 1st (inner) iteration
         'cut-max'      : True   # cut set of all calcs down to MAX
        }, [])

        _coll00 = Collection("Add Sub: + & -",
                             "hier sind alle 1x1-Reihen mit 'in'",
                             None, [])

        _coll01 = Collection("Times Division: x & in",
                             "hier sind alle 1x1-Reihen mit 'in'",
                             None, [_ex010, _ex011, _ex012])

        _coll02 = Collection("Pass Ten: ->10",
                             "hier sind alle 1x1-Reihen mit 'in'",
                             None, [])

        _coll0 = Collection("Templates",
                            "Hier finden Sie alle verfügbaren Templates",
                            None, [_coll00, _coll01, _coll02])

        #constructor of collections root
        self._root = Collection("root = invisible node",
                           "aber benötigt zum richtigen speichern/lesen",
                           None, [_coll0])


        # comment to save changes (order of the items) till the next start
        self._root.set_data_in_pickle(self._root)

        #Provisorium für impl. "treeView-Kollektion" ^^^^^^^^^^^^^^^^^^^^

    def reload(self):
        self._root = self._root.get_data_from_pickle()

    def offer_coll_to_learner(self):
        """Show Collection to Learner and hand over control to Display (gtk)"""
        data = self._root.get_data()
        self._display.offer_coll_to_learner(data)

    def get_exercise(self, obj):
        """ Loads the proper exercise class for the given object and returns it
        as a new exercise object """
        exercise_label = obj.get_object_name()
        if not Exercise.EXERCISES.has_key(exercise_label):
            raise Exception('Collection#select: Wrong pos. To register an exercise see exercises/__init__.py')

        class_name = Exercise.EXERCISES[exercise_label]
        package = __import__("exercises." + class_name.lower())
        module = getattr(package, class_name.lower())
        return getattr(module, class_name)(self._display, (obj.get_settings(), obj.get_eval()))

    """
    #@# 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))
    """