diff options
author | Walter Bender <walter@sugarlabs.org> | 2010-05-29 03:17:05 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2010-05-29 03:17:05 (GMT) |
commit | dde475272e425fb60a4357e32e968879ee33de38 (patch) | |
tree | 50d1ea02b03fc43f82355d9b7f274ae31ce3b730 | |
parent | cedd041a95c40f7948733bff6284d10d5107ff8d (diff) |
removed last precomputed SVG dependency
-rw-r--r-- | abacus_window.py | 65 | ||||
-rw-r--r-- | images/indicator.svg | 10 |
2 files changed, 40 insertions, 35 deletions
diff --git a/abacus_window.py b/abacus_window.py index 1427c2d..9ecc6b0 100644 --- a/abacus_window.py +++ b/abacus_window.py @@ -14,7 +14,7 @@ BWIDTH = 40 BHEIGHT = 30 BOFFSET = 10 -FSTROKE = 30 +FSTROKE = 60 import pygtk pygtk.require('2.0') @@ -56,6 +56,13 @@ def _svg_rect(w, h, rx, ry, x, y, fill, stroke): svg_string += _svg_style("fill:%s;stroke:%s;" % (fill, stroke)) return svg_string +def _svg_indicator(): + """ Returns a wedge-shaped indicator as SVG """ + svg_string = "%s %s" % ("<path d=\"m1.5 1.5 L 18.5 1.5 L 10 13.5 L 1.5", + "1.5 z\"\n") + svg_string += _svg_style("fill:#ff0000;stroke:#ff0000;stroke-width:3.0;") + return svg_string + def _svg_bead(fill, stroke): """ Returns a bead-shaped SVG object """ svg_string = "%s %s %s %s" % ("<path d=\"m1.5 15 A 15 13.5 90 0 1", @@ -202,10 +209,11 @@ class AbacusGeneric(): if self.top_beads > 0: self.frame_height = (self.bot_beads+self.top_beads+5)*BHEIGHT +\ FSTROKE*2 - dy = (self.top_beads+2)*BHEIGHT*self.abacus.scale + # dy = (self.top_beads+2)*BHEIGHT*self.abacus.scale + dy = (FSTROKE+((self.top_beads+1)*BHEIGHT))*self.abacus.scale else: self.frame_height = (self.bot_beads+2)*BHEIGHT + FSTROKE*2 - dy = -FSTROKE + dy = 0 rod_colors = ["#006ffe", "#007ee7", "#0082c4", "#0089ab", "#008c8b", "#008e68", "#008e4c", "#008900", "#5e7700", "#787000", "#876a00", "#986200", "#ab5600", "#d60000", "#e30038"] @@ -292,12 +300,13 @@ class AbacusGeneric(): self.bar.set_label_color('white') # and finally, the mark. + mark = _svg_header(20, 15, self.abacus.scale) +\ + _svg_indicator() +\ + _svg_footer() o = (BWIDTH+BOFFSET-(FSTROKE/2))*self.abacus.scale/2 self.mark = Sprite(self.abacus.sprites, x+(self.num_rods-1)*dx+o, y-(BHEIGHT-(FSTROKE/2))*self.abacus.scale, - load_image(self.abacus.path, "indicator", - 20*self.abacus.scale, - 15*self.abacus.scale)) + _svg_str_to_pixbuf(mark)) self.mark.type = 'mark' def hide(self): @@ -388,7 +397,7 @@ class AbacusGeneric(): v[r+1] += 1 if count_beads: - # Save the value associated with each rod as a 2-byte int. + # Save the value associated with each rod as a 2-byte integer. for j in v[1:]: string += "%2d" % (j) else: @@ -572,13 +581,14 @@ class Schety(AbacusGeneric): self.create() def create(self): - self.frame_width = self.num_rods*(BWIDTH+BOFFSET)+60 + self.frame_width = self.num_rods*(BWIDTH+BOFFSET)+(FSTROKE*2) if self.top_beads > 0: - self.frame_height = (self.bot_beads+self.top_beads+5)*BHEIGHT+60 + self.frame_height = (self.bot_beads+self.top_beads+5)*BHEIGHT +\ + (FSTROKE*2) dy = (self.top_beads+2)*BHEIGHT*self.abacus.scale else: - self.frame_height = (self.bot_beads+2)*BHEIGHT+60 - dy = -30 + self.frame_height = (self.bot_beads+2)*BHEIGHT+(FSTROKE*2) + dy = 0 rod_colors = ["#006ffe", "#007ee7", "#0082c4", "#0089ab", "#008c8b", "#008e68", "#008e4c", "#008900", "#5e7700", "#787000", "#876a00", "#986200", "#ab5600", "#d60000", "#e30038"] @@ -603,10 +613,11 @@ class Schety(AbacusGeneric): # Draw the frame... frame = _svg_header(self.frame_width, self.frame_height, self.abacus.scale) +\ - _svg_rect(self.frame_width, self.frame_height, 15, 15, 0, 0, - "#000000", "#000000") +\ - _svg_rect(self.frame_width-60, self.frame_height-60, 0, 0, - 30, 30, "#808080", "#000000") +\ + _svg_rect(self.frame_width, self.frame_height, (FSTROKE/2), + (FSTROKE/2), 0, 0, "#000000", "#000000") +\ + _svg_rect(self.frame_width-(FSTROKE*2), + self.frame_height-(FSTROKE*2), 0, 0, + FSTROKE, FSTROKE, "#808080", "#000000") +\ _svg_footer() self.frame = Sprite(self.abacus.sprites, x-BHEIGHT*self.abacus.scale, y-BHEIGHT*self.abacus.scale, @@ -620,8 +631,9 @@ class Schety(AbacusGeneric): bo = (BWIDTH-BOFFSET)*self.abacus.scale/4 ro = (BWIDTH+5)*self.abacus.scale/2 for i in range(self.num_rods): - rod = _svg_header(10, self.frame_height-60, self.abacus.scale) +\ - _svg_rect(10, self.frame_height-60, 0, 0, 0, 0, + rod = _svg_header(10, self.frame_height-(FSTROKE*2), + self.abacus.scale) +\ + _svg_rect(10, self.frame_height-(FSTROKE*2), 0, 0, 0, 0, rod_colors[(i+5)%len(rod_colors)], "#404040") +\ _svg_footer() self.rods.append(Sprite(self.abacus.sprites, x+i*dx+ro, @@ -651,8 +663,9 @@ class Schety(AbacusGeneric): i.state = 0 # Draw the dividing bar... - bar = _svg_header(self.frame_width-60, BHEIGHT, self.abacus.scale) +\ - _svg_rect(self.frame_width-60, BHEIGHT, 0, 0, 0, 0, + bar = _svg_header(self.frame_width-(FSTROKE*2), BHEIGHT, + self.abacus.scale) +\ + _svg_rect(self.frame_width-(FSTROKE*2), BHEIGHT, 0, 0, 0, 0, "#000000", "#000000") +\ _svg_footer() self.bar = Sprite(self.abacus.sprites, x, y+dy, @@ -662,12 +675,14 @@ class Schety(AbacusGeneric): self.bar.set_label_color('white') # and the mark. - o = (BWIDTH+BOFFSET-15)*self.abacus.scale/2 + # and finally, the mark. + mark = _svg_header(20, 15, self.abacus.scale) +\ + _svg_indicator() +\ + _svg_footer() + o = (BWIDTH+BOFFSET-(FSTROKE/2))*self.abacus.scale/2 self.mark = Sprite(self.abacus.sprites, x+(self.num_rods-1)*dx+o, - y-(BHEIGHT-15)*self.abacus.scale, - load_image(self.abacus.path, "indicator", - 20*self.abacus.scale, - 15*self.abacus.scale)) + y-(BHEIGHT-(FSTROKE/2))*self.abacus.scale, + _svg_str_to_pixbuf(mark)) self.mark.type = 'mark' def value(self, count_beads=False): @@ -795,7 +810,7 @@ class Schety(AbacusGeneric): o*BHEIGHT*self.abacus.scale)) self.beads[i+ii].state = 0 - +# Experimental code class Fractions(AbacusGeneric): def __init__(self, abacus): diff --git a/images/indicator.svg b/images/indicator.svg deleted file mode 100644 index d1786af..0000000 --- a/images/indicator.svg +++ /dev/null @@ -1,10 +0,0 @@ -<svg - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink" - version="1.1" - width="20.0" - height="15.0"> - <path d="m1.5 1.5 L 18.5 1.5 L 10 13.5 L 1.5 1.5 z" - style="fill:#ff0000;fill-opacity:1;stroke:#ff0000;stroke-width:3.0;stroke-opacity:1;" /> -</svg> |