Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2012-04-27 17:32:34 (GMT)
committer Walter Bender <walter.bender@gmail.com>2012-04-27 17:32:34 (GMT)
commit350dc1ae0a4266207f99386894f17390da0017c0 (patch)
tree6afd2feb6babe4e19bd4db62dfbd2e5b78ad74a2
parent52da662a492d5a095062766404ac14a9284afd35 (diff)
v38
-rw-r--r--AbacusActivity.py20
-rw-r--r--NEWS115
-rw-r--r--abacus_window.py175
-rw-r--r--activity/activity.info2
4 files changed, 167 insertions, 145 deletions
diff --git a/AbacusActivity.py b/AbacusActivity.py
index 814aa5e..a57d6ea 100644
--- a/AbacusActivity.py
+++ b/AbacusActivity.py
@@ -380,17 +380,21 @@ class AbacusActivity(activity.Activity):
def _custom_cb(self, button=None):
''' Display the custom abacus; hide the others '''
value = float(self.abacus.mode.value(count_beads=False))
+ self.abacus.mode.hide()
if self.abacus.custom is not None:
self.abacus.custom.hide()
- self.abacus.custom = Custom(self.abacus,
- rods=self._rods_spin.get_value_as_int(),
- top=self._top_spin.get_value_as_int(),
- bot=self._bottom_spin.get_value_as_int(),
- factor=self._value_spin.get_value_as_int(),
- base=self._base_spin.get_value_as_int(),
- bead_colors=self.bead_colors)
+ self.abacus.custom = Custom(self.abacus, self.abacus.bead_colors)
+ self.abacus.custom.set_custom_parameters(
+ rods=self._rods_spin.get_value_as_int(),
+ top=self._top_spin.get_value_as_int(),
+ bot=self._bottom_spin.get_value_as_int(),
+ factor=self._value_spin.get_value_as_int(),
+ base=self._base_spin.get_value_as_int())
+ self.abacus.custom.create()
+ self.abacus.custom.draw_rods_and_beads()
+ self.abacus.custom.show()
+ self.abacus.mode = self.abacus.custom
self.custom.set_active(True)
- self.abacus.select_abacus('custom')
self._label.set_text(NAMES['custom'])
def _copy_cb(self, arg=None):
diff --git a/NEWS b/NEWS
index 39ae6bc..0b33b6f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,12 +1,23 @@
+30.3
+
+ENHANCEMENTS
+* New translations
+* Notify user of delay in loading new abacus
+* Display abacus name on toolbar
+
+BUG_FIXES:
+* Refactoring to fix problem with excessive memory usage
+* Don't allow custom abacus larger than screen
+
30.2
ENHANCEMENT
-* new translations
+* New translations
30.1
ENHANCEMENT
-* new translations
+* New translations
30
@@ -17,57 +28,57 @@ UNDER THE HOOD
29
ENHANCEMENT
-* conversion to Cairo graphics
+* Conversion to Cairo graphics
28
ENHANCEMENTS
-* new translations
-* improved? labeling scheme
+* New translations
+* Improved? labeling scheme
27
ENHANCEMENTS
-* use gear emblem instead of star emblem on custom abacus icon
+* Use gear emblem instead of star emblem on custom abacus icon
BUG FIX
-* custom tool now updates radio button to indicate custom abacus is selected
+* Custom tool now updates radio button to indicate custom abacus is selected
26
ENHANCEMENTS
-* added button for selecting custom abacus
-* added colors to custom abacus
+* Added button for selecting custom abacus
+* Added colors to custom abacus
BUG FIX
-* fixed problem generating custom abacus under new refactoring
+* Fixed problem generating custom abacus under new refactoring
25
EHNANCEMENTS
-* using profile colors for bead colors
-* moved units of Soroban to center of abacus
-* added dots to Soroban
-* added reset button to toolbar and removed it from the abacus itself
-* move calculation to above the abacus rather than on the crossbar
+* Using profile colors for bead colors
+* Moved units of Soroban to center of abacus
+* Added dots to Soroban
+* Added reset button to toolbar and removed it from the abacus itself
+* Move calculation to above the abacus rather than on the crossbar
24
ENHANCEMENTS
-* new translations
+* New translations
23
ENHANCEMENTS
-* new translations
-* updated icons
+* New translations
+* Updated icons
22
ENHANCEMENTS
-* new translations for de, hy, ku, nah, nl, and tzm
-* updated toolbars and icons
-* label text uses ellipsis instead of shrinking
+* New translations for de, hy, ku, nah, nl, and tzm
+* Updated toolbars and icons
+* Label text uses ellipsis instead of shrinking
21
@@ -78,88 +89,88 @@ BUG FIX
20
ENHANCEMENTS
-* icon cleanup
-* white background
+* Icon cleanup
+* White background
BUG FIXES
-* fixed problem with beads falling off abacus (#2933)
-* fixed problem with launching from GNOME shell
+* Fixed problem with beads falling off abacus (#2933)
+* Fixed problem with launching from GNOME shell
19
-* type in values, copy/paste from clipboard
-* abacus value propogates as you move between abaci
+* Type in values, copy/paste from clipboard
+* Abacus value propogates as you move between abaci
18
-* optimization of redraw code
+* Optimization of redraw code
* Spanish translations
17
-* fixed problem with moving multiple beads on decimal abacus
-* fixed hide problem with desktop version
+* Fixed problem with moving multiple beads on decimal abacus
+* Fixed hide problem with desktop version
16
-* added color to Decimal abacus
+* Added color to Decimal abacus
15
-* added "Caacupe" abacus
-* added Cuisenaire-like abacus
+* Added "Caacupe" abacus
+* Added Cuisenaire-like abacus
14
-* simplifed toolbars
+* Simplifed toolbars
13
-* added save/restore for custom abacus
+* Added save/restore for custom abacus
12
-* decimal abacus
-* reset button
+* Decimal abacus
+* Reset button
11
-* performance improvement in label code
+* Performance improvement in label code
10
-* added labels to the beads (with inspiration and help from tuukkah)
+* Added labels to the beads (with inspiration and help from tuukkah)
9
-* customization toolbar -- design your own abacus
+* Customization toolbar -- design your own abacus
8
-* added hexadecimal
-* code cleanup to make it easier to modify/extend
+* Added hexadecimal
+* Code cleanup to make it easier to modify/extend
7
-* fixed restore bug with fraction abacus
-* added missing type to rods
+* Fixed restore bug with fraction abacus
+* Added missing type to rods
6
-* added binary abacus
-* added fraction abacus
-* autogenerate SVG
-* general code clean-up/consolidation
+* Added binary abacus
+* Added fraction abacus
+* Autogenerate SVG
+* General code clean-up/consolidation
5
-* highlight recently moved beads
-* fixed scaling problem with rods, dividing bar
+* Highlight recently moved beads
+* Fixed scaling problem with rods, dividing bar
4
-* save/restore abacus value
-* movable indicator
+* Save/restore abacus value
+* Movable indicator
3
diff --git a/abacus_window.py b/abacus_window.py
index 440480c..8265899 100644
--- a/abacus_window.py
+++ b/abacus_window.py
@@ -196,9 +196,6 @@ class Bead():
def __init__(self):
self.spr = None
- self.hard_reset()
-
- def hard_reset(self):
self.state = 0
self.fade_level = 0
self.value = 0
@@ -236,11 +233,12 @@ class Bead():
if self.spr is not None:
self.spr.set_layer(BEAD_LAYER)
- def move(self, offset):
+ def move(self, offset, move_the_bead=True):
''' Generic move method: sets state and level. '''
if self.spr is None:
return
- self.spr.move_relative((0, offset))
+ if move_the_bead:
+ self.spr.move_relative((0, offset))
if not self.tristate:
self.state = 1 - self.state
elif self.state == 1: # moving bead back to center
@@ -626,12 +624,10 @@ class Rod():
if i == -1:
return False
+ if self.fade and self.beads[self._bead_count + i].max_fade_level > 0:
+ self.beads[self._bead_count + i].set_color(self.white_beads[3])
if i < self.top_beads:
if dy > 0 and self.beads[self._bead_count + i].get_state() == 0:
- if self.fade and \
- self.beads[self._bead_count + i].max_fade_level > 0:
- self.beads[self._bead_count + i].set_color(
- self.white_beads[3])
self.beads[self._bead_count + i].move_down()
# Make sure beads below this bead are also moved.
for ii in range(self.top_beads - i):
@@ -642,10 +638,6 @@ class Rod():
self.white_beads[3])
self.beads[self._bead_count + i + ii].move_down()
elif dy < 0 and self.beads[self._bead_count + i].state == 1:
- if self.fade and \
- self.beads[self._bead_count + i].max_fade_level > 0:
- self.beads[self._bead_count + i].set_color(
- self.white_beads[3])
self.beads[self._bead_count + i].move_up()
# Make sure beads above this bead are also moved.
for ii in range(i + 1):
@@ -657,10 +649,6 @@ class Rod():
self.beads[self._bead_count + i - ii].move_up()
else:
if dy < 0 and self.beads[self._bead_count + i].state == 0:
- if self.fade and \
- self.beads[self._bead_count + i].max_fade_level > 0:
- self.beads[self._bead_count + i].set_color(
- self.white_beads[3])
self.beads[self._bead_count + i].move_up()
# Make sure beads above this bead are also moved.
for ii in range(i - self.top_beads + 1):
@@ -671,10 +659,6 @@ class Rod():
self.white_beads[3])
self.beads[self._bead_count + i - ii].move_up()
elif dy < 0 and self.beads[self._bead_count + i].state == -1:
- if self.fade and \
- self.beads[self._bead_count + i].max_fade_level > 0:
- self.beads[self._bead_count + i].set_color(
- self.white_beads[3])
self.beads[self._bead_count + i].move_up()
for ii in range(i - self.top_beads + 1):
if self.beads[self._bead_count + i - ii].state == -1:
@@ -684,10 +668,6 @@ class Rod():
self.white_beads[3])
self.beads[self._bead_count + i - ii].move_up()
elif dy > 0 and self.beads[self._bead_count + i].state == 1:
- if self.fade and \
- self.beads[self._bead_count + i].max_fade_level > 0:
- self.beads[self._bead_count + i].set_color(
- self.white_beads[3])
self.beads[self._bead_count + i].move_down()
# Make sure beads below this bead are also moved.
for ii in range(self.top_beads + self.bot_beads - i):
@@ -699,10 +679,6 @@ class Rod():
self.beads[self._bead_count + i + ii].move_down()
elif dy > 0 and self.beads[self._bead_count + i].state == 0 and \
self.beads[self._bead_count + i].tristate:
- if self.fade and \
- self.beads[self._bead_count + i].max_fade_level > 0:
- self.beads[self._bead_count + i].set_color(
- self.white_beads[3])
self.beads[self._bead_count + i].move_down()
# Make sure beads below this bead are also moved.
for ii in range(self.top_beads + self.bot_beads - i):
@@ -715,6 +691,7 @@ class Rod():
self.set_label(self.get_bead_count())
+
def set_label(self, n):
''' Different abaci use different labeling schemes. '''
if self.spr is None:
@@ -778,17 +755,31 @@ class Abacus():
_svg_str_to_pixbuf(background_svg))
background.set_layer(1)
+ self.decimal = None
self.japanese = None
- self.russian = None
+ self.chinese = None
self.mayan = None
- self.binary = None
self.hex = None
- self.decimal = None
+ self.binary = None
+ self.russian = None
self.fraction = None
self.caacupe = None
self.cuisenaire = None
self.custom = None
+ self.mode_dict = {'decimal': [self.decimal, Decimal],
+ 'soroban': [self.japanese, Soroban],
+ 'suanpan': [self.chinese, Suanpan],
+ 'nepohualtzintzin': [self.mayan, Nepohualtzintzin],
+ 'hexadecimal': [self.hex, Hex],
+ 'binary': [self.binary, Binary],
+ 'schety': [self.russian, Schety],
+ 'fraction': [self.fraction, Fractions],
+ 'caacupe': [self.caacupe, Caacupe],
+ 'cuisenaire': [self.cuisenaire, Cuisenaire],
+ 'custom': [self.custom, Custom]
+ }
+
self.bead_cache = []
for i in range(MAX_BEADS):
self.bead_cache.append(Bead())
@@ -804,30 +795,12 @@ class Abacus():
def select_abacus(self, abacus):
self.mode.hide()
- '''
- for bead in self.bead_cache:
- bead.hide()
- for rod in self.rod_cache:
- rod.hide()
- '''
-
- MODE_DICT = {'decimal': [self.decimal, Decimal],
- 'soroban': [self.japanese, Soroban],
- 'suanpan': [self.chinese, Suanpan],
- 'nepohualtzintzin': [self.mayan, Nepohualtzintzin],
- 'hexadecimal': [self.hex, Hex],
- 'binary': [self.binary, Binary],
- 'schety': [self.russian, Schety],
- 'fraction': [self.fraction, Fractions],
- 'caacupe': [self.caacupe, Caacupe],
- 'cuisenaire': [self.cuisenaire, Cuisenaire],
- 'custom': [self.custom, Custom]
- }
- if MODE_DICT[abacus][0] is None:
- MODE_DICT[abacus][0] = MODE_DICT[abacus][1](self, self.bead_colors)
+ if self.mode_dict[abacus][0] is None:
+ self.mode_dict[abacus][0] = self.mode_dict[abacus][1](
+ self, self.bead_colors)
else:
- MODE_DICT[abacus][0].draw_rods_and_beads()
- self.mode = MODE_DICT[abacus][0]
+ self.mode_dict[abacus][0].draw_rods_and_beads()
+ self.mode = self.mode_dict[abacus][0]
self.mode.show()
self.mode.label(self.generate_label())
@@ -1046,14 +1019,14 @@ class AbacusGeneric():
self.set_parameters()
self.create()
- def set_parameters(self):
+ def set_parameters(self, rods=15, top=2, bot=5, factor=5, base=10):
''' Define the physical paramters. '''
self.name = 'suanpan'
- self.num_rods = 15
- self.bot_beads = 5
- self.top_beads = 2
- self.base = 10
- self.top_factor = 5
+ self.num_rods = rods
+ self.bot_beads = top
+ self.top_beads = bot
+ self.top_factor = factor
+ self.base = base
def create(self, dots=False):
''' Create and position the sprites that compose the abacus '''
@@ -1318,28 +1291,25 @@ class AbacusGeneric():
class Custom(AbacusGeneric):
''' A custom-made abacus '''
- def __init__(self, abacus, rods=15, top=2, bot=5, factor=5, base=10,
- bead_colors=None):
+ def __init__(self, abacus, bead_colors=None):
''' Specify parameters that define the abacus '''
self.abacus = abacus
+ self.name = 'custom'
+ self.num_rods = 15
+ self.bot_beads = 5
+ self.top_beads = 2
+ self.top_factor = 5
+ self.base = 10
self.bead_colors = bead_colors
+
+ def set_custom_parameters(self, rods=15, top=2, bot=5, factor=5, base=10):
+ ''' Specify parameters that define the abacus '''
self.name = 'custom'
self.num_rods = rods
self.bot_beads = bot
self.top_beads = top
- self.base = base
self.top_factor = factor
- self.set_parameters()
- self.create()
-
- def set_parameters(self):
- ''' Specify parameters that define the abacus '''
- self.name = 'custom'
- _logger.debug('custom %d %d %d %d %d' % (self.num_rods,
- self.bot_beads,
- self.top_beads,
- self.base,
- self.top_factor))
+ self.base = base
class Nepohualtzintzin(AbacusGeneric):
@@ -1401,8 +1371,15 @@ class Soroban(AbacusGeneric):
self.base = 10
self.top_factor = 5
- def draw_rods_and_beads(self, x, y):
+ def draw_rods_and_beads(self, x=None, y=None):
''' Draw the rods and beads: units offset to center'''
+ if x is None:
+ x = self.rod_x
+ y = self.rod_y
+ else:
+ self.rod_x = x
+ self.rod_y = y
+
dx = (BEAD_WIDTH + BEAD_OFFSET) * self.abacus.scale
ro = (BEAD_WIDTH + 5) * self.abacus.scale / 2
bead_count = 0
@@ -1462,8 +1439,14 @@ class Decimal(AbacusGeneric):
self.base = 10
self.top_factor = 1
- def draw_rods_and_beads(self, x, y):
+ def draw_rods_and_beads(self, x=None, y=None):
''' Draw the rods and beads: override bead color'''
+ if x is None:
+ x = self.rod_x
+ y = self.rod_y
+ else:
+ self.rod_x = x
+ self.rod_y = y
dx = (BEAD_WIDTH + BEAD_OFFSET) * self.abacus.scale
ro = (BEAD_WIDTH + 5) * self.abacus.scale / 2
bead_count = 0
@@ -1527,8 +1510,14 @@ class Schety(AbacusGeneric):
self.base = 10
self.top_factor = 1
- def draw_rods_and_beads(self, x, y):
+ def draw_rods_and_beads(self, x=None, y=None):
''' Draw the rods and beads: short column for 1/4 '''
+ if x is None:
+ x = self.rod_x
+ y = self.rod_y
+ else:
+ self.rod_x = x
+ self.rod_y = y
dx = (BEAD_WIDTH + BEAD_OFFSET) * self.abacus.scale
ro = (BEAD_WIDTH + 5) * self.abacus.scale / 2
bead_count = 0
@@ -1570,8 +1559,14 @@ class Fractions(Schety):
self.base = 10
self.top_factor = 1
- def draw_rods_and_beads(self, x, y):
- ''' Draw the rods and beads: short column for 1/4 '''
+ def draw_rods_and_beads(self, x=None, y=None):
+ ''' Draw the rods and beads: short columns for fractions '''
+ if x is None:
+ x = self.rod_x
+ y = self.rod_y
+ else:
+ self.rod_x = x
+ self.rod_y = y
dx = (BEAD_WIDTH + BEAD_OFFSET) * self.abacus.scale
ro = (BEAD_WIDTH + 5) * self.abacus.scale / 2
bead_count = 0
@@ -1619,8 +1614,14 @@ class Caacupe(Fractions):
self.base = 10
self.top_factor = 1
- def draw_rods_and_beads(self, x, y):
- ''' Draw the rods and beads: short column for 1/4 '''
+ def draw_rods_and_beads(self, x=None, y=None):
+ ''' Draw the rods and beads: short columns for fractions '''
+ if x is None:
+ x = self.rod_x
+ y = self.rod_y
+ else:
+ self.rod_x = x
+ self.rod_y = y
dx = (BEAD_WIDTH + BEAD_OFFSET) * self.abacus.scale
ro = (BEAD_WIDTH + 5) * self.abacus.scale / 2
bead_count = 0
@@ -1668,8 +1669,14 @@ class Cuisenaire(Caacupe):
self.base = 10
self.top_factor = 1
- def draw_rods_and_beads(self, x, y):
- ''' Draw the rods and beads: short column for 1/4 '''
+ def draw_rods_and_beads(self, x=None, y=None):
+ ''' Draw the rods and beads: short columns for fractions '''
+ if x is None:
+ x = self.rod_x
+ y = self.rod_y
+ else:
+ self.rod_x = x
+ self.rod_y = y
dx = (BEAD_WIDTH + BEAD_OFFSET) * self.abacus.scale
ro = (BEAD_WIDTH + 5) * self.abacus.scale / 2
bead_count = 0
diff --git a/activity/activity.info b/activity/activity.info
index 1ca2544..ba08874 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -1,6 +1,6 @@
[Activity]
name = Abacus
-activity_version = 30.2
+activity_version = 30.3
license = GPLv3
bundle_id = org.sugarlabs.AbacusActivity
exec = sugar-activity AbacusActivity.AbacusActivity