diff options
author | Walther Neuper <neuper@neuper.(none)> | 2009-12-13 16:47:37 (GMT) |
---|---|---|
committer | Walther Neuper <neuper@neuper.(none)> | 2009-12-13 16:47:37 (GMT) |
commit | 0b19f6df5b54a490d78b7f7cf754b655448e0fd3 (patch) | |
tree | 6deb912faf0df3ac00c4ccc6470e939d2f07a303 | |
parent | 8731c9ec1da6a087277eee523519685a0015ba98 (diff) |
cleaning code
-rwxr-xr-x | ReckonPrimer.activity/coach.py | 57 | ||||
-rw-r--r-- | ReckonPrimer.activity/collection.py | 8 | ||||
-rwxr-xr-x | ReckonPrimer.activity/exercise.py | 30 | ||||
-rw-r--r-- | ReckonPrimer.activity/learner.py | 10 | ||||
-rwxr-xr-x | ReckonPrimer.activity/settings.py | 72 |
5 files changed, 50 insertions, 127 deletions
diff --git a/ReckonPrimer.activity/coach.py b/ReckonPrimer.activity/coach.py index c6123ca..83d3623 100755 --- a/ReckonPrimer.activity/coach.py +++ b/ReckonPrimer.activity/coach.py @@ -3,30 +3,15 @@ import os import pprint import pickle -from settings import Settings from display import Display -#WN.LV remove these after new collection -from exercise import Exercise -from exaddsimp import ExAddSimp -from expassten import ExPassTen -from extimesdiv import ExTimesDiv class Coach: - """determines Settings which might come from Display. - Thus Coach is an observer (!design pattern!) of Display, - and consequently Session is an observer (!design pattern!) of Coach - """ - - print("DEL import Coach") + """ The coach supervises the selection of exercises. """ + #print('in coach, class definition') def __init__(self): print("DEL do Coach.__init__") - self._setts = Settings() - self._key = '' - # self._dis = sess._dis # see sequence of creation in Session - # --->???self._curr_sett = None - Coach has only 1 current setting - # self._exs = self.create_exs() - self._ex = None + self._ex = None # the learner can change the settings of _this_ exerc def register(self, sess, dis, collect, learner): self._sess = sess @@ -34,32 +19,6 @@ class Coach: self._collect = collect self._learner = learner -# def create_exercises(self): -# self._exs = self.create_exs() -# -# def create_exs(self): -# """TODO version preliminary until exs are stored on disk""" -# -# ['addsub_simp', 'passten', 'times_div'] -# _ex1 = ExAddSimp(self._dis, None) -# _ex2 = ExPassTen(self._dis, None) -# _ex3 = ExTimesDiv(self._dis, None) -# return[_ex1, _ex2, _ex3] - -# def _update_exs(self, ex): -# """update one of the examples known to Coach by topic. -# TODO after exs are stored on disk: take ID instead topic -# """ -# -# # print('in Coach.update_ex: ex.topic=', ex.get_topic()) -# _exs = [] -# for _e in self._exs: -# if _e.get_topic() == ex.get_topic(): -# _exs.append(ex) -# else: -# _exs.append(_e) -# self._exs = _exs - def request_exercise(self): """ This preliminary version just lets the Learner select. """ #print("in coach.request_exercise") @@ -69,18 +28,12 @@ class Coach: def notify(self, (msg, data)): """called by the observed objects""" print("in coach.notify: msg=, data=", (msg, data)) - if msg == 'setting-done': # from display + if msg == 'setting-done': # from display self._ex.update_setting(data) - #self._update_exs(self._ex) self._learner.notify((msg, self._ex)) - elif msg == 'exerc-selected': + elif msg == 'exerc-selected': # from collection self._ex = self._collect.select(data) print('in coach.notify(exerc-selected), 93 self._ex._sett=', self._ex._sett) self._dis.offer_setting(self._ex) -# def get_ex(self, tpc): -# """ Get an Exercise by topic. """ -# for _t in self._exs: -# if _t.get_topic() == tpc: -# return _t diff --git a/ReckonPrimer.activity/collection.py b/ReckonPrimer.activity/collection.py index 948dccd..3f86717 100644 --- a/ReckonPrimer.activity/collection.py +++ b/ReckonPrimer.activity/collection.py @@ -31,10 +31,7 @@ class Collection: def select(self, key): """ Select an exercise by key. """ - #WN.LV Code ersetzen, key NICHT fuer Listen sondern fuer ... - print('in collection.select, key=', key) - print('in collection.select, _data=', self._data) - print('in collection.select, _data[key]=', self._data[key]) + #WN.LV Code ersetzen: key ist dann fuer Listen von Listen !! _sett = self._data[key] if _sett['topic'] == 'addsub_simp': return ExAddSimp(self._display, _sett) @@ -78,10 +75,9 @@ class Collection: self.button.show() _i = _i + 1 self.topic_box.show() - def select_exerc_callback(self, widget, topic): - """callback: get the users choice from buttons above the settings""" + """ Callback telling the item from the collection selected. """ if(self._active_topic == None): self._active_topic = topic print('in collection.select_exerc_callback, 422 self._sett=', diff --git a/ReckonPrimer.activity/exercise.py b/ReckonPrimer.activity/exercise.py index 5d03401..63e6adf 100755 --- a/ReckonPrimer.activity/exercise.py +++ b/ReckonPrimer.activity/exercise.py @@ -22,10 +22,6 @@ class Exercise: """ An Exercise needs the Display for updating the settings""" self._display = None - def get_topic(self): - """The topic is preliminarily used to identify an exercise.""" - return (self._sett)['topic'] - def get_setting(self): return self._sett @@ -48,18 +44,6 @@ class Exercise: the current settings """ return len(self._calcs) - def format_addsub_simp(self, (calc, linepos)): - """ Prepare the representation of a calculation for Display - on 1 line. Used within several subclasses. """ - #@print('in Display.format_addsub_simp: calc=', (calc, linepos))#@ - _ccs = collect_digits(calc) - #print('in Exercise.format_addsub_simp: _ccs=',_ccs ) - _l0 = make_line(_ccs, linepos) - _ip = make_input(_ccs, linepos) - #@print('in Display.format_addsub_simp: return=', ([_l0], _ip)) #@ - return ([_l0], _ip) -#return ([[' ', '1', '0', ' ', '-', ' ', '7', ' ', '=', ' ', '_', ' ']], [(0, 10, '3', ' 10 - 7 = _ ', ' 10 - 7 = 3 ', [' ', '1', '0', ' ', '-', ' ', '7', ' ', '=', ' ', '3', ' '])]) - #===== methods of subclasses different for topic-specific settings def format(self, calc): """ Prepare the representation of a calculation for Display. @@ -79,3 +63,17 @@ class Exercise: def set_buttons(self, sett): """ Display buttons according to the current setting. """ pass + + #===== methods is used by more than one subclass + def format_addsub_simp(self, (calc, linepos)): + """ Prepare the representation of a calculation for Display + on 1 line. Used within several subclasses. """ + #@print('in Display.format_addsub_simp: calc=', (calc, linepos))#@ + _ccs = collect_digits(calc) + #print('in Exercise.format_addsub_simp: _ccs=',_ccs ) + _l0 = make_line(_ccs, linepos) + _ip = make_input(_ccs, linepos) + #@print('in Display.format_addsub_simp: return=', ([_l0], _ip)) #@ + return ([_l0], _ip) +#return ([[' ', '1', '0', ' ', '-', ' ', '7', ' ', '=', ' ', '_', ' ']], [(0, 10, '3', ' 10 - 7 = _ ', ' 10 - 7 = 3 ', [' ', '1', '0', ' ', '-', ' ', '7', ' ', '=', ' ', '3', ' '])]) + diff --git a/ReckonPrimer.activity/learner.py b/ReckonPrimer.activity/learner.py index a678574..bbb831e 100644 --- a/ReckonPrimer.activity/learner.py +++ b/ReckonPrimer.activity/learner.py @@ -7,8 +7,7 @@ class Learner: self._display = display self._coach = coach self._ex = None - self._key = None - self._curr_in = None # TODO rm ??? + self._curr_in = None pass def run(self): @@ -21,18 +20,17 @@ class Learner: def notify(self, (msg, data)): '''called by the observed objects''' - #print('in Session.notify: msg=,data=', msg, data) + #print('in learner.notify: msg=,data=', msg, data) if msg == 'setting-done': # from Coach self._ex = data - self._key = data.get_topic() _calc = self._ex.get_next_calc() _lines, self._input = data.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 + # create_entryline sets the callback from gtk to display if msg == 'digit-done': # from Display - #print('in Session.notify, digit-done: _input=', self._input) + #print('in learner.notify, digit-done: _input=', self._input) (lino, pos, dig, proterr, protok, li) = self._curr_in self._display.create_entryline((lino, -1, dig, proterr, protok, li)) try: # _input.pop() diff --git a/ReckonPrimer.activity/settings.py b/ReckonPrimer.activity/settings.py index 3e115a9..39b8ec1 100755 --- a/ReckonPrimer.activity/settings.py +++ b/ReckonPrimer.activity/settings.py @@ -4,21 +4,14 @@ import pickle
import os
class Settings:
- """
- a setting is a dictionary, the settings are a dict of dicts.
- if there is no file then the default settings are taken ...
- ... see save_last_sett, load_last_sett #due to Sugar write-constraints
-
- WN090624 settings hardcoded in exercises; this class is
- kept for authoring of new exercises: take defaults from here ?!?
- """
- print("DEL import Settings")
+ """ A setting is a dictionary, the settings are a dict of dicts. """
+ print('in settings, begin class definition')
def __init__(self):
print("DEL do Settings.__init__")
#+ and - between min and max, max <= 10
self._default_addsub_simp = \
- {'topic' : 'addsub_simp',
+ {'topic' : 'addsub_simp', #for programmers only
'title' : 'template exaddsimp',
'descript': 'addition and subtraction without carry, \
i.e. without passing the 10 barrier. ',
@@ -43,7 +36,7 @@ class Settings: }
self._default_passten = \
- {'topic' : 'passten',
+ {'topic' : 'passten', #for programmers only
'title' : 'template expassten',
'descript': 'addition and subtraction with carry, \
i.e. with passing the 10 barrier. ',
@@ -71,7 +64,7 @@ class Settings: }
self._default_times_div = \
- {'topic' : 'times_div',
+ {'topic' : 'times_div', #for programmers only
'title' : 'template extimesdiv',
'descript': 'multiplication, division and "in" \
from 2 to 19 and 20 to 190. ',
@@ -105,26 +98,26 @@ class Settings: print("in settings.get_setting, key=" + key)
return self._setts[key]
- def load_last_sett(self, key):
- _dict = None
- _path = 'coach/'
- _path_name = _path + 'LAST_' + key + '.data'
- print('in Setting.load_last_sett: _path_name=', _path_name)
- if os.path.exists(_path_name):
- _addr = open(_path_name, 'rb')
- _dict = pickle.load(_addr)
- _addr.close()
- return _dict
-
- def save_last_sett(self, key, sett):
- print('in Settings.save_last_sett')
- _path = 'coach/'
- _path_name = _path + 'LAST_' + key + '.data'
- print('in Setting.save_last_sett: _path_name=', _path_name)
- _addr = open(_path_name, 'wb')
- pickle.dump(sett, _addr)
- _addr.close()
-
+# def load_last_sett(self, key):
+# _dict = None
+# _path = 'coach/'
+# _path_name = _path + 'LAST_' + key + '.data'
+# print('in Setting.load_last_sett: _path_name=', _path_name)
+# if os.path.exists(_path_name):
+# _addr = open(_path_name, 'rb')
+# _dict = pickle.load(_addr)
+# _addr.close()
+# return _dict
+#
+# def save_last_sett(self, key, sett):
+# print('in Settings.save_last_sett')
+# _path = 'coach/'
+# _path_name = _path + 'LAST_' + key + '.data'
+# print('in Setting.save_last_sett: _path_name=', _path_name)
+# _addr = open(_path_name, 'wb')
+# pickle.dump(sett, _addr)
+# _addr.close()
+#
# def load_setting(self, key):
# """a variant of this will be used for authoring"""
# dat_name = 'C:/rpa8/coach/latest-topic.txt'
@@ -143,18 +136,3 @@ class Settings: # pickle.dump(self._default_addsub_simp, txt_file)
# elif key == 'default_passten':
# pickle.dump(self._default_passten, txt_file)
-
-
-
-# #this version will go to VS on Apr.27: get setts from file
-# def get_setting(self, key):
-# """a variant of this will be used for authoring"""
-# _sett = None
-# print("in Settings.get_setting, key=" + key)
-# _sett = self.load_setting('addsub_simp') #TODO: key
-# if _sett == None:
-# print('in Settings.get_settings, not existent key=', key)
-# ####FIXME exit
-# return (key, _setts)
-########################## + toggle Coach.get_setting ###################
-
|