Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalther Neuper <wneuper@localhost.(none)>2010-04-06 09:09:24 (GMT)
committer Walther Neuper <wneuper@localhost.(none)>2010-04-06 09:09:24 (GMT)
commit556bf90dc8fcdc831e7864bd0a59f748569d8fa7 (patch)
tree36208ab8ea4a695d9dd779b88992b28d7b7d035d
parent41c58febc0b1cc1f89a51981738b39bff2b628b8 (diff)
DOES NOT WORK: saved bevor CH came
-rw-r--r--ReckonPrimer.activity/exercises/extimesdiv.py356
-rw-r--r--ReckonPrimer.activity/functions.py31
-rw-r--r--ReckonPrimer.activity/settings.py23
3 files changed, 280 insertions, 130 deletions
diff --git a/ReckonPrimer.activity/exercises/extimesdiv.py b/ReckonPrimer.activity/exercises/extimesdiv.py
index bf4c065..36c7d3e 100644
--- a/ReckonPrimer.activity/exercises/extimesdiv.py
+++ b/ReckonPrimer.activity/exercises/extimesdiv.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# (c) Martin Neppel 2009
+''' signs like: #################### are new, not really tested parts'''
+
import gtk
import pygtk
import pango
@@ -12,35 +14,39 @@ from exercise import Exercise
from functions import *
class ExTimesDiv(Exercise):
-
- #_sett = None
-
def __init__(self, dis, (sett, errors)):
self._display = dis
self._sett = sett
self._errors = errors
-# {'topic' : 'times_div',
-# 'title' : 'template extimesdiv',
-# 'descript': 'multiplication, division and "in" \
-# from 2 to 19 and 20 to 190. ',
-# 'icon' : None, # for quick reference of the exercise
-# 'calclines' : 1, # no. of lines for calc to be input.
-# '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
+
+#copy from settings.py
+#self._default_times_div = \
+# {'topic' : 'times_div', #for programmers only
+# 'title' : 'template extimesdiv',
+# 'descript': 'multiplication, division and "in" \
+# from 2 to 19 and 20 to 190. ',
+# 'icon' : None, # for quick reference of the exercise
+# 'calclines' : 1, # no. of lines for calc to be input.
+# 'MAX' : 50, # maximum of calcs generated;
+# # TODO: Generate fills up by varying input.
+# 'MIN' : 10, # minimum of calcs generated 090416WN:UNUSED
+# '*' : True, # eg. 7 . 2 =_
+# '*commute' : False, # commute the operands 2 . 7 = _
+# ':' : False, # 14 : 2 = _
+# 'in' : True, # 2 in 14 = _
+# 'remainder' : True, # : | in ... with remainder
+# 'vadd' : 0, # 0 or 10, for 1.11 ... 1.19
+# 'vmult' : 1, # 1 or 10, for 1.10 ... 1.90
+# '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
+# 'factors' : [1,2,3,4,5], # Liste mit ausgewählten zahlen zur berechnung
+# 'shuffle_all' : False, # shuffle all calcs
+# 'shuffle_inner': False, # shuffle only 1st (inner) iteration
+# 'cut-max' : True # cut set of all calcs down to MAX
# }
+
self._calcs = self._generate_calcs()
def format(self, (calc, linepos)):
@@ -62,20 +68,26 @@ class ExTimesDiv(Exercise):
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']))
+ #print('in Generate.times_div, (min, max)=',(_dic['min'], _dic['max'],
+ # _dic['remainder']))
_dic = self._sett
#print('in Generate.times_div, _dic=', _dic)
_calcs = []
if _dic['*']:
- _calcs.extend(self.tim_div(_dic['min'], _dic['max'], '*', _dic['shuffle_inner'], _dic['remainder']))
+ _calcs.extend(self.tim_div(_dic['factors'], '*',
+_dic['shuffle_inner'], _dic['remainder'], _dic['vadd'], _dic['vmult']))
if _dic['*commute']:
- _calcs.extend(self.tim_div(_dic['min'], _dic['max'], '*commute', _dic['shuffle_inner'], _dic['remainder']))
+ _calcs.extend(self.tim_div(_dic['factors'], '*commute',
+_dic['shuffle_inner'], _dic['remainder'], _dic['vadd'], _dic['vmult']))
if _dic[':']:
- _calcs.extend(self.tim_div(_dic['min'], _dic['max'], ':', _dic['shuffle_inner'], _dic['remainder']))
+ _calcs.extend(self.tim_div(_dic['factors'], ':',
+_dic['shuffle_inner'], _dic['remainder'], _dic['vadd'], _dic['vmult']))
if _dic['in']:
- _calcs.extend(self.tim_div(_dic['min'], _dic['max'], 'in', _dic['shuffle_inner'], _dic['remainder']))
+ _calcs.extend(self.tim_div(_dic['factors'], 'in',
+_dic['shuffle_inner'], _dic['remainder'], _dic['vadd'], _dic['vmult']))
if _dic['shuffle_all']:
random.shuffle(_calcs)
+ _calcs = _calcs[:_dic['MAX']]
return _calcs
# def count(self):
@@ -86,174 +98,227 @@ class ExTimesDiv(Exercise):
"""buttons for this setting, which is specific for TimesDiv"""
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._display.settings_table.attach(self.label, 0, 1, 12, 13 )
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._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, 13, 14 )
+ 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, 13, 14 )
+ 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, 13, 14 )
+ 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, 13, 14 )
+ self._display.settings_table.attach(self.label, 5, 6, 12, 13 )
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._display.settings_table.attach(self.label, 6, 7, 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, 0, 1, 12, 13 )
+ self._display.settings_table.attach(self.label, 0, 1, 11, 12 )
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._display.settings_table.attach(self.label, 1, 2, 11, 12 )
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._display.settings_table.attach(self.label, 2, 3, 11, 12 )
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._display.settings_table.attach(self.label, 3, 4, 11, 12 )
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._display.settings_table.attach(self.label, 4, 5, 11, 12 )
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._display.settings_table.attach(self.label, 5, 6, 11, 12 )
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._display.settings_table.attach(self.label, 6, 7, 11, 12 )
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._display.settings_table.attach(self.label, 0, 1, 8, 9 )
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._display.settings_table.attach(self.label, 1, 2, 8, 9 )
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._display.settings_table.attach(self.label, 5, 6, 8, 9 )
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._display.settings_table.attach(self.label, 6, 7, 8, 9 )
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_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._display.settings_table.attach(self.toggle_shuffle_all, 2, 3, 10, 11 )
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_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, 10, 11 )
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_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._display.settings_table.attach(self.toggle_remainder, 6, 7, 10, 11 )
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._display.settings_table.attach(self.label, 0, 3, 9, 10)
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_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._display.settings_table.attach(self.toggle_times, 8, 9, 8, 9 )
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_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._display.settings_table.attach(self.toggle_commute, 8, 9, 9, 10 )
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_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._display.settings_table.attach(self.toggle_div, 8, 9, 11, 12 )
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_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._display.settings_table.attach(self.toggle_in, 8, 9, 12, 13 )
self.toggle_in.show()
+ self.toggle_vadd = gtk.ToggleButton("1")
+ self.toggle_vadd_label = self.toggle_vadd.get_child()
+ self.toggle_vadd_label.modify_font(pango.FontDescription("sans %d" %
+style.zoom(12)))
+ self.toggle_vadd.connect("toggled", self.toggle_vadd_callback)
+ self._display.settings_table.attach(self.toggle_vadd, 2, 3, 0, 9 )
+ self.toggle_vadd.show()
+
+ self.toggle_vmult = gtk.ToggleButton("0")
+ self.toggle_vmult_label = self.toggle_vmult.get_child()
+ self.toggle_vmult_label.modify_font(pango.FontDescription("sans %d" %
+style.zoom(12)))
+ self.toggle_vmult.connect("toggled", self.toggle_vmult_callback)
+ self._display.settings_table.attach(self.toggle_vmult, 4, 5, 0, 9 )
+ self.toggle_vmult.show()
+
self.number_butts = []
- for i in range(2 ,9 + 1):
+ 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_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._display.settings_table.attach(self.toggle, 3, 4, 9-i, 10-i)
self.toggle.show()
self.number_butts.append(self.toggle)
def set_buttons(self, sett):
"""buttons for setting specific to 'topic' 'times_div'"""
-
- #print('extimesdiv: set_buttons')
- self._sett = sett
- #print(str(self._sett['min'])+' '+str(sett['min']))
- for i in range(2, 9 + 1):
- if(i<sett['min'] or i>sett['max']):
- self.number_butts[i-2].set_active(False)
- for i in range(sett['min'],sett['max']+1):
- self.number_butts[i-2].set_active(True)
+ print('### in extimesdiv. set_buttons sett=',sett)
+ for i in range(0, 8+1):
+ print('### inaktiv werden:',i)
+ self.number_butts[i].set_active(False)
+
+ print('### vor der aktivierungsschleife:',sett['factors'])
+ #_xxx = [1,2,3] #sett['factors']
+ #print('### in extimesdiv. set_buttons _xxx=',_xxx)
+ #for i in _xxx:
+ for i in sett['factors']:
+ print('### in extimesdiv, i=',i-1)
+ print('### in der schleife sind die factors:', sett['factors'])
+ self.number_butts[i-1].set_active(True)
+ print('### in extimesdiv. set_buttons after set_active(True)')
+ print('### nach der schleife sind die factors:', sett['factors'])
+
+#('### in extimesdiv. set_buttons _xxx=', [1, 2, 3])
+#('### in extimesdiv, i=', 0)
+#Traceback (most recent call last):
+# File "/netshares/staffhomes/wneuper/Activities/ReckonPrimer.activity/extimesdiv.py", line 381, in toggle_number_callback
+# del_ord(self._display._sett['factors'], i)
+# File "/netshares/staffhomes/wneuper/Activities/ReckonPrimer.activity/functions.py", line 367, in del_ord
+# ls.remove(n)
+#ValueError: list.remove(x): x not in list
+#('### in extimesdiv, i=', 1)
+#Traceback (most recent call last):
+# File "/netshares/staffhomes/wneuper/Activities/ReckonPrimer.activity/extimesdiv.py", line 386, in toggle_number_callback
+# ins_ord(self._display._sett['factors'], i)
+#RuntimeError: maximum recursion depth exceeded
+#('### in extimesdiv, i=', 2)
+#Traceback (most recent call last):
+# File "/netshares/staffhomes/wneuper/Activities/ReckonPrimer.activity/extimesdiv.py", line 381, in toggle_number_callback
+# del_ord(self._display._sett['factors'], i)
+# File "/netshares/staffhomes/wneuper/Activities/ReckonPrimer.activity/functions.py", line 367, in del_ord
+# ls.remove(n)
+#ValueError: list.remove(x): x not in list
+#1265902075.138594 WARNING root: No gtk.AccelGroup in the top level window.
+#1265902075.141243 WARNING root: No gtk.AccelGroup in the top level window.
+### in extimesdiv. set_buttons after set_active(True)
if (sett['shuffle_all'] == True):
self.toggle_shuffle_all.set_active(True)
@@ -292,102 +357,153 @@ class ExTimesDiv(Exercise):
#**** callbacks ********************************************************
+ def toggle_vadd_callback(self, widget):
+ if widget.get_active():
+ self._display._sett['vadd'] = 10
+ self.toggle_vadd.set_active(True)
+ self._display._sett['vmult'] = 1
+ self.toggle_vmult.set_active(False)
+ self._display._sett['remainder'] = False ####################
+ self.toggle_remainder.set_active(False) ####################
+ else:
+ self._display._sett['vadd'] = 0
+
+ def toggle_vmult_callback(self, widget):
+ if widget.get_active():
+ self._display._sett['vmult'] = 10
+ self.toggle_vmult.set_active(True)
+ self._display._sett['vadd'] = 0
+ self.toggle_vadd.set_active(False)
+ self._display._sett['remainder'] = False ####################
+ self.toggle_remainder.set_active(False) ####################
+ else:
+ self._display._sett['vmult'] = 1
+
def toggle_shuffle_all_callback(self, widget):
if widget.get_active():
- self._sett['shuffle_all'] = True
+ self._display._sett['shuffle_all'] = True
self.toggle_shuffle_inner.set_active(True)
else:
- self._sett['shuffle_all'] = False
+ self._display._sett['shuffle_all'] = False
def toggle_shuffle_inner_callback(self, widget):
if widget.get_active():
- self._sett['shuffle_inner'] = True
+ self._display._sett['shuffle_inner'] = True
else:
if(self.toggle_shuffle_all.get_active()):
widget.set_active(True)
else:
- self._sett['shuffle_inner'] = False
+ self._display._sett['shuffle_inner'] = False
+
+ def count_active_butts(self):
+ act = 0
+ for butt in self.number_butts:
+ if butt.get_active():
+ act = act + 1
+ return act
def toggle_number_callback(self, widget, i):
+ """Callback for the numberbuttons 1..9.
+ Any button can be activated or deactivated,
+ but one button must remain active.
+ REMARK: last button is redrawn from settings (i.e. last stmt)."""
if widget.get_active():
- if(i < self._sett['min']):
- self._sett['min'] = i
- #self.set_buttons(self._sett)
- elif( i > self._sett['max'] ):
- self._sett['max'] = i
- #self.set_buttons(self._sett)
+ if(i in self._display._sett['factors']):
+ #print('passed cause i=', i)
+ pass
+ else:
+ #print('number to add=', i)
+ #print('list bevore adding:', self._display._sett['factors'])
+ ins_ord(self._display._sett['factors'], i)
+ #print('list after adding', self._display._sett['factors'])
else:
- if( i == self._sett['min'] and i != self._sett['max'] ):
- self._sett['min'] = i+1
- #self.set_buttons(self._sett)
- if( i == self._sett['max'] and i != self._sett['min'] ):
- widget.set_active(True)
- self._sett['max'] = i-1
- self.set_buttons(self._sett)
+ if(len(self._display._sett['factors']) > 1):
+ #print('number to remove=', i)
+ #print('list bevore removeing:', self._display._sett['factors'])
+ self._display._sett['factors'].remove(i)
+ #print('list after removeing:', self._display._sett['factors'])
+ else: # gtk deactivates button anyway; thus get values from setting
+ #print('list will stay, because list is:', self._display._sett['factors'])
+ self.set_buttons(self._display._sett)
def toggle_times_callback(self, widget):
if widget.get_active():
- self._sett['*'] = True
+ self._display._sett['*'] = True
+ self._display._sett['remainder'] = False ####################
+ self.toggle_remainder.set_active(False) ####################
else:
- if( self.toggle_commute.get_active() or self.toggle_in.get_active() or self.toggle_div.get_active() ):
- self._sett['*'] = False
+ 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._sett['*commute'] = True
+ 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._sett['*commute'] = False
+ 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._sett[':'] = True
+ self._display._sett[':'] = True
else:
- if( self.toggle_times.get_active() or self.toggle_in.get_active() or self.toggle_commute.get_active() ):
- self._sett[':'] = False
+ 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._sett['in'] = True
+ 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._sett['in'] = False
+ 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._sett['remainder'] = True
+ self._display._sett['remainder'] = True
+ self._display._sett['*'] = False ####################
+ self.toggle_times.set_active(False) ####################
+ self._display._sett['vadd'] = 0 ####################
+ self.toggle_vadd.set_active(False) ####################
+ self._display._sett['vmult'] = 1 ####################
+ self.toggle_vmult.set_active(False) ####################
else:
- self._sett['remainder'] = False
+ self._display._sett['remainder'] = False
##### end of public methods ############################################
- def tim_div(self, min, maxx, dic, shuffle_inner, remainder):
+ def tim_div(self, factors, dic, shuffle_inner, remainder, vadd, vmult):
"""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):
+ _calcs = []
+
+ for _j in factors:
+ _jj = (_j+vadd)*vmult
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)
+ _res, _rem = divmod(_i, _jj)
if dic == '*': #this should be excluded by settings
- _c = [str(_i),'*',str(_j),'=',to_str_99(_i*_j)]
+ _c = [str(_i),'*',str(_jj),'=',to_str_99(_i*_jj)]
elif dic == '*commute': #this should be excluded ..
- _c = [str(_j),'*',str(_i),'=',to_str_99(_i*_j)]
+ _c = [str(_jj),'*',str(_i),'=',to_str_99(_i*_jj)]
elif dic == ':':
- _c = [to_str_99(_i),':',str(_j),'=',to_str_99(_res),
+ _c = [to_str_99(_i),':',str(_jj),'=',to_str_99(_res),
'|', str(_rem)]
elif dic == 'in':
- _c = [str(_j),'in',to_str_99(_i),'=',to_str_99(_res),
+ _c = [str(_jj),'in',to_str_99(_i),'=',to_str_99(_res),
'|', str(_rem)]
_c = flatten(_c)
_c = strip(_c, '#') # to_str_99 returns leading 0 as #
@@ -396,14 +512,13 @@ class ExTimesDiv(Exercise):
for _i in range(1,11):
#print('in Generate.tim_div, (j,i)=',(_j, _i))
if dic == '*':
- #_c = [to_str_99(_i),'*',str(_j*10),'=',to_str_99(_i*_j*10)]
- _c = [to_str_99(_i),'*',str(_j),'=',to_str_99(_i*_j)]
+ _c = [to_str_99(_i),'*',str(_jj),'=',to_str_99(_i*_jj)]
elif dic == '*commute':
- _c = [str(_j),'*',to_str_99(_i),'=',to_str_99(_i*_j)]
+ _c = [str(_jj),'*',to_str_99(_i),'=',to_str_99(_i*_jj)]
elif dic == ':':
- _c = [to_str_99(_i*_j),':',str(_j),'=',to_str_99(_i)]
+ _c = [to_str_99(_i*_jj),':',str(_jj),'=',to_str_99(_i)]
elif dic == 'in':
- _c = [str(_j),'in',to_str_99(_i*_j),'=',to_str_99(_i)]
+ _c = [str(_jj),'in',to_str_99(_i*_jj),'=',to_str_99(_i)]
_c = flatten(_c)
_c = strip(_c, '#') # to_str_99 returns leading 0 as #
_calcs.append((_c, 5))
@@ -412,3 +527,4 @@ class ExTimesDiv(Exercise):
return _calcs
+
diff --git a/ReckonPrimer.activity/functions.py b/ReckonPrimer.activity/functions.py
index 0c8f646..bf51c3b 100644
--- a/ReckonPrimer.activity/functions.py
+++ b/ReckonPrimer.activity/functions.py
@@ -322,3 +322,34 @@ def flatten(ls):
#['1', '2', '+', '3', '4', '=', '4', '6']
#print(flatten([['2'], 'in', ['2', '0'], '=', ['1', '0'], '|', ['0']]))
#['2', 'in', '2', '0', '=', '1', '0', '|', '0']
+
+def ins_ord(ls, n):
+ """Insert n into the ordered list ls. Beware of creating doubles. """
+ pos = 0
+ #print("in functions.ins_ord: ls,n=",ls,n)
+ for i in ls:
+ #print("in functions.ins_ord: i=",i)
+ if n > i:
+ pos = pos + 1
+ #print("in functions.ins_ord: pos=",pos)
+ ls.insert(pos, n)
+ return ls
+
+
+#xx = ins_ord([], 2)
+#print("result=",xx)
+
+#xx = ins_ord([2], 8)
+#print("result=",xx)
+
+#xx = ins_ord([2,8], 4)
+#print("result=",xx)
+
+#xx = ins_ord([2,4,8], 1)
+#print("result=",xx)
+
+#xx = ins_ord([2,4,8], 9)
+#print("result=",xx)
+
+#xx = ins_ord([2,4,8], 4)
+#print("result=",xx)
diff --git a/ReckonPrimer.activity/settings.py b/ReckonPrimer.activity/settings.py
index 5b1dc53..786a66f 100644
--- a/ReckonPrimer.activity/settings.py
+++ b/ReckonPrimer.activity/settings.py
@@ -65,25 +65,28 @@ class Settings:
self._default_times_div = \
{'topic' : 'times_div', #for programmers only
- 'title' : 'template extimesdiv',
- 'descript': 'multiplication, division and "in" \
+ 'title' : 'template extimesdiv',
+ 'descript' : 'multiplication, division and "in" \
from 2 to 19 and 20 to 190. ',
- 'icon' : None, # for quick reference of the exercise
+ 'icon' : None, # for quick reference of the exercise
'calclines' : 1, # no. of lines for calc to be input.
- 'MAX' : 100, # maximum of calcs generated;
+ 'MAX' : 50, # 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, # eg. 7 . 2 =_
+ '*commute' : False, # commute the operands 2 . 7 = _
':' : False, # 14 : 2 = _
- 'in' : False, # 2 in 14 = _
- 'remainder' : False, # : | in ... with remainder
+ 'in' : True, # 2 in 14 = _
+ 'remainder' : True, # : | in ... with remainder
+ 'vadd' : 0, # 0 or 10, for 1.11 ... 1.19
+ 'vmult' : 1, # 1 or 10, for 1.10 ... 1.90
'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
+ 'factors' : [2,4,8], # Liste mit ausgewählten zahlen zur berechnung
+ 'shuffle_all' : False, # shuffle all calcs
+ 'shuffle_inner': False, # shuffle only 1st (inner) iteration
'cut-max' : True # cut set of all calcs down to MAX
}
#!!!extend here with additional topic!!!