Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ReckonPrimer.activity/exstore.py
blob: ce22ed393f0797d486c7bc2990c5d7bb3867fe61 (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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# -*- 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._dis = display
        self._coach = coach
        self._active_exerc = None
        #Provisorium für impl. "treeView-Kollektion" vvvvvvvvvvvvvvvvvvvv


####### _c1 ##################################################################
####### _c1c1c1t #############################################################
        _sett = {'topic'    : 'times_div', 
         'title'        : '99-er Reihe',
         'descript'     : 'settings: series (2,4,8 is possible!) of *, "in" and : with remainder, series 11..19 (left bar),series 10..90 (right long bar), separate shuffling or operands.',
         'icon'         : None,  
         'calclines'    : 1,     
         'MAX'          : 50,    
                                 
         'MIN'          : 10,    
         '*'            : True, 
         '*commute'     : False, 
         ':'            : False,  
         'in'           : False, 
         'remainder'    : False, 
         'vadd'         : 0,     
         'vmult'        : 1,     
	 'factors'	: [99], 
         'shuffle_all'  : True, 
         'shuffle_inner': True, 
         'cut-max'      : True   
                        }
        _sett['factors'] = [2]; _sett['title'] = '2-er Reihe'
        _c1c1c1t2 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [3]; _sett['title'] = '3-er Reihe'
        _c1c1c1t3 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [4]; _sett['title'] = '4-er Reihe'
        _c1c1c1t4 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [5]; _sett['title'] = '5-er Reihe'
        _c1c1c1t5 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [6]; _sett['title'] = '6-er Reihe'
        _c1c1c1t6 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [7]; _sett['title'] = '7-er Reihe'
        _c1c1c1t7 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [8]; _sett['title'] = '8-er Reihe'
        _c1c1c1t8 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [9]; _sett['title'] = '9-er Reihe'
        _c1c1c1t9 = Task(copy.deepcopy(_sett), [])
####### _c1c1c2t #############################################################
        _sett['factors'] = [2,4]; _sett['title'] = '2,4-er Reihe'
        _c1c1c2t1 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [2,4,8]; _sett['title'] = '2,4,8-er Reihe'
        _c1c1c2t2 = Task(copy.deepcopy(_sett), [])
        #_sett['factors'] = [5,10]; _sett['title'] = '-er Reihe'
        #_c1c1c2t2 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [3,6]; _sett['title'] = '3,6-er Reihe'
        _c1c1c2t3 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [3,6,9]; _sett['title'] = '3,6,9-er Reihe'
        _c1c1c2t4 = Task(copy.deepcopy(_sett), [])
####### _c1c1c3t #############################################################
        _sett['factors'] = [2,3,4,5,6,7,8,9]; _sett['title'] = 'nur *'
        _c1c1c3t1 = Task(copy.deepcopy(_sett), [])
        _sett['*'] = False; _sett['in'] = True; _sett['title'] = "nur 'in'"
        _c1c1c3t2 = Task(copy.deepcopy(_sett), [])
        _sett['*'] = True; _sett['in'] = False; _sett['vadd'] = 10; _sett['vmult'] = 10; _sett['title'] = "grosse Zahlen"
        _c1c1c3t3 = Task(copy.deepcopy(_sett), [])
####### _c1c2c1c1 ############################################################
        _sett['*'] = False; _sett['in'] = False; _sett[':'] = True; _sett['vadd'] = 0; _sett['vmult'] = 1; _sett['factors'] = [2]; _sett['title'] = "2-er Reihe"
        _c1c2c1c1t1 = Task(copy.deepcopy(_sett), [])
        _sett['factors'] = [3]; _sett['title'] = "2-er Reihe"



####### _c2 ##################################################################
####### _c3 ##################################################################
        _c3t1 = Task({'topic' : 'addsub_simp',
         'title'    : 'Template: + - within 10',
         'descript' : 'settings: range of result, input at 3 positions, swap around =',
         'icon'     : None,   # for quick reference of the exercise      
         'calclines': 1,      # no. of lines for calc to be input.
         'MAX'      : 100,    # 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
         '-'        : False,   # make all subtactions min..max
         '_+_=_'    : True,   # = is _right_ from operator, e.g. 1+2=3
         'input='   : [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'  : False,  # shuffle _all_ the calcs
         'cut-max'  : True    # cut set of all calcs down to MAX
        }, [])
        _c3t2 = Task({'topic'   : 'passten',
         'title'        : 'Template: + - with carry',
         'descript'     : 'settings: range of 1st operand, input left and right from =, input intermediate result, separate shuffling of operands.',
         '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
         'max'          : 2,    # +: maximum in size of number in left argument
         'input'        :[3],   # list of positions in calc 3 | 5
                                # where input is possible.
         '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
        }, [])
        _c3t3 = Task({'topic'    : 'times_div', #for programmers only
         'title'        : 'Template: * : "in" series',
         'descript'     : 'settings: series (2,4,8 is possible!) of *, "in" and : with remainder, series 11..19 (left bar),series 10..90 (right long bar), separate shuffling or operands.',
         'icon'         : None,  # for quick reference of the exercise      
         'calclines'    : 1,     # no. of lines for calc to be input.2
         '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
	 '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
        }, [])
        _c3t4 = Task({'topic'    : 'exaddsub',
         'title'    : 'Template: +- in a column',
         'descript' : 'TODO',
         'icon'     : None, # for quick reference of the exercise
         'calclines': 4,    # no. of lines for calc to be input.
         'MAX'      : 10,   # maximum of calcs generated.
         'MIN'      : 10,   # minimum of calcs generated UNUSED
         'length'   :  3,   # max number of digits in summands
                            # _max_length =< 6 because of Display
         'args'     :  2,   # FIXED due to constraints in
                            # _generate_calcs and format
         'carry'    : False,# the calculation might involve carries
         'ops'      : ["+", "-"],#["+", "-"] are the only options
         'shuffle'  : True,
         'cut-max'  : True  # cut set of all calcs down to MAX
        }, [])
        _c3t5 = Task({'topic'  : 'exmult',
         'title' : 'Template: * with large numbers',
         'descript': 'TODO',
         'icon' : None,     # for quick reference of the exercise      
         'calclines': 4,    # no. of lines for calc to be input.
         'MAX'    : 10,     # maximum of calcs generated.
         'MIN'    : 10,     # minimum of calcs generated UNUSED
         'fact1'  :  5,     # number of digits of left factor
         'fact2'  :  1,     # FIXED due to constraints in
                            # _generate_calcs and format
         'cut-max': True    # cut set of all calcs down to MAX
        }, [])
 
        self._root = \
Collection("root = invisible node","required by tree structure", None, 
  [Collection("Praxis Volksschule PHSt",                         #_c1
              "Rechenuebungen fuer die 1. und 2.Klasse, festgelegt am 16.Dez.09 mit Nina Jaklitsch und Arndt Stoeckl .", 
              None, 
     [Collection("Uebungen . und 'in' ",                         #_c1c1
                 " ", None, 
        [Collection("Einzelne Reihen . und 'in'",                #_c1c1c1 
                    " ", None, 
           [_c1c1c1t2, _c1c1c1t3, _c1c1c1t4, _c1c1c1t5, 
            _c1c1c1t6, _c1c1c1t7, _c1c1c1t8, _c1c1c1t9
           ]),
         Collection("Mehrere Reihen .", 
                    "Wir ueben zusammengehoerende Reihen.", None, 
           [_c1c1c2t1, _c1c1c2t2, _c1c1c2t3, _c1c1c2t4
           ]),
         Collection("Alle Reihen gemischt", 
                    " ", None, 
           [_c1c1c3t1, _c1c1c3t2, _c1c1c3t3
           ])
        ]),                             
      Collection("Uebungen :",                                   #_c1c2
                 " ", None, 
        [Collection(": ohne Rest",                               #_c1c2c1
                    " ", None, 
            [Collection("Reihen einzeln",                         #_c1c2c1c1
                        " ", None, 
                [_c1c2c1c1t1
                ])
             ])
        ]),
      Collection("Uebungen + und - ",                            #_c1c3
                 " ", None, 
        [
        ])
     ]),
   Collection("Mini course",       #_c2
              "Most efficient introduction to the four basic arithmetic \
               operations as taught in the last century in Upper Austria.", 
              None, 
     [
     ]),
   Collection("Templates",          #_c3
              "These are the (classes of) exercises all others are derived \
               from. Thus, please, do not deletem them. \
               For testing exercises disabling of @ is recommended.", None, 
     [_c3t1, _c3t2, _c3t3, _c3t4, _c3t5])
  ])


        # 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._dis.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._dis, (obj.get_settings(), obj.get_eval()))