Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2010-06-05 15:11:42 (GMT)
committer Walter Bender <walter@sugarlabs.org>2010-06-05 15:11:42 (GMT)
commit5ab5a63f9a553bbab9a366a890feb2e55790fe1a (patch)
tree1bee7faf6460a4b81cc9ceab8a4a622fc7427a7b
parent298ecfb824c9639f3ec159430167c173e5496129 (diff)
showing sum of rods in label as per Tuukkah's suggestion
-rw-r--r--abacus_window.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/abacus_window.py b/abacus_window.py
index 4144157..54c39cb 100644
--- a/abacus_window.py
+++ b/abacus_window.py
@@ -177,6 +177,7 @@ class Bead():
self.level = level
def update_label(self):
+ """ Label active beads """
value = self.get_value()
if self.state == 1 and value < 10000 and value > 0.05:
value = self.get_value()
@@ -267,7 +268,9 @@ class Abacus():
if self.press == None:
return True
self.press = None
- self.mode.label(self.mode.value())
+ # self.mode.label(self.mode.value())
+ self.mode.label(" + ".join([str(x) for x in self.mode.rod_values()])+\
+ " = "+self.mode.value())
return True
def _expose_cb(self, win, event):
@@ -581,6 +584,16 @@ class AbacusGeneric():
self.beads[i+ii].set_color(self.colors[3])
self.beads[i+ii].move_down()
+ def rod_values(self):
+ """ Return the sum of the values per rod as an array """
+ v = [0] * (self.num_rods + 1)
+
+ for i, bead in enumerate(self.beads):
+ r = i/(self.top_beads+self.bot_beads)
+ v[r+1] += bead.get_value()
+
+ return v[1:]
+
class Custom(AbacusGeneric):
""" A custom-made abacus """
@@ -764,7 +777,7 @@ class Schety(AbacusGeneric):
print "bead not found"
return
- # Find out which row i corresponds to
+ # Find out which rod i corresponds to
count = 0
for r in range(len(self.bead_count)):
count += self.bead_count[r]
@@ -788,6 +801,20 @@ class Schety(AbacusGeneric):
if self.beads[i+ii].get_state() == 1:
self.beads[i+ii].move_down()
+ def rod_values(self):
+ """ Return the sum of the values per rod as an array """
+ v = [0] * (self.num_rods + 1)
+
+ for i, bead in enumerate(self.beads):
+ count = 0
+ for r in range(len(self.bead_count)):
+ count += self.bead_count[r]
+ if i < count:
+ break
+ v[r+1] += bead.get_value()
+
+ return v[1:]
+
class Fractions(Schety):
""" Inherit from Russian abacus. """