Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ReckonPrimer.activity/learner.py
blob: 5df67e2c40be9d1e9781cd969de77b01dfc5033f (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
# -*- coding: utf-8 -*-

class Learner:
    """ All functionality within the learners rights. """

    def __init__(self, display, coach):
        self._display = display
        self._coach = coach
        self._ex = None
        self._curr_in = None
        pass
    
    def run(self):
        """ As long as user does exercises.
        Doing Exercises is terminated by another choice in the menu
        or by the user going bach to the OS.
        """
        self._coach.request_exercise()
        self._display.init_calc() #TODOWN091101 take Exercise as argument
        
    def start_calcs(self, exercise):
        self._ex = exercise
        self._display.set_curr_exerc(exercise)
        _calc = self._ex.get_next_calc()
        _lines, self._input = exercise.format(_calc)
        self._display.display_calc(_lines)
        self._curr_in = self._input.pop() #need _curr_in in notify
        self._display.create_entryline(self._curr_in)
        
    def digit_done(self):
        (lino, pos, dig, proterr, protok, li) = self._curr_in
        self._display.create_entryline((lino, -1, dig, proterr, protok, li))
        try: # _input.pop()
            self._curr_in = self._input.pop()
            self._display.create_entryline(self._curr_in)
        except IndexError: # start new calc
            self._display.show_progress()
            try: # get_next_calc
                _calc = self._ex.get_next_calc()
                print('in learner.notify: calc=', _calc)
                _lines, self._input = self._ex.format(_calc)
                self._display.display_calc(_lines)
                self._curr_in = self._input.pop() #need _curr_in in notify
                self._display.create_entryline(self._curr_in)
                # create_entryline sets the callback from gtk to Display
            except IndexError:
                self._display.finish_calc()