Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ReckonPrimer.activity/expassten.py
blob: b177cfa93dbea9ec0ffb885cd3a01f281aa3dac9 (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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# -*- coding: utf-8 -*-
#(c) Markus Ehrenreich 2009
#(c) Christian Hain 2009

from exercise import Exercise
import random
import copy
from functions import *
import gtk
import pygtk
import pango
from sugar.graphics import style

class ExPassTen(Exercise):
    def __init__(self, dis, (sett, errors)):
        self._display = dis
        self._sett = sett
        self._errors = errors
#        {'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
#        }
        self._calcs = self._generate_calcs()
    
    def format(self, (cs, ms, linepos)):
        """format the calc for display, prepare overlays for input"""
        #print('in ExPassTen.format: (cs, ms, linepos)=', (cs, ms, linepos))
        if ms is None:
            #@print('in Display.format_passten 1: calc=', (cs, linepos)) #@
            return self.format_addsub_simp((cs, linepos))
        elif contain(cs, '+'):
            #@print('in Display.format_passten 2: calc=', (cs, ms, linepos))#@
            if linepos == 1: ################################## unused !
                #(['3', '+', '7', '=', '1', '0'], ['7', '0'], 1))
                #cs[0]     cs[2]          cs[5], ms[0]  [1],  linepos
                ### the lines of the calculation for display_calc
                #     [' ',' ',' ',' ','_',' ','+',' ','7'  ,' ','=',' ','1'  ,'0']
                _l0 = [' ',' ',' ',' ','_',' ','+',' ',cs[2],' ','=',' ',cs[4],cs[5]]
                #     [' ',' ',' ','_','+','_',' ',' ',' ',' ',' ',' ',' ',' ']
                _l1 = [' ',' ',' ','_','+','_',' ',' ',' ',' ',' ',' ',' ',' ']
                ### the 1st input --> _p0 = '(3+_)+7=10'
                _pe0 = ''.join(['(','_','+','_',')','+',cs[2],'=',cs[4],cs[5]])
                _po0 = ''.join(['(',ms[0],'+','_',')','+',cs[2],'=',cs[4],cs[5]])
                _i0 = (1, 3, ms[0], _pe0, _po0,
                       [' ',' ',' ',ms[0],'+','_',' ',' ',' ',' ',' ',' ',' ',' '])
                ### the 2nd input --> _p0 = '(3+0)+7=10'
                _pe1 = ''.join(['(',ms[0],'+','_',')','+',cs[2],'=',cs[4],cs[5]])
                _po1 = ''.join(['(',ms[0],'+',ms[1],')','+',cs[2],'=',cs[4],cs[5]])
                _i1 = (1, 5, ms[1], _pe1, _po1,
                       [' ',' ',' ',ms[0],'+',ms[1],' ',' ',' ',' ',' ',' ',' ',' '])
                ### the 3rd input --> _p0 = '3+7=10'
                _pe2 = ''.join(['_'  ,'+',cs[2],'=',cs[4],cs[5]])
                _po2 = ''.join([cs[0],'+',cs[2],'=',cs[4],cs[5]])
                _i2 = (0, 13, cs[5], _pe2, _po2,
                       [' ',' ',' ',' ','3',' ','+',' ','7',' ','=',' ','1',cs[5]])
                #@print('in Display.format_passten: return=', ([_l0, _l1], [_i2, _i1, _i0])) #@
                return ([_l0, _l1], [_i2, _i1, _i0]) #_iN reversed for pop
            elif linepos == 3:
                #(['3', '+', '7', '=', '1', '0'], ['3', '0'], 5))
                #cs[0]     cs[2]          cs[5], ms[0]  [1],  linepos
                _l0 = [' ',' ',' ',' ',cs[0],' ','+',' ','_',' ','=',' ',cs[4],cs[5]]
                _l1 = [' ',' ',' ',' ',' ',  ' ',' ','_','+',  '_',' ',' ',' '  ,' ']
                #     '3+(7+_)=10'
                _pe0 = ''.join([cs[0],'+','(','_'  ,'+','_',')','=',cs[4],cs[5]])
                _po0 = ''.join([cs[0],'+','(',ms[0],'+','_',')','=',cs[4],cs[5]])
                _i0 = (1, 7, ms[0], _pe0, _po0,
                       [' ',' ',' ',' ',' ',' ',' ',ms[0],'+','_',' ',' ',' '  ,' '])
                #     '3+(7+0)=10'
                _pe1 = ''.join([cs[0],'+','(',ms[0],'+','_'  ,')','=',cs[4],cs[5]])
                _po1 = ''.join([cs[0],'+','(',ms[0],'+',ms[1],')','=',cs[4],cs[5]])
                _i1 = (1, 9, ms[1], _pe1, _po1,
                       [' ',' ',' ',' ',' ',' ',' ',ms[0],'+',ms[1],' ',' ',' ',' '])
                #     '3+7=10'
                _pe2 = ''.join([cs[0],'+','_','=',cs[4],cs[5]])
                _po2 = ''.join([cs[0],'+',cs[2],'=',cs[4],cs[5]])
                _i2 = (0, 8,cs[2], _pe2, _po2,
                       [' ',' ',' ',' ',cs[0],' ','+',' ',cs[2],' ','=',' ',cs[4],cs[5]])
                #@print('in Display.format_passten: return=', ([_l0, _l1], [_i2, _i1, _i0])) #@
                return ([_l0, _l1], [_i2, _i1, _i0]) #_iN reversed for pop
            elif linepos == 5:
                #(['3', '+', '7', '=', '1', '0'], ['7', '0'], 5))
                #cs[0]     cs[2]          cs[5], ms[0]  [1],  linepos
                _l0 = [' ',' ',' ',' ',cs[0],' ','+',' ',cs[2],' ','=',' ',cs[4],'_']
                _l1 = [' ',' ',' ',' ',' ',  ' ',' ','_','+',  '_',' ',' ',' '  ,' ']
                #     '3+(7+_)=1_'
                _pe0 = ''.join([cs[0],'+','(','_'  ,'+','_',')','=',cs[4],'_'])
                _po0 = ''.join([cs[0],'+','(',ms[0],'+','_',')','=',cs[4],'_'])
                _i0 = (1, 7, ms[0], _pe0, _po0,
                       [' ',' ',' ',' ',' ',' ',' ',ms[0],'+','_',' ',' ',' '  ,' '])
                #     '3+(7+0)=1_'
                _pe1 = ''.join([cs[0],'+','(',ms[0],'+','_'  ,')','=',cs[4],'_'])
                _po1 = ''.join([cs[0],'+','(',ms[0],'+',ms[1],')','=',cs[4],'_'])
                _i1 = (1, 9, ms[1], _pe1, _po1,
                       [' ',' ',' ',' ',' ',' ',' ',ms[0],'+',ms[1],' ',' ',' ',' '])
                #     '3+7=10'
                _pe2 = ''.join([cs[0],'+',cs[2],'=',cs[4],'_'  ])
                _po2 = ''.join([cs[0],'+',cs[2],'=',cs[4],cs[5]])
                _i2 = (0, 13,cs[5], _pe2, _po2,
                       [' ',' ',' ',' ',cs[0],' ','+',' ',cs[2],' ','=',' ',cs[4],cs[5]])
                #@print('in Display.format_passten: return=', ([_l0, _l1], [_i2, _i1, _i0])) #@
                return ([_l0, _l1], [_i2, _i1, _i0]) #_iN reversed for pop
            else:
                print('in Display.format_passten: not exists linepos=', linepos)
                #TODO exit, programmer mode
#            #for linepos = 5:
#            return ([[' ',' ',' ',' ','3',' ','+',' ','_',' ','=',' ','1','_'],
#                     [' ',' ',' ',' ',' ','_','+','_',' ',' ',' ',' ',' ',' ']],
#                    [(0, 13,'0', '3+(_+_)=1_', '3+(7+_)=1_',
#                      [' ',' ',' ',' ','3',' ','+',' ','7',' ','=',' ','1','_']),
#                     (1, 7, '0', '3+(7+_)=1_, '3+(7+0)=1_',
#                      [' ',' ',' ',' ',' ','7','+','_',' ',' ',' ',' ',' ',' ']),
#                     (1, 5, '7', '3+7+=1_', '3+7=10'
#                      [' ',' ',' ',' ',' ','_','+','_',' ',' ',' ',' ',' ',' '])])
        else: #contain(calc, '-')
            #@print('in Display.format_passten 3: calc=', (cs, ms, linepos))#@
            if linepos == 1:
                #(['1', '0', '-', '7', '=', '3'], ['3', '0'], 3))
                #     cs[1]     cs[3]     cs[5], ms[0]  [1],  linepos
                _l0 = [cs[0],'_',' ','-',' ',cs[3],' ','=',' ',cs[5],' ']                
                _l1 = [' '  ,' ',' ',' ',' ',' '  ,' ',' ','_','+'  ,'_']                
                ### the 1st input --> _p0 = '1_-7=(3+_)'
                _pe0 = ''.join([cs[0],'_','-',cs[3],'=','(','_'  ,'+','_',')',])
                _po0 = ''.join([cs[0],'_','-',cs[3],'=','(',ms[0],'+','_',')',])
                _i0 = (1, 8, ms[0], _pe0, _po0,
                       [' '  ,' ',' ',' ',' ',' '  ,' ',' ',ms[0],'+'  ,'_'])
                ### the 2nd input --> _p1 = '1_-7=(3+0)'
                _pe1 = ''.join([cs[0],'_','-',cs[3],'=','(',ms[0],'+','_'  ,')',])
                _po1 = ''.join([cs[0],'_','-',cs[3],'=','(',ms[0],'+',ms[1],')',])
                _i1 = (1, 10, ms[1], _pe1, _po1,
                       [' '  ,' ',' ',' ',' ',' '  ,' ',' ',ms[0],'+'  ,ms[1]])
                ### the 3rd input --> _p2 = '10-7=3'
                _pe2 = ''.join([cs[0],'_'  ,'-',cs[3],'=',cs[5]])
                _po2 = ''.join([cs[0],cs[1],'-',cs[3],'=',cs[5]])
                _i2 = (0, 1, cs[1], _pe2, _po2,
                       [cs[0],cs[1],' ','-',' ',cs[3],' ','=',' ',cs[5],' '])
                #@print('in Display.format_passten: return=', ([_l0, _l1], [_i2, _i1, _i0])) #@
                return ([_l0, _l1], [_i2, _i1, _i0]) #_iN reversed for pop
            elif linepos == 3:
                #(['1', '0', '-', '7', '=', '3'], ['0', '7'], 3))
                #     cs[1]     cs[3]     cs[5], ms[0]  [1],  linepos
                _l0 = [cs[0],cs[1],' ','-',' ','_',' ','=',' ',cs[5],' ']                
                _l1 = [' '  ,' '  ,' ',' ','_','+','_',' ',' ',' '  ,' ']
                #     '10-_=(0+_)'
                _pe0 = ''.join([cs[0],cs[1],'-','(','_','+','_',')','=',cs[5]])
                _po0 = ''.join([cs[0],cs[1],'-','(',ms[0],'+','_',')','=',cs[5]])
                _i0 = (1, 4, ms[0], _pe0, _po0,
                       [' '  ,' '  ,' ',' ',ms[0],'+','_',' ',' ',' '  ,' '])
                #     '10-_=(0+3)'
                _pe1 = ''.join([cs[0],cs[1],'-','(',ms[0],'+','_'  ,')','=',cs[5]])
                _po1 = ''.join([cs[0],cs[1],'-','(',ms[0],'+',ms[1],')','=',cs[5]])
                _i1 = (1, 6, ms[1], _pe1, _po1,
                       [' '  ,' '  ,' ',' ',ms[0],'+',ms[1],' ',' ',' '  ,' '])
                #     '10-7=3'
                _pe2 = ''.join([cs[0],cs[1],'-','_'  ,'=',cs[5]])
                _po2 = ''.join([cs[0],cs[1],'-',cs[3],'=',cs[5]])
                _i2 = (0, 5, cs[3], _pe2, _po2,
                       [cs[0],cs[1],' ','-',' ',cs[3],' ','=',' ',cs[5],' '])
                #@print('in Display.format_passten: return=', ([_l0, _l1], [_i2, _i1, _i0])) #@
                return ([_l0, _l1], [_i2, _i1, _i0]) #_iN reversed for pop
            elif linepos == 5:
                #(['1', '0', '-', '7', '=', '3'], ['0', '7'], 3))
                #     cs[1]     cs[3]     cs[5], ms[0]  [1],  linepos
                _l0 = [cs[0],cs[1],' ','-',' ',cs[3],' ','=',' ','_',' ']                
                _l1 = [' '  ,' '  ,' ',' ','_','+'  ,'_',' ',' ',' ',' ']
                #     '10-(0+_)=_'
                _pe0 = ''.join([cs[0],cs[1],'-','(','_'  ,'+','_',')','=','_'])
                _po0 = ''.join([cs[0],cs[1],'-','(',ms[0],'+','_',')','=','_'])
                _i0 = (1, 4, ms[0], _pe0, _po0,
                       [' '  ,' '  ,' ',' ',ms[0],'+'  ,'_',' ',' ',' ',' '])
                #     '10-(0+7)=_'
                _pe1 = ''.join([cs[0],cs[1],'-','(',ms[0],'+','_',')','=','_'])
                _po1 = ''.join([cs[0],cs[1],'-','(',ms[0],'+',ms[1],')','=','_'])
                _i1 = (1, 6, ms[1], _pe1, _po1,
                       [' '  ,' '  ,' ',' ',ms[0],'+'  ,ms[1],' ',' ',' ',' '])
                #     '10-7=3'
                _pe2 = ''.join([cs[0],cs[1],'-',cs[3],'=','_'  ])
                _po2 = ''.join([cs[0],cs[1],'-',cs[3],'=',cs[5]])
                _i2 = (0, 9, cs[5], _pe2, _po2,
                       [cs[0],cs[1],' ','-',' ',cs[3],' ','=',' ',cs[5],' '])
                #@print('in Display.format_passten: return=', ([_l0, _l1], [_i2, _i1, _i0])) #@
                return ([_l0, _l1], [_i2, _i1, _i0]) #_iN reversed for pop
            else:
                print('in Display.format_passten: not exists linepos=', linepos)
                #TODO exit, programmer mode
        
    def _generate_calcs(self):
        _dic = self._sett
        #print("in ExPassTen._generate_calcs: _dic=", _dic)
        _calcs = []
        _c = []
        # generate all calcs
        if _dic['+']:
            _c = self._pass10add(_dic['min'], _dic['max'], _dic['input'], _dic['newline'], _dic['shuffle_inner'], _dic['shuffle_all'])
            _calcs.extend(_c)

        if _dic['-']:
            _c = self.pass10sub(_dic['min'], _dic['max'], _dic['input'], _dic['newline'], _dic['shuffle_inner'], _dic['shuffle_all'])
            _calcs.extend(_c)
            
        if _dic['shuffle_all']:
            random.shuffle(_calcs)   
        return _calcs

    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_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.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.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.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.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.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.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.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.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_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.append(self.toggle)

    def set_buttons(self, sett):
        """ See comment in Exercies.set_buttons. """
        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:
            self.toggle_minus.set_active(False) 
            
        if (sett['newline'] == True):
            self.toggle_newline.set_active(True)
        else:
            self.toggle_newline.set_active(False)
            
        if (sett['shuffle_all'] == True):
            self.toggle_shuffle_all.set_active(True)
        else:
            self.toggle_shuffle_all.set_active(False)
            
        if (sett['shuffle_inner'] == True):
            self.toggle_shuffle_inner.set_active(True)
        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 ): 
                self.toggle_pos5.set_active(True)

    #**** callbacks ********************************************************

    def toggle_newline_callback(self, widget):
        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():
            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():
            self._display._sett['shuffle_inner'] = True
        else:
            if(self.toggle_shuffle_all.get_active()):   
                widget.set_active(True)
            else:
                self._display._sett['shuffle_inner'] = False
                
    def toggle_pos3_callback(self, widget):
        if widget.get_active():
            self._display._sett['input'] = list(set(self._display._sett['input']) | set([3]))
        else:
            if(self.toggle_pos5.get_active()):
                self._display._sett['input'] = list(set(self._display._sett['input']) - set([3]))
            else:
                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]))
        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:
               widget.set_active(True)
               
    def toggle_number_callback(self, widget, i):

        if widget.get_active():
            if(i < self._display._sett['min']):
                self._display._sett['min'] = i
                self.set_buttons(self._display._sett)
                    

            elif( i > self._display._sett['max'] ):
                self._display._sett['max'] = i
                self.set_buttons(self._display._sett)
                    
        else:
            if( i == self._display._sett['min'] ):
                if( self._display._sett['min'] == self._display._sett['max'] ):
                    widget.set_active(True)
                else:           
                    self._display._sett['min'] = i+1
    
                self.set_buttons(self._display._sett)
                
            elif( i == self._display._sett['max'] ):
                if( self._display._sett['min'] == self._display._sett['max'] ):
                    widget.set_active(True)
                else:           
                    self._display._sett['max'] = i-1                 
                    
                self.set_buttons(self._display._sett)
                
            else:
                widget.set_active(True)
        
    ##### end of public methods ############################################

    def _pass10add(self, min_, max_, inpt, newlin, shuffle_inner, shuffle_all):
        """generate all calcs with + for crossing the tens barrier"""
        _ret_list= []
        for _m in range(min_, max_ + 1):
            _iter_r = []
            _mdown = min_ + max_ - _m # iterator goes down
            #print('in Generate._pass10add _m=',_m, '_mdown=',_mdown)
            for _j in range(10 - _mdown, 10):
                #print('in Generate._pass10add _j=', _j)
                _inp = random.choice(inpt)
                if newlin:
                    if _inp == 1:
                        _y = (10 - _j)
                    else:
                        _y = (10 - _mdown)
                    _z = (_mdown + _j) - 10
                    _iter_r.append(([str(_mdown), '+', str(_j), '=', '1', str((_mdown + _j) - 10)], [str(_y), str(_z)], _inp))
                else:
                    _iter_r.append(([str(_mdown), '+', str(_j), '=', '1', str((_mdown + _j) - 10)], None, _inp))
            if shuffle_inner:
                random.shuffle(_iter_r)
            _ret_list.extend(_iter_r)
        if shuffle_all:
            random.shuffle(_ret_list)
        return _ret_list
        
    def pass10sub(self, min_, max_, inpt, newlin, shuffle_inner, shuffle_all):
        """generate all calcs with + for crossing the tens barrier"""
        _ret_list= []
        for _m in range(min_, max_ + 1):
            _iter_r = []
            _mdown = min_ + max_ - _m # iterator goes down
            #print('in Generate.pass10sub _m=',_m, '_mdown=',_mdown)
            for _j in range(10 - _mdown, 10):
                #print('in Generate.pass10sub _j=', _j)
                _inp = random.choice(inpt)
                if newlin:
                    if _inp == 1:
                        _y = (10 - _j)
                        _z = (_mdown + _j) - 10
                    else:
                        _y = (_mdown + _j) - 10
                        _z = (10 - _mdown)
                    _iter_r.append((['1',str((_mdown + _j) - 10), '-', str(_j), '=', str(_mdown)], [str(_y), str(_z)], _inp))
                else:
                    _iter_r.append((['1',str((_mdown + _j) - 10), '-', str(_j), '=', str(_mdown)], None, _inp))
            if shuffle_inner:
                random.shuffle(_iter_r)
            _ret_list.extend(_iter_r)
        if shuffle_all:
            random.shuffle(_ret_list)
        return _ret_list