diff options
author | Walther Neuper <neuper@neuper.(none)> | 2009-11-17 13:15:58 (GMT) |
---|---|---|
committer | Walther Neuper <neuper@neuper.(none)> | 2009-11-17 13:15:58 (GMT) |
commit | c2e7fd6b7cb517e5c9eb5eca2163afe686f8d762 (patch) | |
tree | de8852753e62a01ecfd5297826db8d157109225b | |
parent | ec941d573a4955a23e4615cc3188b55ef71f30ea (diff) |
deleted useless files (emacs backups, pyc, child dir ReckonPrimer.activity copy)
50 files changed, 15 insertions, 4938 deletions
@@ -1,2 +1,2 @@ *.pyc -*~
\ No newline at end of file + diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/Exercise.py b/ReckonPrimer.activity/ReckonPrimer.activity/Exercise.py deleted file mode 100755 index 4f6921b..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/Exercise.py +++ /dev/null @@ -1,71 +0,0 @@ -# -*- coding: UTF8 -*- -from functions import contain, collect_digits, make_line, make_input -from functions import make_line_remainder, make_input_remainder - -class Exercise: - """This is the base class for the individual exercises. - An exercise is characterized by a topic. A topic determines the - fields of the settings self._sett and public methods of Exercise. - The values of self._sett may vary from exercise to exercise. - """ - def __init__(self): - """ The settings determine the generation of calculations. - The fields of the settings are determined by the topic; - the values of the settings are different for exercises; - the settings may even be changed by the user.""" - self._sett = None - """Calculations have a format GOON""" - self._calcs = [] - - def get_setting(self): - pass - - def get_topic(self): - """The topic is preliminarily used to identify an exercise; - TODO: use self._sett['ID'] instead as soon as exs are stored.""" - pass - - def update_setting(self, sett): ####?????????? - """The settings may be changed by the user. This method - is inherited and thus not contained in subclasses.""" - ####self._sett = sett - - def format(self, calc): - """Prepare the representation of a calculation for Display. - This method is public for eventual use on calculations - coming through the net (TODO cooperative games, etc)""" - pass - - def generate_calcs(self): - """TODO""" - pass - - def count(self): - """TODO""" - pass - #return len(self._calcs) - - def define_buttons(self): - """XXX""" - pass - - def set_buttons(self, sett): - """XXX""" - pass - - - - - - - - def format_addsub_simp(self, (calc, linepos)): - """format the calc for display, prepare overlays for input""" - #@print('in Display.format_addsub_simp: calc=', (calc, linepos))#@ - _ccs = collect_digits(calc) - print('in Display.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/ReckonPrimer.activity/Exercise.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/Exercise.pyc Binary files differdeleted file mode 100755 index d012afe..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/Exercise.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/MANIFEST b/ReckonPrimer.activity/ReckonPrimer.activity/MANIFEST deleted file mode 100755 index b46385c..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/MANIFEST +++ /dev/null @@ -1,19 +0,0 @@ -ReckonPrimerActivity.py -Display.py -Coach.py -Settings.py -Session.py -setup.py -functions.py -Timer.py -ReckonPrimerActivity-NOGUI.py -Exercise.py -AddSubSimp.py -PassTen.py -TimesDiv.py -Display-NOGUI.py -activity/activity-reckonprimer.svg -activity/activity.info -img/addsub_simp.jpg -img/passten.jpg -img/times_div.jpg diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity-NOGUI.py b/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity-NOGUI.py deleted file mode 100755 index 2af5299..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity-NOGUI.py +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: utf-8 -*-
-"""main of ReckonPrimer
-see http://wiki.laptop.org/go/Software_projects#ReconPrimer
-(c) Walther Neuper 2009
-"""
-# WN090416 after successful run there is a strange error at the end ?!?
-
-
-from session import Session
-
-# initializations
-
-_sess = Session("ox-user-name", 'xxx') # TODO.WN090311 name should come from Sugar
-_sess.run()
-
-# finalizations
-
diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity-NOGUI.py~ b/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity-NOGUI.py~ deleted file mode 100755 index 2f01b29..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity-NOGUI.py~ +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: UTF8 -*-
-"""main of ReckonPrimer
-see http://wiki.laptop.org/go/Software_projects#ReconPrimer
-(c) Walther Neuper 2009
-"""
-# WN090416 after successful run there is a strange error at the end ?!?
-
-
-from Session import Session
-
-# initializations
-
-_sess = Session("ox-user-name", 'xxx') # TODO.WN090311 name should come from Sugar
-_sess.run()
-
-# finalizations
-
diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity.py b/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity.py deleted file mode 100755 index 45ae36d..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity.py +++ /dev/null @@ -1,83 +0,0 @@ -#! -*- coding: utf-8 -*- -#(c) Stefan Heher 2009 -from time import strftime -import pygtk -import gtk -from sugar.activity import activity -from sugar.datastore import datastore -from sugar import profile -from session import Session - -class ReckonPrimerActivity(activity.Activity): - - def __init__(self, handle): - - activity.Activity.__init__(self, handle) - """ Create the official Sugar toolbox at the top of the screen""" - toolbox = activity.ActivityToolbox(self) - self.set_toolbox(toolbox) - toolbox.show() - - file_location = activity.get_activity_root() + \ - "/data/reckonprimer_report.txt" - file_handle = open(file_location, 'w') - file_handle.write("Report: " + profile.get_nick_name() + \ - strftime(" %Y-%m-%d %H:%M:%S") + "\n") - file_handle.close() - - title = "Report: " + profile.get_nick_name() + \ - strftime(" %Y-%m-%d %H:%M:%S") - mime = "text/plain" - file_path = activity.get_activity_root() + \ - "/data/reckonprimer_report.txt" - favorite = "1" - tags = "ReckonPrimer" - - journal_object = datastore.create() - journal_object.metadata['title'] = title - journal_object.metadata['mime_type'] = mime - journal_object.file_path = file_path - journal_object.metadata['keep'] = favorite - journal_object.metadata['tags'] = tags - journal_object.metadata['icon-color'] = '#AFD600,#5B615C' - datastore.write( journal_object ) - journal_object.destroy() - - self.run_session() - - - def run_session(self): - session = Session("xo-user-name", self) - session.run() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity.pyc Binary files differdeleted file mode 100755 index a9dc98d..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity.py~ b/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity.py~ deleted file mode 100755 index 67655bb..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/ReckonPrimerActivity.py~ +++ /dev/null @@ -1,83 +0,0 @@ -#! -*- coding: utf-8 -*- -#(c) Stefan Heher 2009 -from time import strftime -import pygtk -import gtk -from sugar.activity import activity -from sugar.datastore import datastore -from sugar import profile -from Session import Session - -class ReckonPrimerActivity(activity.Activity): - - def __init__(self, handle): - - activity.Activity.__init__(self, handle) - """ Create the official Sugar toolbox at the top of the screen""" - toolbox = activity.ActivityToolbox(self) - self.set_toolbox(toolbox) - toolbox.show() - - file_location = activity.get_activity_root() + \ - "/data/reckonprimer_report.txt" - file_handle = open(file_location, 'w') - file_handle.write("Report: " + profile.get_nick_name() + \ - strftime(" %Y-%m-%d %H:%M:%S") + "\n") - file_handle.close() - - title = "Report: " + profile.get_nick_name() + \ - strftime(" %Y-%m-%d %H:%M:%S") - mime = "text/plain" - file_path = activity.get_activity_root() + \ - "/data/reckonprimer_report.txt" - favorite = "1" - tags = "ReckonPrimer" - - journal_object = datastore.create() - journal_object.metadata['title'] = title - journal_object.metadata['mime_type'] = mime - journal_object.file_path = file_path - journal_object.metadata['keep'] = favorite - journal_object.metadata['tags'] = tags - journal_object.metadata['icon-color'] = '#AFD600,#5B615C' - datastore.write( journal_object ) - journal_object.destroy() - - self.run_session() - - - def run_session(self): - session = Session("xo-user-name", self) - session.run() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/activity/activity-reckonprimer.svg b/ReckonPrimer.activity/ReckonPrimer.activity/activity/activity-reckonprimer.svg deleted file mode 100755 index de219f8..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/activity/activity-reckonprimer.svg +++ /dev/null @@ -1,108 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="55" - height="55" - id="svg2" - sodipodi:version="0.32" - inkscape:version="0.46" - inkscape:output_extension="org.inkscape.output.svg.inkscape" - sodipodi:docname="activity-reckonprimer.svg"> - <metadata - id="metadata9"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - </cc:Work> - </rdf:RDF> - </metadata> - <defs - id="defs7"> - <inkscape:perspective - sodipodi:type="inkscape:persp3d" - inkscape:vp_x="0 : 27.5 : 1" - inkscape:vp_y="0 : 1000 : 0" - inkscape:vp_z="55 : 27.5 : 1" - inkscape:persp3d-origin="27.5 : 18.333333 : 1" - id="perspective11" /> - </defs> - <sodipodi:namedview - inkscape:window-height="949" - inkscape:window-width="1280" - inkscape:pageshadow="2" - inkscape:pageopacity="0.0" - guidetolerance="10.0" - gridtolerance="10.0" - objecttolerance="10.0" - borderopacity="1.0" - bordercolor="#666666" - pagecolor="#ffffff" - id="base" - showgrid="false" - inkscape:zoom="14.927835" - inkscape:cx="27.5" - inkscape:cy="27.5" - inkscape:window-x="0" - inkscape:window-y="25" - inkscape:current-layer="svg2" /> - <rect - x="5.5359116" - y="5.3349447" - width="45" - height="45" - style="fill:#ffffff;stroke:#666666;stroke-width:3.5" - id="rect4" /> - <text - xml:space="preserve" - style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - x="28.068371" - y="26.931629" - id="text2412"><tspan - sodipodi:role="line" - id="tspan2414" - x="28.068371" - y="26.931629" /></text> - <text - xml:space="preserve" - style="font-size:18px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - x="17.28315" - y="10.38536" - id="text2420"><tspan - sodipodi:role="line" - id="tspan2422" - x="17.28315" - y="10.38536" /><tspan - sodipodi:role="line" - id="tspan2424" - x="17.28315" - y="32.885361">10</tspan></text> - <text - xml:space="preserve" - style="font-size:18px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - x="21.101521" - y="32.357735" - id="text2426"><tspan - sodipodi:role="line" - id="tspan2428" - x="21.101521" - y="32.357735" /></text> - <text - xml:space="preserve" - style="font-size:18px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - x="31.95373" - y="42.74102" - id="text2430"><tspan - sodipodi:role="line" - id="tspan2432" - x="31.95373" - y="42.74102" /></text> -</svg> diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/activity/activity.info b/ReckonPrimer.activity/ReckonPrimer.activity/activity/activity.info deleted file mode 100755 index 710cce1..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/activity/activity.info +++ /dev/null @@ -1,9 +0,0 @@ -[Activity] -name = ReckonPrimer -bundle_id = org.laptop.ReckonPrimerActivity -class = ReckonPrimerActivity.ReckonPrimerActivity -icon = activity-reckonprimer -activity_version = 5 -host_version = 1 -show_launcher = yes - diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/addsubsimp.py b/ReckonPrimer.activity/ReckonPrimer.activity/addsubsimp.py deleted file mode 100755 index 4d6b027..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/addsubsimp.py +++ /dev/null @@ -1,473 +0,0 @@ -# -*- coding: UTF8 -*- -from Exercise import Exercise -import random -import copy -from functions import * -import gtk -import pygtk -import pango -from sugar.graphics import style - -class AddSubSimp(Exercise): - def __init__(self, dis): - self.display = dis - self._calcs = [] - self._sett = {'topic' : 'addsub_simp', - 'ID' : 'addsub_simp_01', - 'descr' : 'all additions with result 5', #describe this setting - 'MAX' : 50, # 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' : 5, # 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 - } - - def get_setting(self): - return self._sett - - def get_topic(self): - return (self._sett)['topic'] - - def update_setting(self, sett): - self._calcs = self.generate_calcs() - self._sett = sett - - def generate_calcs(self): - _dic = self._sett - _calcs = [] - if _dic['+']: # '+' or '-' are True - _c = self._alladd(_dic['min'], _dic['max']) - if _dic['_+_=_']: # '_+_=_' or '_=_+_' are True - # choose 1 actual position for input - _cc = [(c, random.choice(_dic['input='])) for c in _c] - _calcs.extend(_cc) - if _dic['_=_+_']: - _cc = [swap_eq(c) for c in _c] - # choose 1 actual position for input - _cc = [(c, random.choice(_dic['=input'])) for c in _cc] - _calcs.extend(_cc) - if _dic['-']: - _c = self._allsub(_dic['min'], _dic['max']) - if _dic['_+_=_']: - _cc = [(c, random.choice(_dic['input='])) for c in _c] - _calcs.extend(_cc) - if _dic['_=_+_']: - _cc = [swap_eq(c) for c in _c] - _cc = [(c, random.choice(_dic['=input'])) for c in _cc] - _calcs.extend(_cc) - #if len(_calcs) < _dic['MIN']: TODO - if _dic['shuffle']: - random.shuffle(_calcs) - if _dic['cut-max']: - _c = copy.deepcopy(_calcs) # make a copy - _calcs = _c[:_dic['MAX']] - #print('in Generate.addsub_simp calcs=', _calcs) - return _calcs - - def format(self, (calc, linepos)): - """format the calc for display, prepare overlays for input""" - #@print('in Display.format_addsub_simp: calc=', (calc, linepos))#@ - _ccs = collect_digits(calc) - print('in Display.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', ' '])]) - - def count(self): - """TODO""" - print('in Display.count: len=', len(self._calcs)) - return len(self._calcs) - - def define_buttons(self): - self.toggle_shuffle = gtk.ToggleButton("@") - self.toggle_label = self.toggle_shuffle.get_child() - self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_shuffle.connect("toggled", self.toggle_shuffle_callback) - self.display.settings_table.attach(self.toggle_shuffle, 5, 6, 13, 14 ) - self.toggle_shuffle.show() - - self.toggle_equal_fixed_right = gtk.ToggleButton("<<") - self.toggle_label = self.toggle_equal_fixed_right.get_child() - self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_equal_fixed_right.connect("toggled", self.toggle_equal_fixed_right_callback) - self.display.settings_table.attach(self.toggle_equal_fixed_right, 5, 6, 10, 11 ) - self.toggle_equal_fixed_right.show() - - self.toggle_equal_fixed_left = gtk.ToggleButton("<<") - self.toggle_label = self.toggle_equal_fixed_left.get_child() - self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_equal_fixed_left.connect("toggled", self.toggle_equal_fixed_left_callback) - self.display.settings_table.attach(self.toggle_equal_fixed_left, 5, 6, 12, 13 ) - self.toggle_equal_fixed_left.show() - - self.toggle_pos1 = gtk.ToggleButton("--") - self.toggle_label = self.toggle_pos1.get_child() - self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_pos1.connect("toggled", self.toggle_pos1_callback) - self.display.settings_table.attach(self.toggle_pos1, 0, 1, 11, 12 ) - self.toggle_pos1.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, 11, 12 ) - 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, 11, 12 ) - self.toggle_pos5.show() - - self.toggle_pos1_lower = gtk.ToggleButton("--") - self.toggle_label = self.toggle_pos1_lower.get_child() - self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_pos1_lower.connect("toggled", self.toggle_pos1_lower_callback) - self.display.settings_table.attach(self.toggle_pos1_lower, 0, 1, 13, 14 ) - self.toggle_pos1_lower.show() - - self.toggle_pos3_lower = gtk.ToggleButton("--") - self.toggle_label = self.toggle_pos3_lower.get_child() - self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_pos3_lower.connect("toggled", self.toggle_pos3_lower_callback) - self.display.settings_table.attach(self.toggle_pos3_lower, 2, 3, 13, 14 ) - self.toggle_pos3_lower.show() - - self.toggle_pos5_lower = gtk.ToggleButton("--") - self.toggle_label = self.toggle_pos5_lower.get_child() - self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_pos5_lower.connect("toggled", self.toggle_pos5_lower_callback) - self.display.settings_table.attach(self.toggle_pos5_lower, 4, 5, 13, 14 ) - self.toggle_pos5_lower.show() - - self.label0 = gtk.Label("0") - self.label0.modify_font(pango.FontDescription("sans 12")) - self.display.settings_table.attach(self.label0, 0, 1, 10, 11 ) - self.label0.show() - - 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.label02 = gtk.Label("0") - self.label02.modify_font(pango.FontDescription("sans 12")) - self.display.settings_table.attach(self.label02, 2, 3, 10, 11 ) - self.label02.show() - - self.label_equal = gtk.Label("=") - self.label_equal.modify_font(pango.FontDescription("sans 12")) - self.display.settings_table.attach(self.label_equal, 3, 4, 10, 11 ) - self.label_equal.show() - - self.label0_lower = gtk.Label("0") - self.label0_lower.modify_font(pango.FontDescription("sans 12")) - self.display.settings_table.attach(self.label0_lower, 0, 1, 12, 13 ) - self.label0_lower.show() - - self.label_equal_lower = gtk.Label("=") - self.label_equal_lower.modify_font(pango.FontDescription("sans 12")) - self.display.settings_table.attach(self.label_equal_lower, 1, 2, 12, 13 ) - self.label_equal_lower.show() - - self.label02_lower = gtk.Label("0") - self.label02_lower.modify_font(pango.FontDescription("sans 12")) - self.display.settings_table.attach(self.label02_lower, 2, 3, 12, 13 ) - self.label02_lower.show() - - self.label_plus_minus_lower = gtk.Label("+") - self.label_plus_minus_lower.modify_font(pango.FontDescription("sans 12")) - self.display.settings_table.attach(self.label_plus_minus_lower, 3, 4, 12, 13 ) - self.label_plus_minus_lower.show() - - self.label03_lower = gtk.Label("0") - self.label03_lower.modify_font(pango.FontDescription("sans 12")) - self.display.settings_table.attach(self.label03_lower, 4, 5, 12, 13 ) - self.label03_lower.show() - - # Buttons 9 .. 0 - self.number_butts = [] - for i in range(0,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, 4, 5, 10-i, 11-i) - self.toggle.show() - self.number_butts.append(self.toggle) - - def set_buttons(self, sett): - - for i in range(sett['min'],sett['max']+1): - self.number_butts[i].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['shuffle'] == True ): - self.toggle_shuffle.set_active(True) - else: - self.toggle_shuffle.set_active(False) - - if ( sett['_+_=_'] == True ): - self.toggle_equal_fixed_right.set_active(True) - else: - self.toggle_equal_fixed_right.set_active(False) - - if ( sett['_=_+_'] == True ): - self.toggle_equal_fixed_left.set_active(True) - else: - self.toggle_equal_fixed_left.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) - - for i in sett['=input']: - if( i == 1 ): - self.toggle_pos1_lower.set_active(True) - if ( i == 3 ): - self.toggle_pos3_lower.set_active(True) - if ( i == 5 ): - self.toggle_pos5_lower.set_active(True) - - #**** callbacks ******************************************************** - - 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) - - # callbacks updating the settings - 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_shuffle_callback(self, widget): - if widget.get_active(): - self.display._sett['shuffle'] = True - else: - self.display._sett['shuffle'] = False - - def toggle_equal_fixed_right_callback(self, widget): - if widget.get_active(): - self.display._sett['_+_=_'] = True - self.toggle_pos1.set_active(True) - self.toggle_pos3.set_active(True) - self.toggle_pos5.set_active(True) - else: - if( self.toggle_equal_fixed_left.get_active() ): - self.display._sett['_+_=_'] = False - self.toggle_pos1.set_active(False) - self.toggle_pos3.set_active(False) - self.toggle_pos5.set_active(False) - else: - widget.set_active(True) - - def toggle_equal_fixed_left_callback(self, widget): - if widget.get_active(): - self.display._sett['_=_+_'] = True - self.toggle_pos1_lower.set_active(True) - self.toggle_pos3_lower.set_active(True) - self.toggle_pos5_lower.set_active(True) - else: - if( self.toggle_equal_fixed_right.get_active() ): - self.display._sett['_=_+_'] = False - self.toggle_pos1_lower.set_active(False) - self.toggle_pos3_lower.set_active(False) - self.toggle_pos5_lower.set_active(False) - else: - widget.set_active(True) - - def toggle_pos1_callback(self, widget): - - if( self.toggle_equal_fixed_right.get_active() ): - pass - else: - self.toggle_pos1.set_active(False) - - if( self.toggle_pos1.get_active() ): - self.display._sett['input='] = list(set(self.display._sett['input=']) | set([1])) - else: - if( self.toggle_equal_fixed_right.get_active() ): - if( not self.toggle_pos3.get_active() and not self.toggle_pos5.get_active() ): - self.toggle_pos1.set_active(True) - else: - self.display._sett['input='] = list(set(self.display._sett['input=']) - set([1])) - - def toggle_pos3_callback(self, widget): - if( self.toggle_equal_fixed_right.get_active() ): - pass - else: - self.toggle_pos3.set_active(False) - - if( self.toggle_pos3.get_active() ): - self.display._sett['input='] = list(set(self.display._sett['input=']) | set([3])) - else: - if( self.toggle_equal_fixed_right.get_active() ): - if( not self.toggle_pos1.get_active() and not self.toggle_pos5.get_active() ): - self.toggle_pos3.set_active(True) - else: - self.display._sett['input='] = list(set(self.display._sett['input=']) - set([3])) - - def toggle_pos5_callback(self, widget): - if( self.toggle_equal_fixed_right.get_active() ): - pass - else: - self.toggle_pos5.set_active(False) - - if( self.toggle_pos5.get_active() ): - self.display._sett['input='] = list(set(self.display._sett['input=']) | set([5])) - else: - if( self.toggle_equal_fixed_right.get_active() ): - if( not self.toggle_pos1.get_active() and not self.toggle_pos3.get_active() ): - self.toggle_pos5.set_active(True) - else: - self.display._sett['input='] = list(set(self.display._sett['input=']) - set([5])) - - def toggle_pos1_lower_callback(self, widget): - - if( self.toggle_equal_fixed_left.get_active() ): - pass - else: - self.toggle_pos1_lower.set_active(False) - - if( self.toggle_pos1_lower.get_active() ): - self.display._sett['=input'] = list(set(self.display._sett['=input']) | set([1])) - else: - if( self.toggle_equal_fixed_left.get_active() ): - if( not self.toggle_pos3_lower.get_active() and not self.toggle_pos5_lower.get_active() ): - self.toggle_pos1_lower.set_active(True) - else: - self.display._sett['=input'] = list(set(self.display._sett['=input']) - set([1])) - - def toggle_pos3_lower_callback(self, widget): - if( self.toggle_equal_fixed_left.get_active() ): - pass - else: - self.toggle_pos3_lower.set_active(False) - - if( self.toggle_pos3_lower.get_active() ): - self.display._sett['=input'] = list(set(self.display._sett['=input']) | set([3])) - else: - if( self.toggle_equal_fixed_left.get_active() ): - if( not self.toggle_pos1_lower.get_active() and not self.toggle_pos5_lower.get_active() ): - self.toggle_pos3_lower.set_active(True) - else: - self.display._sett['=input'] = list(set(self.display._sett['=input']) - set([3])) - - def toggle_pos5_lower_callback(self, widget): - if( self.toggle_equal_fixed_left.get_active() ): - pass - else: - self.toggle_pos5_lower.set_active(False) - - if( self.toggle_pos5_lower.get_active() ): - self.display._sett['=input'] = list(set(self.display._sett['=input']) | set([5])) - else: - if( self.toggle_equal_fixed_left.get_active() ): - if( not self.toggle_pos1_lower.get_active() and not self.toggle_pos3_lower.get_active()): - self.toggle_pos5_lower.set_active(True) - else: - self.display._sett['=input'] = list(set(self.display._sett['=input']) - set([5])) - - ##### end of public methods ############################################ - def _alladd(self, min, max): - """generate all calcs for +""" - _adds = [] - for _i in range(min, max +1): - for _j in range(0, _i +1): - #print("in Generate._alladd i= ",_i," j= ", _j) - _c = [to_str_99(_j),'+',to_str_99(_i-_j),'=',to_str_99(_i)] - _c = flatten(_c) - _c = strip(_c, '#') - _adds.append(_c) - #print("in Generate._alladd adds= ", _adds) - return _adds - - def _allsub(self, min, max): - """generate all calcs for -""" - _subs = [] - for _i in range(min, max +1): - for _j in range(0, _i +1) : - #print ("in Generate._allsub i= ",_i," j= ", _j) - _c = [to_str_99(_i), '-', to_str_99(_j), '=', to_str_99(_i - _j)] - _c = flatten(_c) - _c = strip(_c, '#') - _subs.append(_c) - return _subs - diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/addsubsimp.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/addsubsimp.pyc Binary files differdeleted file mode 100755 index 158b555..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/addsubsimp.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/coach.py b/ReckonPrimer.activity/ReckonPrimer.activity/coach.py deleted file mode 100755 index 9b3c159..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/coach.py +++ /dev/null @@ -1,104 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -import pprint -import pickle -from settings import Settings -from display import Display -from Exercise import Exercise -from addsubsimp import AddSubSimp -from passten import PassTen -from timesdiv import TimesDiv - -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") - - 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 - - def register(self, sess, dis): - self._sess = sess - self._dis = dis - - 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 = AddSubSimp(self._dis) - _ex2 = PassTen(self._dis) - _ex3 = TimesDiv(self._dis) - 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 - - # this version will go to VS on Apr.27: get setts from file - # def get_setting(self): - # print("in Coach.get_setting") - # TODO coach selects an exercise - # self._key = 'addsub_simp' - #TODO relate key to sett of exercise - # _sett = self._setts.load_last_sett(self._key) - # print("in Coach.get_setting, key=, sett=", self._key, _sett) - # self._dis.show_setting(self._key, _sett) - # sett returned from Display by Session.notify - # + toggle Settings.get_setting - Coach.notify - # for testing passten: get setts from default_* - # WN090624 def get_setting(self): - - def request_exercise(self): - print("in Coach.get_setting") - # WN090624 self._dis.offer_topics(['addsub_simp', - # 'passten', 'times_div']) - self._dis.offer_topics([t.get_topic() for t in self._exs]) - # calls back with notify('setting-done'... - - def notify(self, (msg, data)): - """called by the observed objects""" - - print("in Coach.notify: msg=, data=", (msg, data)) - if msg == 'setting-done': - # + self._setts.save_last_sett(self._key, data) - # WN090624 self._sess.notify((msg, data)) - self._ex.update_setting(data) - self._update_exs(self._ex) - self._sess.notify((msg, self._ex)) - elif msg == 'new-topic': - # WN090624 self._key, _sett = self._setts.get_setting(data) - # WN090624 self._dis.offer_setting(self._key, _sett) - # WN090624 new... - self._ex = self.get_ex(data) - self._dis.offer_setting(self._ex) - - def get_ex(self, tpc): - """Get an example by topic. TODO get by ID if exs are stored on disk. - """ - - for _t in self._exs: - if _t.get_topic() == tpc: - return _t diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/coach.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/coach.pyc Binary files differdeleted file mode 100755 index 496beca..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/coach.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/coach.py~ b/ReckonPrimer.activity/ReckonPrimer.activity/coach.py~ deleted file mode 100755 index 369b0b5..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/coach.py~ +++ /dev/null @@ -1,104 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -import pprint -import pickle -from settings import Settings -from display import Display -from Exercise import Exercise -from addsubsimp import AddSubSimp -from PassTen import PassTen -from TimesDiv import TimesDiv - -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") - - 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 - - def register(self, sess, dis): - self._sess = sess - self._dis = dis - - 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 = AddSubSimp(self._dis) - _ex2 = PassTen(self._dis) - _ex3 = TimesDiv(self._dis) - 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 - - # this version will go to VS on Apr.27: get setts from file - # def get_setting(self): - # print("in Coach.get_setting") - # TODO coach selects an exercise - # self._key = 'addsub_simp' - #TODO relate key to sett of exercise - # _sett = self._setts.load_last_sett(self._key) - # print("in Coach.get_setting, key=, sett=", self._key, _sett) - # self._dis.show_setting(self._key, _sett) - # sett returned from Display by Session.notify - # + toggle Settings.get_setting - Coach.notify - # for testing passten: get setts from default_* - # WN090624 def get_setting(self): - - def request_exercise(self): - print("in Coach.get_setting") - # WN090624 self._dis.offer_topics(['addsub_simp', - # 'passten', 'times_div']) - self._dis.offer_topics([t.get_topic() for t in self._exs]) - # calls back with notify('setting-done'... - - def notify(self, (msg, data)): - """called by the observed objects""" - - print("in Coach.notify: msg=, data=", (msg, data)) - if msg == 'setting-done': - # + self._setts.save_last_sett(self._key, data) - # WN090624 self._sess.notify((msg, data)) - self._ex.update_setting(data) - self._update_exs(self._ex) - self._sess.notify((msg, self._ex)) - elif msg == 'new-topic': - # WN090624 self._key, _sett = self._setts.get_setting(data) - # WN090624 self._dis.offer_setting(self._key, _sett) - # WN090624 new... - self._ex = self.get_ex(data) - self._dis.offer_setting(self._ex) - - def get_ex(self, tpc): - """Get an example by topic. TODO get by ID if exs are stored on disk. - """ - - for _t in self._exs: - if _t.get_topic() == tpc: - return _t diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/display-NOGUI.py b/ReckonPrimer.activity/ReckonPrimer.activity/display-NOGUI.py deleted file mode 100755 index 357576f..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/display-NOGUI.py +++ /dev/null @@ -1,114 +0,0 @@ -# -*- coding: UTF8 -*-
-# Display-NOGUI.py !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-from functions import contain, collect_digits, make_line, make_input
-from functions import make_line_remainder, make_input_remainder
-
-class Display:
- """.. all gui-elements of ReckonPrimer"""
- print("DEL import Display")
-
-
- def __init__(self, window):
- pass #see sequence of creation in Session
-
- def register(self, sess, co):
- self._sess = sess
- self._co = co
-
- def init_calc(self):
- """prepares for calculations from 1 setting.
- for instance, a calculation might be on 1 ore more lines.
- """
- print("in Display.init_calc")
- pass
-
- # different with GUI
- #WN090624 def show_setting(self, key, sett):
- #WN090624 def offer_setting(self, key, sett):
- def offer_setting(self, ex):
- #WN090624 self._sett = sett
- #WN090624 self._key = key
- self._sett = ex.get_setting()
- self._key = ex.get_topic()
- print('in Display.offer_setting: key=,sett=',self._key,self._sett)
- input('in Display.show_setting: Start-Button #')
- self._co.notify(('setting-done', self._sett))
-
- def notify(self, (msg, data)):
- """only used by gtk"""
- if msg == 'digit-done':
- self._sess.notify(('digit-done', None)) #WN090624
- #if len(self._input) > 0:
- # self._curr_in = self._input.pop()
- # self.create_entryline(self._curr_in)
- #else:
- # self._sess.notify(('calc-done', None))
-
-
-
- def show_calc (self, calc):
- """start calc: format calc for display and input, input first digit"""
- #TODO: warum ist calc ein Argument _und_ self. ? ENTWEDER..ODER !
- #TODO: warum ist _key kein Argument ? ENTWEDER..ODER !
- print('in Display.show_calc: calc=',calc)
- if(self._key == 'addsub_simp'):
- _lines, self._input = self.format_addsub_simp(calc)
- elif(self._key == 'passten'):
- _lines, self._input = self.format_passten(calc)
- elif(self._key == 'times_div'):
- _lines, self._input = self.format_times_div(calc)
- else:
- print('in Display.show_calc: ERROR no key=', self._key)
- #TODO: exit (programmer mode!)
- self.display_calc(_lines)
- self._curr_in = self._input.pop() #need _curr_in in notify
- self.create_entryline(self._curr_in)
- # create_entryline sets the callback from gtk
-
- def display_calc(self, lines):
- """display the lines of a calc with _ at all input positions"""
- for l in lines:
- print('in Display.display_calc, line=', l) #@
- pass
-
- #OLD show_calc_addsub_simp(self, calc):
- def create_entryline(self,(lineno, linepos, dig, prot_err, prot_ok, line)):
- """create gtk.Entry in line at linepos and set callback_input_digit"""
- calculation, cursor = line, linepos
- #print('in Display.create_entryline:l=', line) #@
- self.input_digit('widget', dig, prot_err, prot_ok)
-
-
- def input_digit(self, widget, dig, prot_err, prot_ok):
- """input a digit and give feedback.
- The _only_ other active widget is the <stop>-button on the right"""
- print('in Display.input_digit: dig=', dig, ', prot_err=', prot_err) #@
- #_dig = input('in Display.input_digit: dig= ')
- #while str(_dig) != dig:
- # _dig = input('in Display.input_digit: dig= ')
- self.notify(('digit-done', None))
-
-
- def finish_calc(self):
- #WN090518 needed ???
- pass
-
- def offer_topics(self, topics):
- """TODO: get the users choice from buttons above the settings"""
- _i = 0
- for _t in topics:
- _i = _i + 1
- print('in Display.offer_topics: ' + _t + '....' + str(_i))
- #TODO: make that a callback...
- self.new_topic(topics)
-
- #TODO: make that a callback...
- def new_topic(self, topics):
- """TODO: get the users choice from buttons above the settings"""
- _choice = int(input('in Display.new_topic: ...............?'))
- while _choice < 1 and 3 < _choice:
- _choice = int(input('in Display.new_topic: ...............?'))
- self._co.notify(('new-topic', topics[_choice - 1]))
-
-
diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/display.py b/ReckonPrimer.activity/ReckonPrimer.activity/display.py deleted file mode 100755 index 30fd773..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/display.py +++ /dev/null @@ -1,451 +0,0 @@ -#! -*- coding: utf-8 -*- -#(c) Stefan Heher 2009 -#1234567890123456789012345678901234567890123456789012345678901234567890123456789 -import gtk -import pygtk -import pango -import time -import gobject -from sugar.activity import activity -from functions import * -from settings import Settings -from timer import Timer -from Exercise import * -from sugar import profile -from sugar.graphics import style - - - -class Display: - """ - Definition and manipulation of all GUI-elemts. - Exception (redesign?): def define_buttons in classes derived from Exercise. - """ - print("DEL import Display") - - def __init__(self, window): - self.errors = 0 - self._sett = None # setting updated by callbacks during input - self.running = False # first round of calculations - - self.active_topic = None - - - # ----- all permanent GUI-elements ----- TODO separate def - # Save the sugar main window - self.main_window = window - - # Create a table consisting of 4 possible entries - self.table = gtk.Table(5, 2, True) - - # Put the table in the main window - self.main_window.set_canvas(self.table) - - # Create the log_buffer - self.log_buffer = gtk.TextBuffer() - - # Create a tag table from the buffer - self.tag_table = self.log_buffer.get_tag_table() - - # Create a tag for errors - self.error_tag = gtk.TextTag("error") - self.error_tag.set_property("foreground", "blue") - self.tag_table.add(self.error_tag) - - # Create a tag for correct calculations - self.correct_tag = gtk.TextTag("correct") - self.correct_tag.set_property("foreground", "green") - self.tag_table.add(self.correct_tag) - - - # Create a log_view with the previously created log_buffer - self.log_view = gtk.TextView(self.log_buffer) - - # Set the font size for the log_view - self.log_view.modify_font(pango.FontDescription('sans bold 14')) - - # Set the log_view to not editable - self.log_view.set_editable(False) - - # Set the cursor to not visible - self.log_view.set_cursor_visible(False) - - # Set the justification to center - self.log_view.set_justification(gtk.JUSTIFY_CENTER) - - # Create a scrollable window for the log_view - self.scrolled_window = gtk.ScrolledWindow() - - # Set scrollable window policies - self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - - # Connect log_view and scrolled window - self.scrolled_window.add(self.log_view) - - # Insert the log_view into the upper half - self.table.attach(self.scrolled_window, 0, 1, 0, 3) - - # Display the log_view - self.log_view.show() - - # Display the scrolled_window - self.scrolled_window.show() - - # Settings start here - self.settings_table = gtk.Table(15, 6, True) - - # Topic table - self.topic_table = gtk.Table(15, 6, True) - - # Separate table for start button - self.table_with_start = gtk.Table(15, 6, True) - - # Insert the settings window into the right half of the screen - self.table.attach(self.settings_table, 1, 2, 0, 5) - - # Insert the topic window into the right half of the screen - self.table.attach(self.topic_table, 1, 2, 0, 5) - - # Insert the table for start button into the right half of the screen - self.table.attach(self.table_with_start, 1, 2, 0, 5) - - # Display the settings_table - self.settings_table.show() - - # Disply the topic table - self.topic_table.show() - - # Display the table_with_start - self.table_with_start.show() - - # Display the table - self.table.show() - - def register(self, sess, co): - """register _after_ Session and Coach have been instantiated""" - self._sess = sess - self._co = co - - def update_time(self): - minutes, seconds = divmod(self.stopwatch.elapsed, 60) - if(minutes < 10 and seconds < 10): - time = "0" + str(int(minutes)) + ":" + "0" + str(int(seconds)) - if(minutes > 9 and seconds > 9): - time = str(int(minutes)) + ":" + str(int(seconds)) - if(minutes > 9 and seconds < 10): - time = str(int(minutes)) + ":" + "0" + str(int(seconds)) - if(minutes < 10 and seconds > 10): - time = "0" + str(int(minutes)) + ":" + str(int(seconds)) - self.stopwatch_label.set_label(time) - self.stopwatch_label.queue_draw() - return True - - - - def draw_result_screen(self): - - # Section for stopwatch - self.stopwatch = Timer() - self.stopwatch_label = gtk.Label("00:00") - self.stopwatch_label.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.stopwatch_label, 3, 5, 12, 13) - - # Section for nickname - self.name = profile.get_nick_name() - self.name_label = gtk.Label(self.name) - self.name_label.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.name_label, 0, 6, 13, 14) - - # Section for progress bar - self.progressbar = gtk.ProgressBar(adjustment=None) - - # Color for progress bar - style = self.progressbar.get_style() - style.bg[gtk.STATE_PRELIGHT] = gtk.gdk.color_parse("green") - self.progressbar.set_style (style) - self.progressbar.set_fraction(0) - self.table_with_start.attach(self.progressbar, 0, 6, 8, 9) - - # Labels for progress bar - self.progress0 = gtk.Label("0") - self.progress0.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.progress0, 0, 1, 9, 10 ) - - # Labels for status update - self.correct_count = 0 - self.correct_counter = gtk.Label(str(self.correct_count)) - self.correct_counter.modify_font(pango.FontDescription("sans 16")) - - - # Ugly code for label color - attr = pango.AttrList() - fg_color = pango.AttrForeground(0, 65535, 0, 0, 6) - attr.insert(fg_color) - self.correct_counter.set_attributes(attr) - - self.table_with_start.attach(self.correct_counter, 2, 4, 9, 10 ) - - self.false_count = 0 - self.false_counter = gtk.Label(str(self.false_count)) - self.false_counter.modify_font(pango.FontDescription("sans 16")) - - # Ugly code for label color - attr = pango.AttrList() - fg_color = pango.AttrForeground(0, 0, 65535, 0, 6) - attr.insert(fg_color) - self.false_counter.set_attributes(attr) - - self.table_with_start.attach(self.false_counter, 2, 4, 10, 11 ) - - self.stopwatch_label.show() - gobject.timeout_add(1000, self.update_time) - self.name_label.show() - self.progressbar.show() - self.progress0.show() - self.correct_counter.show() - self.false_counter.show() - - self.total_calcs = self._ex.count() - self.progress_total = gtk.Label(str(self.total_calcs)) - self.progress_total.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.progress_total, 5, 6, 9, 10 ) - self.progress_total.show() - - def hide_result_screen(self): - self.progressbar.set_fraction(0) - self.stopwatch_label.hide() - self.name_label.hide() - self.progressbar.hide() - self.progress0.hide() - self.correct_counter.hide() - self.false_counter.hide() - self.progress_total.hide() - - def offer_setting(self,ex): - self._ex = ex - self._sett = self._ex.get_setting() - - ### START BUTTON BEGIN ### - self.start_button = gtk.Button(None, gtk.STOCK_GO_FORWARD) - self.start_button.connect("clicked", self.clicked_start_callback) - self.table_with_start.attach(self.start_button, 0, 6, 14, 15) - self.start_alignment = self.start_button.get_children()[0] - self.start_hbox = self.start_alignment.get_children()[0] - self.start_image, self.start_label = self.start_hbox.get_children() - self.start_label.set_label("") - self.start_button.show() - ### START BUTTON END ### - - - ### NEW ### - self.current_exercise = ex - self.current_exercise.define_buttons() - self.current_exercise.set_buttons(self._sett) - ### NEW ### - - def clicked_start_callback(self, widget): - - if( self.running == False): - - self.running = True - self.start_button.set_label(gtk.STOCK_STOP) - self.start_alignment = self.start_button.get_children()[0] - self.start_hbox = self.start_alignment.get_children()[0] - self.start_image, self.start_label = self.start_hbox.get_children() - self.start_label.set_label("") - self._co.notify(('setting-done', self._sett)) - self.settings_table.hide() - self.topic_table.hide() - - self.draw_result_screen() - - elif( self.running == True): - - self.protocol('----------------------------------------', 0, 'OK') - self.running = False - self.start_button.set_label(gtk.STOCK_GO_FORWARD) - self.start_alignment = self.start_button.get_children()[0] - self.start_hbox = self.start_alignment.get_children()[0] - self.start_image, self.start_label = self.start_hbox.get_children() - self.start_label.set_label("") - self.display_table.destroy() - self.hide_result_screen() - self.settings_table.show() - self.topic_table.show() - - def init_calc(self): - """ - prepares for calculations from 1 setting. - for instance, a calculation might be on 1 ore more lines. - """ - print("DEL do Display.init_calc") - # make empty lines such that all calcs are entered at bottom - for i in range(1,21): - end_iterator = self.log_buffer.get_end_iter() - self.log_buffer.insert(end_iterator, "\n") - self.log_view.scroll_mark_onscreen(self.log_buffer.get_insert()) - - - - - def destroy_box(self): - self.calculation_box.destroy() - - def protocol(self, full_line, errors, feedback): - end_iterator = self.log_buffer.get_end_iter() - - if( feedback == 'OK' ): - self.log_buffer.insert_with_tags_by_name(end_iterator, "\n" + full_line, "correct" ) - elif ( feedback == 'XXX' ): - self.log_buffer.insert_with_tags_by_name(end_iterator, "\n" + full_line, "error" ) - end_iterator = self.log_buffer.get_end_iter() - mark = self.log_buffer.create_mark(None, end_iterator, True) - self.log_view.scroll_mark_onscreen(mark) - - def dis_calc(self, clist, cursor, errs): - _i, _calc = 0, '' - for _c in clist: - _i = _i + 1 - if (_i == cursor) & (errs > 0): - _calc = _calc + '_' - else: - _calc = _calc + _c - return _calc + ' ' + errs * '/' - - def input_digit(self, widget, dig, proterr, protok): - """input a digit and give feedback. - The _only_ other active widget is the <stop>-button on the right""" - entry_text = widget.get_text() - ### bitte anzeigen !??????? - if(entry_text == dig): - - self.errors = 0 #WN090518 ??? - self.protocol(protok, self.errors, 'OK') - self.destroy_box() - self.notify(('digit-done', None)) - elif(entry_text == ""): - pass #otherwise feedback in protocol written twice: see entry.set_text("") below - else: - self.false_count = self.false_count + 1 - self.false_counter.set_text(str(self.false_count)) - self.errors = self.errors + 1 - widget.set_text("") - self.protocol(proterr, self.errors, 'XXX') - - - #WN090518 - def display_calc(self, lines): - - self.display_table = gtk.Table(5, 1, True) - self.table.attach(self.display_table, 0, 1, 0, 5) - self.display_table.show() - - """display the lines of a calc with _ at all input positions""" - lino = 0 - for li in lines: - print('in Display.display_calc, line=', li) - self.create_entryline((lino, -1, 'dummy-dig', 'dummy-proterr', 'dummy-protok', li)) - lino = lino + 1 - - - def create_entryline(self, (lineno, linepos, dig, proterr, protok, line)): - """create gtk.Entry in line at linepos and set callback_input_digit""" - print('in Display.create_entryline: lineno=', lineno, ', linepos=', - linepos, ', line=', line) - calculation, cursor = line, linepos - self.calculation_box = gtk.HBox(True, 0) - calc_pos = 0 - self.display_table.attach(self.calculation_box, 0, 1, 3 + lineno, 4 + lineno) - for i in calculation: - if (calc_pos != cursor): - self.label = gtk.Label(i) - self.label.modify_font(pango.FontDescription("sans 24")) - self.calculation_box.pack_start(self.label) - self.label.show() - else: # prepare for input - self.text_entry = gtk.Entry(max = 1) - self.text_entry.modify_font(pango.FontDescription("sans 24")) - self.text_entry.connect("changed", self.input_digit, dig, proterr, protok) - self.calculation_box.pack_start(self.text_entry) - self.text_entry.show() - calc_pos = calc_pos + 1 - #?kann m.die calculation_box ZUERST aufbauen und DANN self.table.attach - self.calculation_box.show() - - if(cursor != -1): - self.text_entry.grab_focus() - #just add lineno to table.attach - #TODO rename calculation, cursor below ... - #TODO remove hack on callback: - #self.input_digit('widget', dig, protline) - - - def finish_calc(self): - self.stopwatch.stop() - - - def notify(self, msg): - """only used by gtk""" - if msg[0] == 'digit-done': - self._sess.notify(('digit-done', None)) - - def show_progress(self): - self.progressbar.set_fraction(self.progressbar.get_fraction()+(float(1)/float(self.total_calcs))) - self.correct_count = self.correct_count + 1 - self.correct_counter.set_text(str(self.correct_count)) - self.display_table.destroy() - - - def offer_topics(self, topics): - """TODO: get the users choice from buttons above the settings""" - self.topic_box = gtk.HBox(True, 0) - self.topic_table.attach(self.topic_box, 0, 6, 0, 1) - - _i = 0 - for _t in topics: - _i = _i + 1 - 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.new_topic, _t) - self.topic_box.pack_start(self.button) - self.button.show() - - self.topic_box.show() - - - def new_topic(self, widget, topic): - """TODO: get the users choice from buttons above the settings""" - - if(self.active_topic == None): - self.active_topic = topic - self._co.notify(('new-topic', topic)) - - elif(self.active_topic == topic): - pass - - elif(self.active_topic != topic): - self.active_topic = topic - self.settings_table.destroy() - self.settings_table = gtk.Table(15, 6, True) - self.table.attach(self.settings_table, 1, 2, 0, 5) - self.settings_table.show() - - self.table_with_start.destroy() - self.table_with_start = gtk.Table(15, 6, True) - self.table.attach(self.table_with_start, 1, 2, 0, 5) - self.table_with_start.show() - self._co.notify(('new-topic', topic)) - - - - - diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/display.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/display.pyc Binary files differdeleted file mode 100755 index 84cb0ac..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/display.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/display.py~ b/ReckonPrimer.activity/ReckonPrimer.activity/display.py~ deleted file mode 100755 index 3c39316..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/display.py~ +++ /dev/null @@ -1,451 +0,0 @@ -#! -*- coding: utf-8 -*- -#(c) Stefan Heher 2009 -#1234567890123456789012345678901234567890123456789012345678901234567890123456789 -import gtk -import pygtk -import pango -import time -import gobject -from sugar.activity import activity -from functions import * -from settings import Settings -from Timer import Timer -from Exercise import * -from sugar import profile -from sugar.graphics import style - - - -class Display: - """ - Definition and manipulation of all GUI-elemts. - Exception (redesign?): def define_buttons in classes derived from Exercise. - """ - print("DEL import Display") - - def __init__(self, window): - self.errors = 0 - self._sett = None # setting updated by callbacks during input - self.running = False # first round of calculations - - self.active_topic = None - - - # ----- all permanent GUI-elements ----- TODO separate def - # Save the sugar main window - self.main_window = window - - # Create a table consisting of 4 possible entries - self.table = gtk.Table(5, 2, True) - - # Put the table in the main window - self.main_window.set_canvas(self.table) - - # Create the log_buffer - self.log_buffer = gtk.TextBuffer() - - # Create a tag table from the buffer - self.tag_table = self.log_buffer.get_tag_table() - - # Create a tag for errors - self.error_tag = gtk.TextTag("error") - self.error_tag.set_property("foreground", "blue") - self.tag_table.add(self.error_tag) - - # Create a tag for correct calculations - self.correct_tag = gtk.TextTag("correct") - self.correct_tag.set_property("foreground", "green") - self.tag_table.add(self.correct_tag) - - - # Create a log_view with the previously created log_buffer - self.log_view = gtk.TextView(self.log_buffer) - - # Set the font size for the log_view - self.log_view.modify_font(pango.FontDescription('sans bold 14')) - - # Set the log_view to not editable - self.log_view.set_editable(False) - - # Set the cursor to not visible - self.log_view.set_cursor_visible(False) - - # Set the justification to center - self.log_view.set_justification(gtk.JUSTIFY_CENTER) - - # Create a scrollable window for the log_view - self.scrolled_window = gtk.ScrolledWindow() - - # Set scrollable window policies - self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - - # Connect log_view and scrolled window - self.scrolled_window.add(self.log_view) - - # Insert the log_view into the upper half - self.table.attach(self.scrolled_window, 0, 1, 0, 3) - - # Display the log_view - self.log_view.show() - - # Display the scrolled_window - self.scrolled_window.show() - - # Settings start here - self.settings_table = gtk.Table(15, 6, True) - - # Topic table - self.topic_table = gtk.Table(15, 6, True) - - # Separate table for start button - self.table_with_start = gtk.Table(15, 6, True) - - # Insert the settings window into the right half of the screen - self.table.attach(self.settings_table, 1, 2, 0, 5) - - # Insert the topic window into the right half of the screen - self.table.attach(self.topic_table, 1, 2, 0, 5) - - # Insert the table for start button into the right half of the screen - self.table.attach(self.table_with_start, 1, 2, 0, 5) - - # Display the settings_table - self.settings_table.show() - - # Disply the topic table - self.topic_table.show() - - # Display the table_with_start - self.table_with_start.show() - - # Display the table - self.table.show() - - def register(self, sess, co): - """register _after_ Session and Coach have been instantiated""" - self._sess = sess - self._co = co - - def update_time(self): - minutes, seconds = divmod(self.stopwatch.elapsed, 60) - if(minutes < 10 and seconds < 10): - time = "0" + str(int(minutes)) + ":" + "0" + str(int(seconds)) - if(minutes > 9 and seconds > 9): - time = str(int(minutes)) + ":" + str(int(seconds)) - if(minutes > 9 and seconds < 10): - time = str(int(minutes)) + ":" + "0" + str(int(seconds)) - if(minutes < 10 and seconds > 10): - time = "0" + str(int(minutes)) + ":" + str(int(seconds)) - self.stopwatch_label.set_label(time) - self.stopwatch_label.queue_draw() - return True - - - - def draw_result_screen(self): - - # Section for stopwatch - self.stopwatch = Timer() - self.stopwatch_label = gtk.Label("00:00") - self.stopwatch_label.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.stopwatch_label, 3, 5, 12, 13) - - # Section for nickname - self.name = profile.get_nick_name() - self.name_label = gtk.Label(self.name) - self.name_label.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.name_label, 0, 6, 13, 14) - - # Section for progress bar - self.progressbar = gtk.ProgressBar(adjustment=None) - - # Color for progress bar - style = self.progressbar.get_style() - style.bg[gtk.STATE_PRELIGHT] = gtk.gdk.color_parse("green") - self.progressbar.set_style (style) - self.progressbar.set_fraction(0) - self.table_with_start.attach(self.progressbar, 0, 6, 8, 9) - - # Labels for progress bar - self.progress0 = gtk.Label("0") - self.progress0.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.progress0, 0, 1, 9, 10 ) - - # Labels for status update - self.correct_count = 0 - self.correct_counter = gtk.Label(str(self.correct_count)) - self.correct_counter.modify_font(pango.FontDescription("sans 16")) - - - # Ugly code for label color - attr = pango.AttrList() - fg_color = pango.AttrForeground(0, 65535, 0, 0, 6) - attr.insert(fg_color) - self.correct_counter.set_attributes(attr) - - self.table_with_start.attach(self.correct_counter, 2, 4, 9, 10 ) - - self.false_count = 0 - self.false_counter = gtk.Label(str(self.false_count)) - self.false_counter.modify_font(pango.FontDescription("sans 16")) - - # Ugly code for label color - attr = pango.AttrList() - fg_color = pango.AttrForeground(0, 0, 65535, 0, 6) - attr.insert(fg_color) - self.false_counter.set_attributes(attr) - - self.table_with_start.attach(self.false_counter, 2, 4, 10, 11 ) - - self.stopwatch_label.show() - gobject.timeout_add(1000, self.update_time) - self.name_label.show() - self.progressbar.show() - self.progress0.show() - self.correct_counter.show() - self.false_counter.show() - - self.total_calcs = self._ex.count() - self.progress_total = gtk.Label(str(self.total_calcs)) - self.progress_total.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.progress_total, 5, 6, 9, 10 ) - self.progress_total.show() - - def hide_result_screen(self): - self.progressbar.set_fraction(0) - self.stopwatch_label.hide() - self.name_label.hide() - self.progressbar.hide() - self.progress0.hide() - self.correct_counter.hide() - self.false_counter.hide() - self.progress_total.hide() - - def offer_setting(self,ex): - self._ex = ex - self._sett = self._ex.get_setting() - - ### START BUTTON BEGIN ### - self.start_button = gtk.Button(None, gtk.STOCK_GO_FORWARD) - self.start_button.connect("clicked", self.clicked_start_callback) - self.table_with_start.attach(self.start_button, 0, 6, 14, 15) - self.start_alignment = self.start_button.get_children()[0] - self.start_hbox = self.start_alignment.get_children()[0] - self.start_image, self.start_label = self.start_hbox.get_children() - self.start_label.set_label("") - self.start_button.show() - ### START BUTTON END ### - - - ### NEW ### - self.current_exercise = ex - self.current_exercise.define_buttons() - self.current_exercise.set_buttons(self._sett) - ### NEW ### - - def clicked_start_callback(self, widget): - - if( self.running == False): - - self.running = True - self.start_button.set_label(gtk.STOCK_STOP) - self.start_alignment = self.start_button.get_children()[0] - self.start_hbox = self.start_alignment.get_children()[0] - self.start_image, self.start_label = self.start_hbox.get_children() - self.start_label.set_label("") - self._co.notify(('setting-done', self._sett)) - self.settings_table.hide() - self.topic_table.hide() - - self.draw_result_screen() - - elif( self.running == True): - - self.protocol('----------------------------------------', 0, 'OK') - self.running = False - self.start_button.set_label(gtk.STOCK_GO_FORWARD) - self.start_alignment = self.start_button.get_children()[0] - self.start_hbox = self.start_alignment.get_children()[0] - self.start_image, self.start_label = self.start_hbox.get_children() - self.start_label.set_label("") - self.display_table.destroy() - self.hide_result_screen() - self.settings_table.show() - self.topic_table.show() - - def init_calc(self): - """ - prepares for calculations from 1 setting. - for instance, a calculation might be on 1 ore more lines. - """ - print("DEL do Display.init_calc") - # make empty lines such that all calcs are entered at bottom - for i in range(1,21): - end_iterator = self.log_buffer.get_end_iter() - self.log_buffer.insert(end_iterator, "\n") - self.log_view.scroll_mark_onscreen(self.log_buffer.get_insert()) - - - - - def destroy_box(self): - self.calculation_box.destroy() - - def protocol(self, full_line, errors, feedback): - end_iterator = self.log_buffer.get_end_iter() - - if( feedback == 'OK' ): - self.log_buffer.insert_with_tags_by_name(end_iterator, "\n" + full_line, "correct" ) - elif ( feedback == 'XXX' ): - self.log_buffer.insert_with_tags_by_name(end_iterator, "\n" + full_line, "error" ) - end_iterator = self.log_buffer.get_end_iter() - mark = self.log_buffer.create_mark(None, end_iterator, True) - self.log_view.scroll_mark_onscreen(mark) - - def dis_calc(self, clist, cursor, errs): - _i, _calc = 0, '' - for _c in clist: - _i = _i + 1 - if (_i == cursor) & (errs > 0): - _calc = _calc + '_' - else: - _calc = _calc + _c - return _calc + ' ' + errs * '/' - - def input_digit(self, widget, dig, proterr, protok): - """input a digit and give feedback. - The _only_ other active widget is the <stop>-button on the right""" - entry_text = widget.get_text() - ### bitte anzeigen !??????? - if(entry_text == dig): - - self.errors = 0 #WN090518 ??? - self.protocol(protok, self.errors, 'OK') - self.destroy_box() - self.notify(('digit-done', None)) - elif(entry_text == ""): - pass #otherwise feedback in protocol written twice: see entry.set_text("") below - else: - self.false_count = self.false_count + 1 - self.false_counter.set_text(str(self.false_count)) - self.errors = self.errors + 1 - widget.set_text("") - self.protocol(proterr, self.errors, 'XXX') - - - #WN090518 - def display_calc(self, lines): - - self.display_table = gtk.Table(5, 1, True) - self.table.attach(self.display_table, 0, 1, 0, 5) - self.display_table.show() - - """display the lines of a calc with _ at all input positions""" - lino = 0 - for li in lines: - print('in Display.display_calc, line=', li) - self.create_entryline((lino, -1, 'dummy-dig', 'dummy-proterr', 'dummy-protok', li)) - lino = lino + 1 - - - def create_entryline(self, (lineno, linepos, dig, proterr, protok, line)): - """create gtk.Entry in line at linepos and set callback_input_digit""" - print('in Display.create_entryline: lineno=', lineno, ', linepos=', - linepos, ', line=', line) - calculation, cursor = line, linepos - self.calculation_box = gtk.HBox(True, 0) - calc_pos = 0 - self.display_table.attach(self.calculation_box, 0, 1, 3 + lineno, 4 + lineno) - for i in calculation: - if (calc_pos != cursor): - self.label = gtk.Label(i) - self.label.modify_font(pango.FontDescription("sans 24")) - self.calculation_box.pack_start(self.label) - self.label.show() - else: # prepare for input - self.text_entry = gtk.Entry(max = 1) - self.text_entry.modify_font(pango.FontDescription("sans 24")) - self.text_entry.connect("changed", self.input_digit, dig, proterr, protok) - self.calculation_box.pack_start(self.text_entry) - self.text_entry.show() - calc_pos = calc_pos + 1 - #?kann m.die calculation_box ZUERST aufbauen und DANN self.table.attach - self.calculation_box.show() - - if(cursor != -1): - self.text_entry.grab_focus() - #just add lineno to table.attach - #TODO rename calculation, cursor below ... - #TODO remove hack on callback: - #self.input_digit('widget', dig, protline) - - - def finish_calc(self): - self.stopwatch.stop() - - - def notify(self, msg): - """only used by gtk""" - if msg[0] == 'digit-done': - self._sess.notify(('digit-done', None)) - - def show_progress(self): - self.progressbar.set_fraction(self.progressbar.get_fraction()+(float(1)/float(self.total_calcs))) - self.correct_count = self.correct_count + 1 - self.correct_counter.set_text(str(self.correct_count)) - self.display_table.destroy() - - - def offer_topics(self, topics): - """TODO: get the users choice from buttons above the settings""" - self.topic_box = gtk.HBox(True, 0) - self.topic_table.attach(self.topic_box, 0, 6, 0, 1) - - _i = 0 - for _t in topics: - _i = _i + 1 - 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.new_topic, _t) - self.topic_box.pack_start(self.button) - self.button.show() - - self.topic_box.show() - - - def new_topic(self, widget, topic): - """TODO: get the users choice from buttons above the settings""" - - if(self.active_topic == None): - self.active_topic = topic - self._co.notify(('new-topic', topic)) - - elif(self.active_topic == topic): - pass - - elif(self.active_topic != topic): - self.active_topic = topic - self.settings_table.destroy() - self.settings_table = gtk.Table(15, 6, True) - self.table.attach(self.settings_table, 1, 2, 0, 5) - self.settings_table.show() - - self.table_with_start.destroy() - self.table_with_start = gtk.Table(15, 6, True) - self.table.attach(self.table_with_start, 1, 2, 0, 5) - self.table_with_start.show() - self._co.notify(('new-topic', topic)) - - - - - diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/functions.py b/ReckonPrimer.activity/ReckonPrimer.activity/functions.py deleted file mode 100755 index 8cc0c9e..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/functions.py +++ /dev/null @@ -1,323 +0,0 @@ -# -*- coding: UTF8 -*-
-"""the module for functions of reckonprimer.py.
-placed in reconprimer.py caused recursive import."""
-import copy
-def reverse_(list):
- """list.reverse() returns None; reverse_ returns the reversed list"""
- li = copy.deepcopy(list[3:5]) # make a copy
- li.reverse()
- del list[3:5]
- list = (li + list)
- return list
-
-def get_until(char, chars):
- _i, _chars = 0, []
- while chars[_i] != char:
- #print('in get_until, chars[', _i, ']=', chars[_i])
- _chars.append(chars[_i])
- _i = _i + 1
- return _chars
-
-def get_after(char, chars):
- _i, _chars, _max = 0, [], len(chars)
- while (chars[_i] != char) & (_i < _max):
- print('in get_after, chars[', _i, ']=', chars[_i])
- _i = _i + 1
- return chars[_i+1:]
-
-def extend_(chars1, chars2):
- _chars = copy.deepcopy(chars1) # make a copy
- _chars.extend(chars2)
- return _chars
-
-def swap_eq(chars):
- _i, _chars = 0, []
- while chars[_i] != '=':
- #print('in swap_eq chars[', _i, ']=', chars[_i])
- _chars.append(chars[_i])
- _i = _i + 1
- return extend_(extend_(chars[_i+1:], ['=']), _chars)
-
-#_c = ['2','+','3','=','5']
-#print('_c =', _c)
-#_c1 = get_until('=', _c)
-#print('get_until', _c1)
-#_c2 = get_after('=', _c)
-#print('get_after', _c2)
-#_c3 = extend_(_c1, _c2)
-#print('extend_ ', _c3)
-#_c4 = swap_eq(_c)
-#print('swap_eq ', _c4)
-
-def contain(chars, char):
- """do chars (list of characters) contain char ?"""
- if len(chars) > 0:
- for _c in chars:
- if _c == char:
- return True
- else:
- return False
- else:
- return False
-#chrs = ['2','+','3',\
-# '=','5']
-#print('contain([\'2\',\'+\',\'3\',\'=\',\'5\'], \'+\')', contain(chrs, '+'))
-#print('contain([\'2\',\'+\',\'3\',\'=\',\'5\'], \'-\')', contain(chrs, '-'))
-
-def make_blanks(n):
- """create a list of n blanks"""
- _l = []
- for i in range(0, n):
- _l.append(' ')
- return _l
-#xxx = make_blanks(3)
-#print(xxx)
-#xxx[1]='+'
-#print(xxx)
-
-#ls = [11,22,33]
-#[a,b,c] = ls
-#print('in functions: a=',a,', b=',b,', c=',c)
-def collect_digits(calc):
- """collect the digits of each number in a calc into a list"""
- _coll_calc, _i = [], 0
- while _i < len(calc):
- _coll_no = []
- while not(calc[_i] in ['=','+','-','*',':','in','|']):
- _coll_no.append(calc[_i])
- #print('in collect_digits: _coll_calc=',_coll_calc,', _i=',_i,\
- # ', _coll_no=',_coll_no)
- _i = _i+1
- if _i >= len(calc):
- _coll_calc.append(_coll_no)
- return _coll_calc
- _coll_calc.append(_coll_no)
- _coll_calc.append(calc[_i])
- _i = _i+1
-#cs = collect_digits(['1','2','+','3','4','=','4','6'])
-#print('in functions: cs=', cs)
-##('in functions: cs=', [['1', '2'], '+', ['3', '4'], '=', ['4', '6']])
-#cs = collect_digits(['1','+','2','=','3'])
-#print('in functions: cs=', cs)
-##('in functions: cs=', [['1'], '+', ['2'], '=', ['3']])
-
-def make_line(coll_calc, linepos):
- """make a calc (returned by collect_digits) to a line to display;
- linepos is 1 or 3 or 5."""
- _i, _line = 0, [' ']
- for _c in coll_calc:
- #print('in make_line: _c=', _c)
- if _i == linepos -1:
- for _d in _c:
- _line.append('_')
- else:
- for _d in _c:
- #print('in make_line: _d=', _d)
- if _d in ['=','+','-','*',':','in']:
- _line.extend([' ',_d,' '])
- else:
- _line.append(_d)
- _i = _i + 1
- _line.append(' ')
- return _line
-#coll_calc = [['1', '2'], '+', ['3', '4'], '=', ['4', '6']]
-#print('in functions: make_line(coll_calc, 1)=', make_line(coll_calc, 1))
-##[' ', '_', '_', ' ', '+', ' ', '3', '4', ' ', '=', ' ', '4', '6', ' ']
-#print('in functions: make_line(coll_calc, 3)=', make_line(coll_calc, 3))
-##[' ', '1', '2', ' ', '+', ' ', '_', '_', ' ', '=', ' ', '4', '6', ' ']
-#print('in functions: make_line(coll_calc, 5)=', make_line(coll_calc, 5))
-##[' ', '1', '2', ' ', '+', ' ', '3', '4', ' ', '=', ' ', '_', '_', ' ']
-#coll_calc = [['1'], '+', ['2'], '=', ['3']]
-#print('in functions: make_line(coll_calc, 1)=', make_line(coll_calc, 1))
-##[' ', '_', ' ', '+', ' ', '2', ' ', '=', ' ', '3', ' ']
-#print('in functions: make_line(coll_calc, 3)=', make_line(coll_calc, 3))
-##[' ', '1', ' ', '+', ' ', '_', ' ', '=', ' ', '3', ' ']
-#print('in functions: make_line(coll_calc, 5)=', make_line(coll_calc, 5))
-##[' ', '1', ' ', '+', ' ', '2', ' ', '=', ' ', '_', ' ']
-
-
-def make_line_remainder(coll_calc):
- """make a calc (returned by collect_digits) to a line to display"""
- _i, _line = 0, [' ']
- for _c in coll_calc:
- if _i == 4 or _i == 6:
- for _d in _c:
- #print('in make_line_remainder: _c, _d=', _c, _d)
- _line.append('_')
- else:
- if _c == 'in':
- _line.extend([' ',_c,' '])
- else:
- for _d in _c:
- #print('in make_line: _c, _d=', _c, _d)
- if _d in ['=','+','-','*',':']: #not '|'
- _line.extend([' ',_d,' '])
- else:
- _line.append(_d)
- _i = _i + 1
- _line.append(' ')
- return _line
-#coll_calc = [['2'], 'in', ['2'], '=', ['1'], '|', ['0']]
-#print(make_line_remainder(coll_calc))
-
-
-def make_input(coll_calc, linepos):
- """make a list of inputs formatted for Display in one line.
- take car of 'in' from times_div"""
- _indig_cnt, _ins = 0, []
- for _indig in coll_calc[linepos-1]:
- _c_cnt, _inline, _in_idx, _in_ahead = 0, [' '], 1, True
- for _c in coll_calc: #build 1 line (see make_line)
- #print('in make_input: _c_cnt=', _c_cnt,', _c=',_c)
- if _c_cnt == linepos-1:
- _d_cnt = 0
- for _d in _c:
- #print('in make_input: _d_cnt=',_d_cnt,', _d=',_d)
- if _indig_cnt >= _d_cnt:
- _inline.append(_d)
- _in_ahead = False
- #_in_idx = _in_idx + 1
- else:
- _inline.append('_')
- _d_cnt = _d_cnt + 1
- else:
- if _c == 'in':
- _inline.extend([' ',_c,' '])
- if _in_ahead:
- _in_idx = _in_idx + 3
- else:
- for _d in _c:
- #print('in make_input: _d=', _d)
- if _d in ['=','+','-','*',':','in']:
- _inline.extend([' ',_d,' '])
- if _in_ahead:
- _in_idx = _in_idx + 3
- else:
- _inline.append(_d)
- if _in_ahead:
- _in_idx = _in_idx + 1
- _c_cnt = _c_cnt + 1
- _inline.append(' ')
- _idx = _in_idx + _indig_cnt
- _indig = coll_calc[linepos-1][_indig_cnt]
- _prot_err = copy.deepcopy(_inline)
- _prot_err[_idx] = '_'
- _in = (0, _idx, _indig, \
- ''.join(_prot_err), ''.join(_inline), \
- _inline)
- _ins.append(_in)
- _indig_cnt = _indig_cnt + 1
- _ins.reverse() #for pop
- return _ins
-####################################################################
-#ins = make_input([['1','2','3'], '+', ['4'], '=', ['1','2','7']], 5)
-#print(ins)
-#[(0, 13, '7', ' 123 + 4 = 12_ ', ' 123 + 4 = 127 ',
-# [' ', '1', '2', '3', ' ', '+', ' ', '4', ' ', '=', ' ', '1', '2', '7',' ']),
-# (0, 12, '2', ' 123 + 4 = 1__ ', ' 123 + 4 = 12_ ',
-# [' ', '1', '2', '3', ' ', '+', ' ', '4', ' ', '=', ' ', '1', '2', '_',' ']),
-# (0, 11, '1', ' 123 + 4 = ___ ', ' 123 + 4 = 1__ ',
-# [' ', '1', '2', '3', ' ', '+', ' ', '4', ' ', '=', ' ', '1', '_', '_',' '])]
-#ins = make_input([['1'], '*', ['2'], '=', ['2']], 5)
-#print(ins)
-#[(0, 9, '2', ' 1 * 2 = _ ', ' 1 * 2 = 2 ',
-# [' ', '1', ' ', '*', ' ', '2', ' ', '=', ' ', '2', ' '])]
-
-
-def make_input_remainder(strs, res, rem):
- """make the 2 lines for input result and remainder with ':' and 'in'"""
- #print('in make_input_remainder: len(strs)=', len(strs))
- #print('in make_input_remainder: strs=', strs)
- #print('in make_input_remainder: res=', res, ', rem=', rem)
- _strs = copy.deepcopy(strs)
- if len(_strs) == 13: # 9 : 2 = 4|1
- _line1 = copy.deepcopy(_strs)
- _strs[9] = res[0]
- _line2 = copy.deepcopy(_strs)
- _strs[11] = rem[0]
- _line3 = copy.deepcopy(_strs)
- #print('in make_input_remainder: line1,2,3=', _line1, _line2, _line3)
- _ins = [(0, 9, res[0], "".join(_line1), "".join(_line2), _line2),\
- (0, 11, rem[0], "".join(_line2), "".join(_line3), _line3)]
- elif len(_strs) == 14: # 17 : 2 = 8|1
- _line1 = copy.deepcopy(_strs)
- _strs[10] = res[0]
- _line2 = copy.deepcopy(_strs)
- _strs[12] = rem[0]
- _line3 = copy.deepcopy(_strs)
- _ins = [(0, 10, res[0], "".join(_line1), "".join(_line2), _line2),\
- (0, 12, rem[0], "".join(_line2), "".join(_line3), _line3)]
- elif len(_strs) == 15: # 20 : 2 = 10|0
- _line1 = copy.deepcopy(_strs)
- _strs[10] = res[0]
- _line2 = copy.deepcopy(_strs)
- _strs[11] = res[1]
- _line3 = copy.deepcopy(_strs)
- _strs[13] = rem[0]
- _line4 = copy.deepcopy(_strs)
- _ins = [(0, 10, res[0], "".join(_line1), "".join(_line2), _line2),\
- (0, 11, res[1], "".join(_line2), "".join(_line3), _line3),\
- (0, 13, rem[0], "".join(_line3), "".join(_line4), _line4)]
- else:
- print('in make_input_remainder: ERROR len(_strs)=', len(_strs))
- #exit
- _ins.reverse() # for pop()
- return _ins
-#strs = [' ', '9', ' ', ':', ' ', '2', ' ', '=', ' ', '_', '|', '_', ' ']
-#print(make_input_remainder(strs, ['4'], ['1']))
-#[(0, 9, '4', ' 9 : 2 = _|_ ', ' 9 : 2 = 4|_ ',
-# [' ', '9', ' ', ':', ' ', '2', ' ', '=', ' ', '4', '|', '_', ' ']),
-# (0, 11, '1', ' 9 : 2 = 4|_ ', ' 9 : 2 = 4|1 ',
-# [' ', '9', ' ', ':', ' ', '2', ' ', '=', ' ', '4', '|', '1', ' '])]
-#strs = [' ', '1','7', ' ', ':', ' ', '2', ' ', '=', ' ', '_', '|', '_', ' ']
-#print(make_input_remainder(strs, ['8'], ['1']))
-#[(0, 10, '8', ' 17 : 2 = _|_ ', ' 17 : 2 = 8|_ ',
-# [' ', '1', '7', ' ', ':', ' ', '2', ' ', '=', ' ', '8', '|', '_', ' ']),
-# (0, 12, '1', ' 17 : 2 = 8|_ ', ' 17 : 2 = 8|1 ',
-# [' ', '1', '7', ' ', ':', ' ', '2', ' ', '=', ' ', '8', '|', '1', ' '])]
-#strs = [' ','2','0',' ',':',' ','2',' ','=',' ','_','_','|','_',' ']
-#print(make_input_remainder(strs, ['1','0'], ['0']))
-#[(0, 10, '1', ' 20 : 2 = __|_ ', ' 20 : 2 = 1_|_ ',
-# [' ', '2', '0', ' ', ':', ' ', '2', ' ', '=', ' ', '1', '_', '|', '_',' ']),
-# (0, 11, '0', ' 20 : 2 = 1_|_ ', ' 20 : 2 = 10|_ ',
-# [' ', '2', '0', ' ', ':', ' ', '2', ' ', '=', ' ', '1', '0', '|', '_',' ']),
-# (0, 13, '0', ' 20 : 2 = 10|_ ', ' 20 : 2 = 10|0 ',
-# [' ', '2', '0', ' ', ':', ' ', '2', ' ', '=', ' ', '1', '0', '|', '0',' '])]
-
-def strip(chars, c):
- """strip all characters c from a list of characters chars"""
- _cs = []
- for _c in chars:
- if _c != c:
- _cs.append(_c)
- return _cs
-#print(strip(['1','2','3','0','4','0'], '0'))
-#['1', '2', '3', '4']
-
-def to_str_99(i):
- """convert a 2-digit number to a list of 2 characters;
- a leading 0 is displayed by #"""
- _10, _1 = divmod(i, 10)
- if _10 == 0:
- _10 = '#' #leading 0 can be removed by strip
- return [str(_10), str(_1)]
-#print(to_str_99(98))
-#['9', '8']
-#print(to_str_99(9))
-#['#', '9']
-
-def flatten(ls):
- """flatten a list of lists; only one level"""
- _flat = []
- for _e in ls:
- if _e == 'in':
- _flat.append(_e)
- else:
- for _ei in _e:
- #print(_e, ' ', _ei)
- _flat.append(_ei)
- return _flat
-#print(flatten([['1', '2'], '+', ['3', '4'], '=', ['4', '6']]))
-#['1', '2', '+', '3', '4', '=', '4', '6']
-#print(flatten([['2'], 'in', ['2', '0'], '=', ['1', '0'], '|', ['0']]))
-#['2', 'in', '2', '0', '=', '1', '0', '|', '0']
diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/functions.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/functions.pyc Binary files differdeleted file mode 100755 index 98b3f32..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/functions.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/img/addsub_simp.jpg b/ReckonPrimer.activity/ReckonPrimer.activity/img/addsub_simp.jpg Binary files differdeleted file mode 100755 index c0c9874..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/img/addsub_simp.jpg +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/img/passten.jpg b/ReckonPrimer.activity/ReckonPrimer.activity/img/passten.jpg Binary files differdeleted file mode 100755 index d9b8313..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/img/passten.jpg +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/img/times_div.jpg b/ReckonPrimer.activity/ReckonPrimer.activity/img/times_div.jpg Binary files differdeleted file mode 100755 index aa36438..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/img/times_div.jpg +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/passten.py b/ReckonPrimer.activity/ReckonPrimer.activity/passten.py deleted file mode 100755 index 399eac4..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/passten.py +++ /dev/null @@ -1,508 +0,0 @@ -# -*- coding: UTF8 -*- -from Exercise import Exercise -import random -import copy -from functions import * -import gtk -import pygtk -import pango -from sugar.graphics import style - -class PassTen(Exercise): - def __init__(self, dis): - self.display = dis - self._calcs = [] - self._sett = {'topic' : 'passten', - 'ID' : 'passten_01', # for - 'descr' : 'subtractions passing 10', - '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 - } - - def get_setting(self): - return self._sett - - def get_topic(self): - return (self._sett)['topic'] - - def update_setting(self, sett): - self._calcs = self.generate_calcs() - self._sett = sett - - def format(self, (cs, ms, linepos)): - """format the calc for display, prepare overlays for input""" - if ms == None: - #@print('in Display.format_passten 1: calc=', (cs, linepos)) #@ - return Exercise.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 - _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 count(self): - """TODO""" - return len(self._calcs) - - def define_buttons(self): - - 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): - 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 diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/passten.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/passten.pyc Binary files differdeleted file mode 100755 index 9e95455..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/passten.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/session.py b/ReckonPrimer.activity/ReckonPrimer.activity/session.py deleted file mode 100755 index 12042aa..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/session.py +++ /dev/null @@ -1,80 +0,0 @@ -# -*- coding: utf-8 -*- - -from coach import Coach -#from Generate import Generate -from display import Display - - -class Session: - """ - for stand-alone usage by the ox-user. - ?for collaborative sessions see CoSession - """ - print("DEL import Session") - - def __init__(self, name, window): - self._name = name - #self._co = Coach(self) - #self._dis = Display(window, self) - - self._dis = Display(window) - self._co = Coach() - self._co.register(self, self._dis) - self._dis.register(self, self._co) - self._co.create_exercises() - self._calcs = None #pop ! - - def run(self): - """as long as user does exercises""" - print("in Session.run") - #WN090624 self._co.get_setting() - self._co.request_exercise() - self._dis.init_calc() - - def notify(self, (msg, data)): - '''called by the observed objects''' - #print('in Session.notify: msg=,data=', msg, data) - if msg == 'setting-done': # from Coach - self._ex = data - self._calcs = data.generate_calcs() - self._key = data.get_topic() - (self._calcs).reverse() - _calc = (self._calcs).pop() - #WN090624 self._dis.show_calc((self._calcs).pop()) - #print('in Session.notify: calc=', _calc) - _lines, self._input = data.format(_calc) - self._dis.display_calc(_lines) - self._curr_in = self._input.pop() #need _curr_in in notify - self._dis.create_entryline(self._curr_in) - # create_entryline sets the callback from gtk to Display - #WN090624 new - if msg == 'digit-done': - #print('in Session.notify, digit-done: _input=', self._input) - (lino, pos, dig, proterr, protok, li) = self._curr_in - self._dis.create_entryline((lino, -1, dig, proterr, protok, li)) - if len(self._input) > 0: - self._curr_in = self._input.pop() - self._dis.create_entryline(self._curr_in) - else: # start new calc - #WN090624 self._sess.notify(('calc-done', None)) - self._dis.show_progress() - if len(self._calcs) > 0: - _calc = (self._calcs).pop() - #WN090624 self._dis.show_calc((self._calcs).pop()) - print('in Session.notify: calc=', _calc) - _lines, self._input = self._ex.format(_calc) - self._dis.display_calc(_lines) - self._curr_in = self._input.pop() #need _curr_in in notify - self._dis.create_entryline(self._curr_in) - # create_entryline sets the callback from gtk to Display - else: - self._dis.finish_calc() - #WN090624 - #if msg == 'calc-done': - # if len(self._calcs) > 0: - # self._dis.show_calc((self._calcs).pop()) - # else: - # self._dis.finish_calc() - - - diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/session.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/session.pyc Binary files differdeleted file mode 100755 index c789cb7..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/session.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/session.py~ b/ReckonPrimer.activity/ReckonPrimer.activity/session.py~ deleted file mode 100755 index e2dfabe..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/session.py~ +++ /dev/null @@ -1,80 +0,0 @@ -# -*- coding: UTF8 -*- - -from Coach import Coach -#from Generate import Generate -from Display import Display - - -class Session: - """ - for stand-alone usage by the ox-user. - ?for collaborative sessions see CoSession - """ - print("DEL import Session") - - def __init__(self, name, window): - self._name = name - #self._co = Coach(self) - #self._dis = Display(window, self) - - self._dis = Display(window) - self._co = Coach() - self._co.register(self, self._dis) - self._dis.register(self, self._co) - self._co.create_exercises() - self._calcs = None #pop ! - - def run(self): - """as long as user does exercises""" - print("in Session.run") - #WN090624 self._co.get_setting() - self._co.request_exercise() - self._dis.init_calc() - - def notify(self, (msg, data)): - '''called by the observed objects''' - #print('in Session.notify: msg=,data=', msg, data) - if msg == 'setting-done': # from Coach - self._ex = data - self._calcs = data.generate_calcs() - self._key = data.get_topic() - (self._calcs).reverse() - _calc = (self._calcs).pop() - #WN090624 self._dis.show_calc((self._calcs).pop()) - #print('in Session.notify: calc=', _calc) - _lines, self._input = data.format(_calc) - self._dis.display_calc(_lines) - self._curr_in = self._input.pop() #need _curr_in in notify - self._dis.create_entryline(self._curr_in) - # create_entryline sets the callback from gtk to Display - #WN090624 new - if msg == 'digit-done': - #print('in Session.notify, digit-done: _input=', self._input) - (lino, pos, dig, proterr, protok, li) = self._curr_in - self._dis.create_entryline((lino, -1, dig, proterr, protok, li)) - if len(self._input) > 0: - self._curr_in = self._input.pop() - self._dis.create_entryline(self._curr_in) - else: # start new calc - #WN090624 self._sess.notify(('calc-done', None)) - self._dis.show_progress() - if len(self._calcs) > 0: - _calc = (self._calcs).pop() - #WN090624 self._dis.show_calc((self._calcs).pop()) - print('in Session.notify: calc=', _calc) - _lines, self._input = self._ex.format(_calc) - self._dis.display_calc(_lines) - self._curr_in = self._input.pop() #need _curr_in in notify - self._dis.create_entryline(self._curr_in) - # create_entryline sets the callback from gtk to Display - else: - self._dis.finish_calc() - #WN090624 - #if msg == 'calc-done': - # if len(self._calcs) > 0: - # self._dis.show_calc((self._calcs).pop()) - # else: - # self._dis.finish_calc() - - - diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/settings.py b/ReckonPrimer.activity/ReckonPrimer.activity/settings.py deleted file mode 100755 index 4ada373..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/settings.py +++ /dev/null @@ -1,151 +0,0 @@ -# -*- coding: UTF8 -*-
-# (c) Patrick Loder 2009
-
-import pickle
-import os
-class Settings:
- """
- a setting is a dictionary, the settings is 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")
-
- def __init__(self):
- print("DEL do Settings.__init__")
- #+ and - between min and max, max <= 10
- self._default_addsub_simp = \
- {'topic' : 'addsub_simp',
- 'ID' : 'addsub_simp_01',
- 'descr' : 'all additions with result 5', #describe this setting
- 'MAX' : 50, # 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' : 5, # 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
- }
-
- self._default_passten = \
- {'topic' : 'passten',
- 'ID' : 'passten_01',
- 'descr' : 'subtractions passing 10',
- '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._default_times_div = \
- {'topic' : 'times_div',
- 'ID' : 'times_div_01',
- 'descr' : 'n times 2',
- 'MAX' : 100, # maximum of calcs generated;
- # TODO: Generate fills up by varying input.
- 'MIN' : 10, # minimum of calcs generated 090416WN:UNUSED
- '*' : True, # eg. 7 . 2 =_
- '*commute' : True, # commute the operands 2 . 7 = _
- ':' : False, # 14 : 2 = _
- 'in' : False, # 2 in 14 = _
- 'remainder' : False, # : | in ... with remainder
- 'min' : 2, # +: minimum number in right *operand
- # -: minimum result
- 'max' : 2, # +: maximum number in right *operand
- # -: maximum result
- 'shuffle_all' : False, # shuffle all calcs
- 'shuffle_inner': True, # shuffle only 1st (inner) iteration
- 'cut-max' : True # cut set of all calcs down to MAX
- }
- #!!!extend here with additional topic!!!
-
- self._setts = {'default_addsub_simp' : self._default_addsub_simp,
- 'default_passten' : self._default_passten,
- 'default_times_div' : self._default_times_div
- #!!!extend here with additional topic!!!
- }
-
- 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'
-# if os.path.exists(dat_name):
-# txt_file = open(dat_name, 'rb')
-# if key == 'default_addsub_simp':
-# self._default_addsub_simp = pickle.load(txt_file)
-# elif key == 'default_passten':
-# self._default_passten = pickle.load(txt_file)
-#
-# def save_setting(self, key):
-# """a variant of this will be used for authoring"""
-# dat_name = 'C:/rpa8/coach/latest-topic.txt'
-# txt_file = open(dat_name, 'wb')
-# if key == 'default_addsub_simp':
-# 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 ###################
- #for testing passten: get setts from default_*
- def get_setting(self, key):
- print("in Settings.get_setting, key=" + key)
- return (key, self._setts['default_' + key])
-
diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/settings.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/settings.pyc Binary files differdeleted file mode 100755 index b6dc9f1..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/settings.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/setup.py b/ReckonPrimer.activity/ReckonPrimer.activity/setup.py deleted file mode 100755 index ec0f64e..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/setup.py +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env python -from sugar.activity import bundlebuilder -bundlebuilder.start() diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/setup.py~ b/ReckonPrimer.activity/ReckonPrimer.activity/setup.py~ deleted file mode 100755 index 6ed89aa..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/setup.py~ +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env python -from sugar.activity import bundlebuilder -bundlebuilder.start() - diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/timer.py b/ReckonPrimer.activity/ReckonPrimer.activity/timer.py deleted file mode 100755 index 5043452..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/timer.py +++ /dev/null @@ -1,101 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2008 John Paulett (john -at- 7oars.com) -# All rights reserved. -# -# This software is licensed as described in the file COPYING, which -# you should have received as part of this distribution. - -import time - -"""stopwatch is a very simple Python module for measuring time. -Great for finding out how long code takes to execute. - ->>> import stopwatch ->>> t = stopwatch.Timer() ->>> t.elapsed -3.8274309635162354 ->>> print t -15.9507198334 sec ->>> t.stop() -30.153270959854126 ->>> print t -30.1532709599 sec - -Decorator exists for printing out execution times: ->>> from stopwatch import clockit ->>> @clockit - def mult(a, b): - return a * b ->>> print mult(2, 6) -mult in 1.38282775879e-05 sec -6 - -""" - -__version__ = '0.3.1' -__author__ = 'John Paulett <http://blog.7oars.com>' - -class Timer(object): - def __init__(self): - self.__stopped = None - self.__start = self.__time() - - def stop(self): - """Stops the clock permanently for the instance of the Timer. - Returns the time at which the instance was stopped. - """ - self.__stopped = self.__last_time() - return self.elapsed - - def elapsed(self): - """The number of seconds since the current time that the Timer - object was created. If stop() was called, it is the number - of seconds from the instance creation until stop() was called. - """ - return self.__last_time() - self.__start - elapsed = property(elapsed) - - def start_time(self): - """The time at which the Timer instance was created. - """ - return self.__start - start_time = property(start_time) - - def stop_time(self): - """The time at which stop() was called, or None if stop was - never called. - """ - return self.__stopped - stop_time = property(stop_time) - - def __last_time(self): - """Return the current time or the time at which stop() was call, - if called at all. - """ - if self.__stopped is not None: - return self.__stopped - return self.__time() - - def __time(self): - """Wrapper for time.time() to allow unit testing. - """ - return time.time() - - def __str__(self): - """Nicely format the elapsed time - """ - return str(self.elapsed) + ' sec' - -def clockit(func): - """Function decorator that times the evaluation of *func* and prints the - execution time. - """ - def new(*args, **kw): - t = Timer() - retval = func(*args, **kw) - t.stop() - print '%s in %s' % (func.__name__, t) - del t - return retval - return new diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/timer.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/timer.pyc Binary files differdeleted file mode 100755 index 68ef6e7..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/timer.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/timesdiv.py b/ReckonPrimer.activity/ReckonPrimer.activity/timesdiv.py deleted file mode 100755 index c3bb3a4..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/timesdiv.py +++ /dev/null @@ -1,417 +0,0 @@ -# -*- coding: UTF8 -*- -from Exercise import Exercise -import random -import copy -from functions import * -import gtk -import pygtk -import pango -from sugar.graphics import style - -class TimesDiv(Exercise): - def __init__(self, dis): - self.display = dis - self._calcs = [] - self._sett = {'topic' : 'times_div', - 'ID' : 'times_div_01', - 'descr' : 'n times 2', - 'MAX' : 100, # maximum of calcs generated; - # TODO: Generate fills up by varying input. - 'MIN' : 10, # minimum of calcs generated 090416WN:UNUSED - '*' : True, # eg. 7 . 2 =_ - '*commute' : True, # commute the operands 2 . 7 = _ - ':' : False, # 14 : 2 = _ - 'in' : False, # 2 in 14 = _ - 'remainder' : False, # : | in ... with remainder - 'min' : 2, # +: minimum number in right *operand - # -: minimum result - 'max' : 2, # +: maximum number in right *operand - # -: maximum result - 'shuffle_all' : False, # shuffle all calcs - 'shuffle_inner': True, # shuffle only 1st (inner) iteration - 'cut-max' : True # cut set of all calcs down to MAX - } - - def get_setting(self): - return self._sett - - def get_topic(self): - return (self._sett)['topic'] - - def update_setting(self, sett): - self._calcs = self.generate_calcs() - self._sett = sett - - def format(self, (calc, linepos)): - """format the calc for display, prepare overlays for input""" - #print('in Display.format_times_div: calc=', (calc, linepos))#@ - _ccs = collect_digits(calc) - #print('in Display.format_times_div: _ccs=', _ccs) - _l0 = make_line_remainder(_ccs) - #print('in Display.format_times_div: _l0=', _l0) - if contain(calc, '|'): - #print('in Display.format_times_div: (_l0,_c[4],_c[6])=', - # (_l0, _ccs[4], _ccs[6])) - _ip = make_input_remainder(_l0, _ccs[4], _ccs[6]) - #print('in Display.format_times_div: _ip=', _ip) - else: - _ip = make_input(_ccs, linepos) - #print('in Display.format_times_div: return=', ([_l0], _ip)) #@ - return ([_l0], _ip) - - def generate_calcs(self): - """generate all calculations between min..max given in dict""" - #print('in Generate.times_div, (min, max)=',(_dic['min'], _dic['max'], _dic['remainder'])) - _dic = self._sett - _calcs = [] - if _dic['*']: - _calcs.extend(self.tim_div(_dic['min'], _dic['max'], '*', _dic['shuffle_inner'], _dic['remainder'])) - if _dic['*commute']: - _calcs.extend(self.tim_div(_dic['min'], _dic['max'], '*commute', _dic['shuffle_inner'], _dic['remainder'])) - if _dic[':']: - _calcs.extend(self.tim_div(_dic['min'], _dic['max'], ':', _dic['shuffle_inner'], _dic['remainder'])) - if _dic['in']: - _calcs.extend(self.tim_div(_dic['min'], _dic['max'], 'in', _dic['shuffle_inner'], _dic['remainder'])) - if _dic['shuffle_all']: - random.shuffle(_calcs) - return _calcs - - def count(self): - """TODO""" - return len(self._calcs) - - def define_buttons(self): - - self.label = gtk.Label("2")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 0, 1, 13, 14 )
- self.label.show() - - self.label = gtk.Label("in")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 1, 2, 13, 14 )
- self.label.show() - - self.label = gtk.Label("2")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 2, 3, 13, 14 )
- self.label.show() - - self.label = gtk.Label("=")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 3, 4, 13, 14 )
- self.label.show() - - self.label = gtk.Label("1")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 4, 5, 13, 14 )
- self.label.show() - - self.label = gtk.Label("|")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 5, 6, 13, 14 )
- self.label.show() - - self.display.settings_table.resize(15, 8) - - self.label = gtk.Label("0")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 6, 7, 13, 14 )
- self.label.show() - - self.label = gtk.Label("2")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 0, 1, 12, 13 )
- self.label.show() - - self.label = gtk.Label(":")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 1, 2, 12, 13 )
- self.label.show() - - self.label = gtk.Label("2")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 2, 3, 12, 13 )
- self.label.show() - - self.label = gtk.Label("=")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 3, 4, 12, 13 )
- self.label.show() - - self.label = gtk.Label("1")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 4, 5, 12, 13 )
- self.label.show() - - self.label = gtk.Label("|")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 5, 6, 12, 13 )
- self.label.show() - - self.label = gtk.Label("0")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 6, 7, 12, 13 )
- self.label.show() - - self.label = gtk.Label("1")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 0, 1, 9, 10 )
- self.label.show() - - self.label = gtk.Label("*")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 1, 2, 9, 10 )
- self.label.show() - - self.label = gtk.Label("=")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 3, 4, 9, 10 )
- self.label.show() - - self.label = gtk.Label("2")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 4, 5, 9, 10 )
- self.label.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, 2, 3, 11, 12 )
- 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, 0, 1, 11, 12 )
- self.toggle_shuffle_inner.show() - - self.toggle_remainder = gtk.ToggleButton("V")
- self.toggle_remainder_label = self.toggle_remainder.get_child()
- self.toggle_remainder_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
- self.toggle_remainder.connect("toggled", self.toggle_remainder_callback)
- self.display.settings_table.attach(self.toggle_remainder, 5, 7, 11, 12 )
- self.toggle_remainder.show() - - self.label = gtk.Label("< - >")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 0, 3, 10, 11)
- self.label.show() - - self.toggle_times = gtk.ToggleButton("<") - self.toggle_times_label = self.toggle_times.get_child()
- self.toggle_times_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_times.connect("toggled", self.toggle_times_callback) - self.display.settings_table.attach(self.toggle_times, 7, 8, 9, 10 )
- self.toggle_times.show() - - self.toggle_commute = gtk.ToggleButton("<") - self.toggle_commute_label = self.toggle_commute.get_child()
- self.toggle_commute_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_commute.connect("toggled", self.toggle_commute_callback) - self.display.settings_table.attach(self.toggle_commute, 7, 8, 10, 11 )
- self.toggle_commute.show() - - self.toggle_div = gtk.ToggleButton("<") - self.toggle_div_label = self.toggle_div.get_child()
- self.toggle_div_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_div.connect("toggled", self.toggle_div_callback) - self.display.settings_table.attach(self.toggle_div, 7, 8, 12, 13 )
- self.toggle_div.show() - - self.toggle_in = gtk.ToggleButton("<") - self.toggle_in_label = self.toggle_in.get_child()
- self.toggle_in_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_in.connect("toggled", self.toggle_in_callback) - self.display.settings_table.attach(self.toggle_in, 7, 8, 13, 14 )
- self.toggle_in.show() - - self.number_butts = []
-
- for i in range(2 ,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, 2, 3, 11-i, 12-i)
- self.toggle.show()
- self.number_butts.append(self.toggle) - - def set_buttons(self, sett): - - for i in range(sett['min'],sett['max']+1):
- self.number_butts[i-2].set_active(True) - - 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) - - if (sett['*'] == True): - self.toggle_times.set_active(True) - else: - self.toggle_times.set_active(False) - - if (sett['*commute'] == True): - self.toggle_commute.set_active(True) - else: - self.toggle_commute.set_active(False) - - if (sett[':'] == True): - self.toggle_div.set_active(True) - else: - self.toggle_div.set_active(False) - - if (sett['in'] == True): - self.toggle_in.set_active(True) - else: - self.toggle_in.set_active(False) - - if (sett['remainder'] == True): - self.toggle_remainder.set_active(True) - else: - self.toggle_remainder.set_active(False) - - #**** callbacks ******************************************************** - - 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_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) - - - def toggle_times_callback(self, widget): - if widget.get_active(): - self.display._sett['*'] = True - else: - if( self.toggle_commute.get_active() or self.toggle_in.get_active() or self.toggle_div.get_active() ): - self.display._sett['*'] = False - else: - widget.set_active(True) - - def toggle_commute_callback(self, widget): - if widget.get_active(): - self.display._sett['*commute'] = True - else: - if( self.toggle_times.get_active() or self.toggle_in.get_active() or self.toggle_div.get_active() ): - self.display._sett['*commute'] = False - else: - widget.set_active(True) - - def toggle_div_callback(self, widget): - if widget.get_active(): - self.display._sett[':'] = True - else: - if( self.toggle_times.get_active() or self.toggle_in.get_active() or self.toggle_commute.get_active() ): - self.display._sett[':'] = False - else: - widget.set_active(True) - - def toggle_in_callback(self, widget): - if widget.get_active(): - self.display._sett['in'] = True - else: - if( self.toggle_times.get_active() or self.toggle_commute.get_active() or self.toggle_div.get_active() ): - self.display._sett['in'] = False - else: - widget.set_active(True) - - def toggle_remainder_callback(self, widget): - if widget.get_active(): - self.display._sett['remainder'] = True - else: - self.display._sett['remainder'] = False - - ##### end of public methods ############################################ - - def tim_div(self, min, maxx, dic, shuffle_inner, remainder): - """generate all multiplications between min..max given for * : in; - to be called such that all *, all : etc are together""" - _calcs = [] - for _j in range(min, maxx +1): - if remainder: - for _i in range(0,10*_j +1): - #print('in Generate.tim_div, (j,i,dm)=',(_j, _i), - # divmod(_i, _j)) - _res, _rem = divmod(_i, _j) - if dic == '*': #this should be excluded by settings - _c = [str(_i),'*',str(_j),'=',to_str_99(_i*_j)] - elif dic == '*commute': #this should be excluded .. - _c = [str(_j),'*',str(_i),'=',to_str_99(_i*_j)] - elif dic == ':': - _c = [to_str_99(_i),':',str(_j),'=',to_str_99(_res), - '|', str(_rem)] - elif dic == 'in': - _c = [str(_j),'in',to_str_99(_i),'=',to_str_99(_res), - '|', str(_rem)] - _c = flatten(_c) - _c = strip(_c, '#') # to_str_99 returns leading 0 as # - _calcs.append((_c, 5)) - else: - for _i in range(1,11): - #print('in Generate.tim_div, (j,i)=',(_j, _i)) - if dic == '*': - _c = [to_str_99(_i),'*',str(_j),'=',to_str_99(_i*_j)] - elif dic == '*commute': - _c = [str(_j),'*',to_str_99(_i),'=',to_str_99(_i*_j)] - elif dic == ':': - _c = [to_str_99(_i*_j),':',str(_j),'=',to_str_99(_i)] - elif dic == 'in': - _c = [str(_j),'in',to_str_99(_i*_j),'=',to_str_99(_i)] - _c = flatten(_c) - _c = strip(_c, '#') # to_str_99 returns leading 0 as # - _calcs.append((_c, 5)) - if shuffle_inner: - random.shuffle(_calcs) - - return _calcs - diff --git a/ReckonPrimer.activity/ReckonPrimer.activity/timesdiv.pyc b/ReckonPrimer.activity/ReckonPrimer.activity/timesdiv.pyc Binary files differdeleted file mode 100755 index c145f46..0000000 --- a/ReckonPrimer.activity/ReckonPrimer.activity/timesdiv.pyc +++ /dev/null diff --git a/ReckonPrimer.activity/ReckonPrimerActivity.py~ b/ReckonPrimer.activity/ReckonPrimerActivity.py~ deleted file mode 100755 index 67655bb..0000000 --- a/ReckonPrimer.activity/ReckonPrimerActivity.py~ +++ /dev/null @@ -1,83 +0,0 @@ -#! -*- coding: utf-8 -*- -#(c) Stefan Heher 2009 -from time import strftime -import pygtk -import gtk -from sugar.activity import activity -from sugar.datastore import datastore -from sugar import profile -from Session import Session - -class ReckonPrimerActivity(activity.Activity): - - def __init__(self, handle): - - activity.Activity.__init__(self, handle) - """ Create the official Sugar toolbox at the top of the screen""" - toolbox = activity.ActivityToolbox(self) - self.set_toolbox(toolbox) - toolbox.show() - - file_location = activity.get_activity_root() + \ - "/data/reckonprimer_report.txt" - file_handle = open(file_location, 'w') - file_handle.write("Report: " + profile.get_nick_name() + \ - strftime(" %Y-%m-%d %H:%M:%S") + "\n") - file_handle.close() - - title = "Report: " + profile.get_nick_name() + \ - strftime(" %Y-%m-%d %H:%M:%S") - mime = "text/plain" - file_path = activity.get_activity_root() + \ - "/data/reckonprimer_report.txt" - favorite = "1" - tags = "ReckonPrimer" - - journal_object = datastore.create() - journal_object.metadata['title'] = title - journal_object.metadata['mime_type'] = mime - journal_object.file_path = file_path - journal_object.metadata['keep'] = favorite - journal_object.metadata['tags'] = tags - journal_object.metadata['icon-color'] = '#AFD600,#5B615C' - datastore.write( journal_object ) - journal_object.destroy() - - self.run_session() - - - def run_session(self): - session = Session("xo-user-name", self) - session.run() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ReckonPrimer.activity/coach.py~ b/ReckonPrimer.activity/coach.py~ deleted file mode 100755 index 6c49bf3..0000000 --- a/ReckonPrimer.activity/coach.py~ +++ /dev/null @@ -1,103 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -import pprint -import pickle -from settings import Settings -from display import Display -from Exercise import Exercise -from addsubsimp import AddSubSimp -from passten import PassTen -from timesdiv import TimesDiv - -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") - - 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 - - def register(self, sess, dis): - self._sess = sess - self._dis = dis - - 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 = AddSubSimp(self._dis) - _ex2 = PassTen(self._dis) - _ex3 = TimesDiv(self._dis) - 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 - - # this version will go to VS on Apr.27: get setts from file - # def get_setting(self): - # print("in Coach.get_setting") - # TODO coach selects an exercise - # self._key = 'addsub_simp' - #TODO relate key to sett of exercise - # _sett = self._setts.load_last_sett(self._key) - # print("in Coach.get_setting, key=, sett=", self._key, _sett) - # self._dis.show_setting(self._key, _sett) - # sett returned from Display by Session.notify - # + toggle Settings.get_setting - Coach.notify - # for testing passten: get setts from default_* - # WN090624 def get_setting(self): - - def request_exercise(self): - print("in Coach.get_setting") - # WN090624 self._dis.offer_topics(['addsub_simp', - # 'passten', 'times_div']) - self._dis.offer_topics([t.get_topic() for t in self._exs]) - # calls back with notify('setting-done'... - - def notify(self, (msg, data)): - """called by the observed objects""" - - print("in Coach.notify: msg=, data=", (msg, data)) - if msg == 'setting-done': - # + self._setts.save_last_sett(self._key, data) - # WN090624 self._sess.notify((msg, data)) - self._ex.update_setting(data) - self._update_exs(self._ex) - self._sess.notify((msg, self._ex)) - elif msg == 'new-topic': - # WN090624 self._key, _sett = self._setts.get_setting(data) - # WN090624 self._dis.offer_setting(self._key, _sett) - # WN090624 new... - self._ex = self.get_ex(data) - self._dis.offer_setting(self._ex) - - def get_ex(self, tpc): - """Get an example by topic. TODO get by ID if exs are stored on disk. - """ - for _t in self._exs: - if _t.get_topic() == tpc: - return _t diff --git a/ReckonPrimer.activity/display.py~ b/ReckonPrimer.activity/display.py~ deleted file mode 100755 index ed8e90b..0000000 --- a/ReckonPrimer.activity/display.py~ +++ /dev/null @@ -1,451 +0,0 @@ -#! -*- coding: utf-8 -*- -#(c) Stefan Heher 2009 -#1234567890123456789012345678901234567890123456789012345678901234567890123456789 -import gtk -import pygtk -import pango -import time -import gobject -from sugar.activity import activity -from functions import * -from settings import Settings -from timer import Timer -from Exercise import Exercise -from sugar import profile -from sugar.graphics import style - - - -class Display: - """ - Definition and manipulation of all GUI-elemts. - Exception (redesign?): def define_buttons in classes derived from Exercise. - """ - print("DEL import Display") - - def __init__(self, window): - self.errors = 0 - self._sett = None # setting updated by callbacks during input - self.running = False # first round of calculations - - self.active_topic = None - - - # ----- all permanent GUI-elements ----- TODO separate def - # Save the sugar main window - self.main_window = window - - # Create a table consisting of 4 possible entries - self.table = gtk.Table(5, 2, True) - - # Put the table in the main window - self.main_window.set_canvas(self.table) - - # Create the log_buffer - self.log_buffer = gtk.TextBuffer() - - # Create a tag table from the buffer - self.tag_table = self.log_buffer.get_tag_table() - - # Create a tag for errors - self.error_tag = gtk.TextTag("error") - self.error_tag.set_property("foreground", "blue") - self.tag_table.add(self.error_tag) - - # Create a tag for correct calculations - self.correct_tag = gtk.TextTag("correct") - self.correct_tag.set_property("foreground", "green") - self.tag_table.add(self.correct_tag) - - - # Create a log_view with the previously created log_buffer - self.log_view = gtk.TextView(self.log_buffer) - - # Set the font size for the log_view - self.log_view.modify_font(pango.FontDescription('sans bold 14')) - - # Set the log_view to not editable - self.log_view.set_editable(False) - - # Set the cursor to not visible - self.log_view.set_cursor_visible(False) - - # Set the justification to center - self.log_view.set_justification(gtk.JUSTIFY_CENTER) - - # Create a scrollable window for the log_view - self.scrolled_window = gtk.ScrolledWindow() - - # Set scrollable window policies - self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - - # Connect log_view and scrolled window - self.scrolled_window.add(self.log_view) - - # Insert the log_view into the upper half - self.table.attach(self.scrolled_window, 0, 1, 0, 3) - - # Display the log_view - self.log_view.show() - - # Display the scrolled_window - self.scrolled_window.show() - - # Settings start here - self.settings_table = gtk.Table(15, 6, True) - - # Topic table - self.topic_table = gtk.Table(15, 6, True) - - # Separate table for start button - self.table_with_start = gtk.Table(15, 6, True) - - # Insert the settings window into the right half of the screen - self.table.attach(self.settings_table, 1, 2, 0, 5) - - # Insert the topic window into the right half of the screen - self.table.attach(self.topic_table, 1, 2, 0, 5) - - # Insert the table for start button into the right half of the screen - self.table.attach(self.table_with_start, 1, 2, 0, 5) - - # Display the settings_table - self.settings_table.show() - - # Disply the topic table - self.topic_table.show() - - # Display the table_with_start - self.table_with_start.show() - - # Display the table - self.table.show() - - def register(self, sess, co): - """register _after_ Session and Coach have been instantiated""" - self._sess = sess - self._co = co - - def update_time(self): - minutes, seconds = divmod(self.stopwatch.elapsed, 60) - if(minutes < 10 and seconds < 10): - time = "0" + str(int(minutes)) + ":" + "0" + str(int(seconds)) - if(minutes > 9 and seconds > 9): - time = str(int(minutes)) + ":" + str(int(seconds)) - if(minutes > 9 and seconds < 10): - time = str(int(minutes)) + ":" + "0" + str(int(seconds)) - if(minutes < 10 and seconds > 10): - time = "0" + str(int(minutes)) + ":" + str(int(seconds)) - self.stopwatch_label.set_label(time) - self.stopwatch_label.queue_draw() - return True - - - - def draw_result_screen(self): - - # Section for stopwatch - self.stopwatch = Timer() - self.stopwatch_label = gtk.Label("00:00") - self.stopwatch_label.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.stopwatch_label, 3, 5, 12, 13) - - # Section for nickname - self.name = profile.get_nick_name() - self.name_label = gtk.Label(self.name) - self.name_label.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.name_label, 0, 6, 13, 14) - - # Section for progress bar - self.progressbar = gtk.ProgressBar(adjustment=None) - - # Color for progress bar - style = self.progressbar.get_style() - style.bg[gtk.STATE_PRELIGHT] = gtk.gdk.color_parse("green") - self.progressbar.set_style (style) - self.progressbar.set_fraction(0) - self.table_with_start.attach(self.progressbar, 0, 6, 8, 9) - - # Labels for progress bar - self.progress0 = gtk.Label("0") - self.progress0.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.progress0, 0, 1, 9, 10 ) - - # Labels for status update - self.correct_count = 0 - self.correct_counter = gtk.Label(str(self.correct_count)) - self.correct_counter.modify_font(pango.FontDescription("sans 16")) - - - # Ugly code for label color - attr = pango.AttrList() - fg_color = pango.AttrForeground(0, 65535, 0, 0, 6) - attr.insert(fg_color) - self.correct_counter.set_attributes(attr) - - self.table_with_start.attach(self.correct_counter, 2, 4, 9, 10 ) - - self.false_count = 0 - self.false_counter = gtk.Label(str(self.false_count)) - self.false_counter.modify_font(pango.FontDescription("sans 16")) - - # Ugly code for label color - attr = pango.AttrList() - fg_color = pango.AttrForeground(0, 0, 65535, 0, 6) - attr.insert(fg_color) - self.false_counter.set_attributes(attr) - - self.table_with_start.attach(self.false_counter, 2, 4, 10, 11 ) - - self.stopwatch_label.show() - gobject.timeout_add(1000, self.update_time) - self.name_label.show() - self.progressbar.show() - self.progress0.show() - self.correct_counter.show() - self.false_counter.show() - - self.total_calcs = self._ex.count() - self.progress_total = gtk.Label(str(self.total_calcs)) - self.progress_total.modify_font(pango.FontDescription("sans 16")) - self.table_with_start.attach(self.progress_total, 5, 6, 9, 10 ) - self.progress_total.show() - - def hide_result_screen(self): - self.progressbar.set_fraction(0) - self.stopwatch_label.hide() - self.name_label.hide() - self.progressbar.hide() - self.progress0.hide() - self.correct_counter.hide() - self.false_counter.hide() - self.progress_total.hide() - - def offer_setting(self,ex): - self._ex = ex - self._sett = self._ex.get_setting() - - ### START BUTTON BEGIN ### - self.start_button = gtk.Button(None, gtk.STOCK_GO_FORWARD) - self.start_button.connect("clicked", self.clicked_start_callback) - self.table_with_start.attach(self.start_button, 0, 6, 14, 15) - self.start_alignment = self.start_button.get_children()[0] - self.start_hbox = self.start_alignment.get_children()[0] - self.start_image, self.start_label = self.start_hbox.get_children() - self.start_label.set_label("") - self.start_button.show() - ### START BUTTON END ### - - - ### NEW ### - self.current_exercise = ex - self.current_exercise.define_buttons() - self.current_exercise.set_buttons(self._sett) - ### NEW ### - - def clicked_start_callback(self, widget): - - if( self.running == False): - - self.running = True - self.start_button.set_label(gtk.STOCK_STOP) - self.start_alignment = self.start_button.get_children()[0] - self.start_hbox = self.start_alignment.get_children()[0] - self.start_image, self.start_label = self.start_hbox.get_children() - self.start_label.set_label("") - self._co.notify(('setting-done', self._sett)) - self.settings_table.hide() - self.topic_table.hide() - - self.draw_result_screen() - - elif( self.running == True): - - self.protocol('----------------------------------------', 0, 'OK') - self.running = False - self.start_button.set_label(gtk.STOCK_GO_FORWARD) - self.start_alignment = self.start_button.get_children()[0] - self.start_hbox = self.start_alignment.get_children()[0] - self.start_image, self.start_label = self.start_hbox.get_children() - self.start_label.set_label("") - self.display_table.destroy() - self.hide_result_screen() - self.settings_table.show() - self.topic_table.show() - - def init_calc(self): - """ - prepares for calculations from 1 setting. - for instance, a calculation might be on 1 ore more lines. - """ - print("DEL do Display.init_calc") - # make empty lines such that all calcs are entered at bottom - for i in range(1,21): - end_iterator = self.log_buffer.get_end_iter() - self.log_buffer.insert(end_iterator, "\n") - self.log_view.scroll_mark_onscreen(self.log_buffer.get_insert()) - - - - - def destroy_box(self): - self.calculation_box.destroy() - - def protocol(self, full_line, errors, feedback): - end_iterator = self.log_buffer.get_end_iter() - - if( feedback == 'OK' ): - self.log_buffer.insert_with_tags_by_name(end_iterator, "\n" + full_line, "correct" ) - elif ( feedback == 'XXX' ): - self.log_buffer.insert_with_tags_by_name(end_iterator, "\n" + full_line, "error" ) - end_iterator = self.log_buffer.get_end_iter() - mark = self.log_buffer.create_mark(None, end_iterator, True) - self.log_view.scroll_mark_onscreen(mark) - - def dis_calc(self, clist, cursor, errs): - _i, _calc = 0, '' - for _c in clist: - _i = _i + 1 - if (_i == cursor) & (errs > 0): - _calc = _calc + '_' - else: - _calc = _calc + _c - return _calc + ' ' + errs * '/' - - def input_digit(self, widget, dig, proterr, protok): - """input a digit and give feedback. - The _only_ other active widget is the <stop>-button on the right""" - entry_text = widget.get_text() - ### bitte anzeigen !??????? - if(entry_text == dig): - - self.errors = 0 #WN090518 ??? - self.protocol(protok, self.errors, 'OK') - self.destroy_box() - self.notify(('digit-done', None)) - elif(entry_text == ""): - pass #otherwise feedback in protocol written twice: see entry.set_text("") below - else: - self.false_count = self.false_count + 1 - self.false_counter.set_text(str(self.false_count)) - self.errors = self.errors + 1 - widget.set_text("") - self.protocol(proterr, self.errors, 'XXX') - - - #WN090518 - def display_calc(self, lines): - - self.display_table = gtk.Table(5, 1, True) - self.table.attach(self.display_table, 0, 1, 0, 5) - self.display_table.show() - - """display the lines of a calc with _ at all input positions""" - lino = 0 - for li in lines: - print('in Display.display_calc, line=', li) - self.create_entryline((lino, -1, 'dummy-dig', 'dummy-proterr', 'dummy-protok', li)) - lino = lino + 1 - - - def create_entryline(self, (lineno, linepos, dig, proterr, protok, line)): - """create gtk.Entry in line at linepos and set callback_input_digit""" - print('in Display.create_entryline: lineno=', lineno, ', linepos=', - linepos, ', line=', line) - calculation, cursor = line, linepos - self.calculation_box = gtk.HBox(True, 0) - calc_pos = 0 - self.display_table.attach(self.calculation_box, 0, 1, 3 + lineno, 4 + lineno) - for i in calculation: - if (calc_pos != cursor): - self.label = gtk.Label(i) - self.label.modify_font(pango.FontDescription("sans 24")) - self.calculation_box.pack_start(self.label) - self.label.show() - else: # prepare for input - self.text_entry = gtk.Entry(max = 1) - self.text_entry.modify_font(pango.FontDescription("sans 24")) - self.text_entry.connect("changed", self.input_digit, dig, proterr, protok) - self.calculation_box.pack_start(self.text_entry) - self.text_entry.show() - calc_pos = calc_pos + 1 - #?kann m.die calculation_box ZUERST aufbauen und DANN self.table.attach - self.calculation_box.show() - - if(cursor != -1): - self.text_entry.grab_focus() - #just add lineno to table.attach - #TODO rename calculation, cursor below ... - #TODO remove hack on callback: - #self.input_digit('widget', dig, protline) - - - def finish_calc(self): - self.stopwatch.stop() - - - def notify(self, msg): - """only used by gtk""" - if msg[0] == 'digit-done': - self._sess.notify(('digit-done', None)) - - def show_progress(self): - self.progressbar.set_fraction(self.progressbar.get_fraction()+(float(1)/float(self.total_calcs))) - self.correct_count = self.correct_count + 1 - self.correct_counter.set_text(str(self.correct_count)) - self.display_table.destroy() - - - def offer_topics(self, topics): - """TODO: get the users choice from buttons above the settings""" - self.topic_box = gtk.HBox(True, 0) - self.topic_table.attach(self.topic_box, 0, 6, 0, 1) - - _i = 0 - for _t in topics: - _i = _i + 1 - 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.new_topic, _t) - self.topic_box.pack_start(self.button) - self.button.show() - - self.topic_box.show() - - - def new_topic(self, widget, topic): - """TODO: get the users choice from buttons above the settings""" - - if(self.active_topic == None): - self.active_topic = topic - self._co.notify(('new-topic', topic)) - - elif(self.active_topic == topic): - pass - - elif(self.active_topic != topic): - self.active_topic = topic - self.settings_table.destroy() - self.settings_table = gtk.Table(15, 6, True) - self.table.attach(self.settings_table, 1, 2, 0, 5) - self.settings_table.show() - - self.table_with_start.destroy() - self.table_with_start = gtk.Table(15, 6, True) - self.table.attach(self.table_with_start, 1, 2, 0, 5) - self.table_with_start.show() - self._co.notify(('new-topic', topic)) - - - - - diff --git a/ReckonPrimer.activity/session.py~ b/ReckonPrimer.activity/session.py~ deleted file mode 100755 index 61f612e..0000000 --- a/ReckonPrimer.activity/session.py~ +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- - -from coach import Coach -#from Generate import Generate -from display import Display - - -class Session: - """ - for stand-alone usage by the ox-user. - ?for collaborative sessions see CoSession - """ - print("DEL import Session") - - def __init__(self, name, window): - self._name = name - self._dis = Display(window) - self._co = Coach() - self._co.register(self, self._dis) - self._dis.register(self, self._co) - self._co.create_exercises() #TODO.WN091101 replace by storing Exerc.s - self._calcs = None #pop ! - - def run(self): - """as long as user does exercises""" - #print("in Session.run") - self._co.request_exercise() - self._dis.init_calc() #TODOWN091101 take Exercise as argument - - def notify(self, (msg, data)): - '''called by the observed objects''' - #print('in Session.notify: msg=,data=', msg, data) - if msg == 'setting-done': # from Coach - self._ex = data - self._calcs = data.generate_calcs() - self._key = data.get_topic() - (self._calcs).reverse() - _calc = (self._calcs).pop() - #print('in Session.notify: calc=', _calc) - _lines, self._input = data.format(_calc) - self._dis.display_calc(_lines) - self._curr_in = self._input.pop() #need _curr_in in notify - self._dis.create_entryline(self._curr_in) - # create_entryline sets the callback from gtk to Display - if msg == 'digit-done': # from Display - #print('in Session.notify, digit-done: _input=', self._input) - (lino, pos, dig, proterr, protok, li) = self._curr_in - self._dis.create_entryline((lino, -1, dig, proterr, protok, li)) - if len(self._input) > 0: - self._curr_in = self._input.pop() - self._dis.create_entryline(self._curr_in) - else: # start new calc - self._dis.show_progress() - if len(self._calcs) > 0: - _calc = (self._calcs).pop() - print('in Session.notify: calc=', _calc) - _lines, self._input = self._ex.format(_calc) - self._dis.display_calc(_lines) - self._curr_in = self._input.pop() #need _curr_in in notify - self._dis.create_entryline(self._curr_in) - # create_entryline sets the callback from gtk to Display - else: - self._dis.finish_calc() diff --git a/ReckonPrimer.activity/setup.py~ b/ReckonPrimer.activity/setup.py~ deleted file mode 100755 index 6ed89aa..0000000 --- a/ReckonPrimer.activity/setup.py~ +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env python -from sugar.activity import bundlebuilder -bundlebuilder.start() - diff --git a/ReckonPrimer.activity/timesdiv.py~ b/ReckonPrimer.activity/timesdiv.py~ deleted file mode 100755 index c3bb3a4..0000000 --- a/ReckonPrimer.activity/timesdiv.py~ +++ /dev/null @@ -1,417 +0,0 @@ -# -*- coding: UTF8 -*- -from Exercise import Exercise -import random -import copy -from functions import * -import gtk -import pygtk -import pango -from sugar.graphics import style - -class TimesDiv(Exercise): - def __init__(self, dis): - self.display = dis - self._calcs = [] - self._sett = {'topic' : 'times_div', - 'ID' : 'times_div_01', - 'descr' : 'n times 2', - 'MAX' : 100, # maximum of calcs generated; - # TODO: Generate fills up by varying input. - 'MIN' : 10, # minimum of calcs generated 090416WN:UNUSED - '*' : True, # eg. 7 . 2 =_ - '*commute' : True, # commute the operands 2 . 7 = _ - ':' : False, # 14 : 2 = _ - 'in' : False, # 2 in 14 = _ - 'remainder' : False, # : | in ... with remainder - 'min' : 2, # +: minimum number in right *operand - # -: minimum result - 'max' : 2, # +: maximum number in right *operand - # -: maximum result - 'shuffle_all' : False, # shuffle all calcs - 'shuffle_inner': True, # shuffle only 1st (inner) iteration - 'cut-max' : True # cut set of all calcs down to MAX - } - - def get_setting(self): - return self._sett - - def get_topic(self): - return (self._sett)['topic'] - - def update_setting(self, sett): - self._calcs = self.generate_calcs() - self._sett = sett - - def format(self, (calc, linepos)): - """format the calc for display, prepare overlays for input""" - #print('in Display.format_times_div: calc=', (calc, linepos))#@ - _ccs = collect_digits(calc) - #print('in Display.format_times_div: _ccs=', _ccs) - _l0 = make_line_remainder(_ccs) - #print('in Display.format_times_div: _l0=', _l0) - if contain(calc, '|'): - #print('in Display.format_times_div: (_l0,_c[4],_c[6])=', - # (_l0, _ccs[4], _ccs[6])) - _ip = make_input_remainder(_l0, _ccs[4], _ccs[6]) - #print('in Display.format_times_div: _ip=', _ip) - else: - _ip = make_input(_ccs, linepos) - #print('in Display.format_times_div: return=', ([_l0], _ip)) #@ - return ([_l0], _ip) - - def generate_calcs(self): - """generate all calculations between min..max given in dict""" - #print('in Generate.times_div, (min, max)=',(_dic['min'], _dic['max'], _dic['remainder'])) - _dic = self._sett - _calcs = [] - if _dic['*']: - _calcs.extend(self.tim_div(_dic['min'], _dic['max'], '*', _dic['shuffle_inner'], _dic['remainder'])) - if _dic['*commute']: - _calcs.extend(self.tim_div(_dic['min'], _dic['max'], '*commute', _dic['shuffle_inner'], _dic['remainder'])) - if _dic[':']: - _calcs.extend(self.tim_div(_dic['min'], _dic['max'], ':', _dic['shuffle_inner'], _dic['remainder'])) - if _dic['in']: - _calcs.extend(self.tim_div(_dic['min'], _dic['max'], 'in', _dic['shuffle_inner'], _dic['remainder'])) - if _dic['shuffle_all']: - random.shuffle(_calcs) - return _calcs - - def count(self): - """TODO""" - return len(self._calcs) - - def define_buttons(self): - - self.label = gtk.Label("2")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 0, 1, 13, 14 )
- self.label.show() - - self.label = gtk.Label("in")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 1, 2, 13, 14 )
- self.label.show() - - self.label = gtk.Label("2")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 2, 3, 13, 14 )
- self.label.show() - - self.label = gtk.Label("=")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 3, 4, 13, 14 )
- self.label.show() - - self.label = gtk.Label("1")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 4, 5, 13, 14 )
- self.label.show() - - self.label = gtk.Label("|")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 5, 6, 13, 14 )
- self.label.show() - - self.display.settings_table.resize(15, 8) - - self.label = gtk.Label("0")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 6, 7, 13, 14 )
- self.label.show() - - self.label = gtk.Label("2")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 0, 1, 12, 13 )
- self.label.show() - - self.label = gtk.Label(":")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 1, 2, 12, 13 )
- self.label.show() - - self.label = gtk.Label("2")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 2, 3, 12, 13 )
- self.label.show() - - self.label = gtk.Label("=")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 3, 4, 12, 13 )
- self.label.show() - - self.label = gtk.Label("1")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 4, 5, 12, 13 )
- self.label.show() - - self.label = gtk.Label("|")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 5, 6, 12, 13 )
- self.label.show() - - self.label = gtk.Label("0")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 6, 7, 12, 13 )
- self.label.show() - - self.label = gtk.Label("1")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 0, 1, 9, 10 )
- self.label.show() - - self.label = gtk.Label("*")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 1, 2, 9, 10 )
- self.label.show() - - self.label = gtk.Label("=")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 3, 4, 9, 10 )
- self.label.show() - - self.label = gtk.Label("2")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 4, 5, 9, 10 )
- self.label.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, 2, 3, 11, 12 )
- 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, 0, 1, 11, 12 )
- self.toggle_shuffle_inner.show() - - self.toggle_remainder = gtk.ToggleButton("V")
- self.toggle_remainder_label = self.toggle_remainder.get_child()
- self.toggle_remainder_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
- self.toggle_remainder.connect("toggled", self.toggle_remainder_callback)
- self.display.settings_table.attach(self.toggle_remainder, 5, 7, 11, 12 )
- self.toggle_remainder.show() - - self.label = gtk.Label("< - >")
- self.label.modify_font(pango.FontDescription("sans 12"))
- self.display.settings_table.attach(self.label, 0, 3, 10, 11)
- self.label.show() - - self.toggle_times = gtk.ToggleButton("<") - self.toggle_times_label = self.toggle_times.get_child()
- self.toggle_times_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_times.connect("toggled", self.toggle_times_callback) - self.display.settings_table.attach(self.toggle_times, 7, 8, 9, 10 )
- self.toggle_times.show() - - self.toggle_commute = gtk.ToggleButton("<") - self.toggle_commute_label = self.toggle_commute.get_child()
- self.toggle_commute_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_commute.connect("toggled", self.toggle_commute_callback) - self.display.settings_table.attach(self.toggle_commute, 7, 8, 10, 11 )
- self.toggle_commute.show() - - self.toggle_div = gtk.ToggleButton("<") - self.toggle_div_label = self.toggle_div.get_child()
- self.toggle_div_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_div.connect("toggled", self.toggle_div_callback) - self.display.settings_table.attach(self.toggle_div, 7, 8, 12, 13 )
- self.toggle_div.show() - - self.toggle_in = gtk.ToggleButton("<") - self.toggle_in_label = self.toggle_in.get_child()
- self.toggle_in_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12))) - self.toggle_in.connect("toggled", self.toggle_in_callback) - self.display.settings_table.attach(self.toggle_in, 7, 8, 13, 14 )
- self.toggle_in.show() - - self.number_butts = []
-
- for i in range(2 ,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, 2, 3, 11-i, 12-i)
- self.toggle.show()
- self.number_butts.append(self.toggle) - - def set_buttons(self, sett): - - for i in range(sett['min'],sett['max']+1):
- self.number_butts[i-2].set_active(True) - - 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) - - if (sett['*'] == True): - self.toggle_times.set_active(True) - else: - self.toggle_times.set_active(False) - - if (sett['*commute'] == True): - self.toggle_commute.set_active(True) - else: - self.toggle_commute.set_active(False) - - if (sett[':'] == True): - self.toggle_div.set_active(True) - else: - self.toggle_div.set_active(False) - - if (sett['in'] == True): - self.toggle_in.set_active(True) - else: - self.toggle_in.set_active(False) - - if (sett['remainder'] == True): - self.toggle_remainder.set_active(True) - else: - self.toggle_remainder.set_active(False) - - #**** callbacks ******************************************************** - - 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_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) - - - def toggle_times_callback(self, widget): - if widget.get_active(): - self.display._sett['*'] = True - else: - if( self.toggle_commute.get_active() or self.toggle_in.get_active() or self.toggle_div.get_active() ): - self.display._sett['*'] = False - else: - widget.set_active(True) - - def toggle_commute_callback(self, widget): - if widget.get_active(): - self.display._sett['*commute'] = True - else: - if( self.toggle_times.get_active() or self.toggle_in.get_active() or self.toggle_div.get_active() ): - self.display._sett['*commute'] = False - else: - widget.set_active(True) - - def toggle_div_callback(self, widget): - if widget.get_active(): - self.display._sett[':'] = True - else: - if( self.toggle_times.get_active() or self.toggle_in.get_active() or self.toggle_commute.get_active() ): - self.display._sett[':'] = False - else: - widget.set_active(True) - - def toggle_in_callback(self, widget): - if widget.get_active(): - self.display._sett['in'] = True - else: - if( self.toggle_times.get_active() or self.toggle_commute.get_active() or self.toggle_div.get_active() ): - self.display._sett['in'] = False - else: - widget.set_active(True) - - def toggle_remainder_callback(self, widget): - if widget.get_active(): - self.display._sett['remainder'] = True - else: - self.display._sett['remainder'] = False - - ##### end of public methods ############################################ - - def tim_div(self, min, maxx, dic, shuffle_inner, remainder): - """generate all multiplications between min..max given for * : in; - to be called such that all *, all : etc are together""" - _calcs = [] - for _j in range(min, maxx +1): - if remainder: - for _i in range(0,10*_j +1): - #print('in Generate.tim_div, (j,i,dm)=',(_j, _i), - # divmod(_i, _j)) - _res, _rem = divmod(_i, _j) - if dic == '*': #this should be excluded by settings - _c = [str(_i),'*',str(_j),'=',to_str_99(_i*_j)] - elif dic == '*commute': #this should be excluded .. - _c = [str(_j),'*',str(_i),'=',to_str_99(_i*_j)] - elif dic == ':': - _c = [to_str_99(_i),':',str(_j),'=',to_str_99(_res), - '|', str(_rem)] - elif dic == 'in': - _c = [str(_j),'in',to_str_99(_i),'=',to_str_99(_res), - '|', str(_rem)] - _c = flatten(_c) - _c = strip(_c, '#') # to_str_99 returns leading 0 as # - _calcs.append((_c, 5)) - else: - for _i in range(1,11): - #print('in Generate.tim_div, (j,i)=',(_j, _i)) - if dic == '*': - _c = [to_str_99(_i),'*',str(_j),'=',to_str_99(_i*_j)] - elif dic == '*commute': - _c = [str(_j),'*',to_str_99(_i),'=',to_str_99(_i*_j)] - elif dic == ':': - _c = [to_str_99(_i*_j),':',str(_j),'=',to_str_99(_i)] - elif dic == 'in': - _c = [str(_j),'in',to_str_99(_i*_j),'=',to_str_99(_i)] - _c = flatten(_c) - _c = strip(_c, '#') # to_str_99 returns leading 0 as # - _calcs.append((_c, 5)) - if shuffle_inner: - random.shuffle(_calcs) - - return _calcs - diff --git a/ReckonPrimer.tests/README.txt b/ReckonPrimer.tests/README.txt index fe9e883..8909f4e 100755 --- a/ReckonPrimer.tests/README.txt +++ b/ReckonPrimer.tests/README.txt @@ -5,7 +5,7 @@ legend: the prompt is > run all tests: ~~~~~~~~~~~~~~ -> python _all-test.py +ReckonPrimer.tests> python _all_test.py ... must finish with ##### ReckonPrimer.tests/_all-test.py SUCCESS ######################## @@ -38,6 +38,8 @@ all directories involved need to be in the PYTHONPATH: > export PYTHONPATH +... these commands are required at the beginning of each session, unless ... + organization of test-driven development: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # each module of the production code contains one class @@ -45,6 +47,6 @@ organization of test-driven development: # in each directory RP.tests/dirname there is a file _dirname_test.py # this _dirname_test.py contains "def _dirname_test():" which executes all tests in this directory -# test modules are named modulename_test.py -# all test classes are named TestClassName +# test modules are named module_name_test.py +# all test classes are named MockClassName # all test methods are named test_method_name diff --git a/ReckonPrimer.tests/README.txt~ b/ReckonPrimer.tests/README.txt~ deleted file mode 100755 index 1323625..0000000 --- a/ReckonPrimer.tests/README.txt~ +++ /dev/null @@ -1,15 +0,0 @@ - - - -Exercise.py -ReckonPrimerActivity.py -addsubsimp.py -coach.py -display.py -functions.py -passten.py -session.py -settings.py -setup.py -timer.py -timesdiv.py diff --git a/ReckonPrimer.tests/ReckonPrimerActivity/ReckonPrimerActivity-NOGUI.py~ b/ReckonPrimer.tests/ReckonPrimerActivity/ReckonPrimerActivity-NOGUI.py~ deleted file mode 100755 index 2f01b29..0000000 --- a/ReckonPrimer.tests/ReckonPrimerActivity/ReckonPrimerActivity-NOGUI.py~ +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: UTF8 -*-
-"""main of ReckonPrimer
-see http://wiki.laptop.org/go/Software_projects#ReconPrimer
-(c) Walther Neuper 2009
-"""
-# WN090416 after successful run there is a strange error at the end ?!?
-
-
-from Session import Session
-
-# initializations
-
-_sess = Session("ox-user-name", 'xxx') # TODO.WN090311 name should come from Sugar
-_sess.run()
-
-# finalizations
-
diff --git a/ReckonPrimer.tests/_all_test.py b/ReckonPrimer.tests/_all_test.py index 234c0f5..4b0c425 100644 --- a/ReckonPrimer.tests/_all_test.py +++ b/ReckonPrimer.tests/_all_test.py @@ -5,8 +5,10 @@ print("#########################_________####################################") print("##### ReckonPrimer.tests/_all_test.py ################################") -from _addsubsimp_test import _addsubsimp_test -_addsubsimp_test() + +#from _addsubsimp_test import _addsubsimp_test +#_addsubsimp_test() +import _addsubsimp_test import _timesdiv_test print("##### ReckonPrimer.tests/_all_test.py ################################") diff --git a/ReckonPrimer.tests/_bugs.txt~ b/ReckonPrimer.tests/_bugs.txt~ deleted file mode 100755 index 2f4ae10..0000000 --- a/ReckonPrimer.tests/_bugs.txt~ +++ /dev/null @@ -1,4 +0,0 @@ -Activities/ReckonPrimer.tests/_bugs.txt -WN091110 - -#WN091110: <10> with "1+2 <" switched off does not create calcs diff --git a/ReckonPrimer.tests/addsubsimp/_addsubsimp_test.py b/ReckonPrimer.tests/addsubsimp/_addsubsimp_test.py index 63a00fc..7fbf160 100644 --- a/ReckonPrimer.tests/addsubsimp/_addsubsimp_test.py +++ b/ReckonPrimer.tests/addsubsimp/_addsubsimp_test.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- -# Activities/ReckonPrimer.tests/addsubsimp/_all-test.py print("#########################__________###################################") print("##### ReckonPrimer.tests/addsubsimp/_addsubsimp_test.py ##############") -def _addsubsimp_test(): - from test_generate_calc import test_generate_calc - test_generate_calc() +#def _addsubsimp_test(): +# from test_generate_calc import test_generate_calc +# test_generate_calc() + + import test_generate_calc from test_some import test_some test_some() |