diff options
author | Walter Bender <walter@sugarlabs.org> | 2010-05-28 14:53:05 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2010-05-28 14:53:05 (GMT) |
commit | cedd041a95c40f7948733bff6284d10d5107ff8d (patch) | |
tree | 6136ac45e3eaf8b5d2339978d74934a12613a025 | |
parent | c29a828f42befa3de00ed90ef9e7d0156d63cafb (diff) |
no need for sep. constants file; no need for schety svg
-rw-r--r-- | abacus_window.py | 118 | ||||
-rw-r--r-- | constants.py | 19 | ||||
-rw-r--r-- | images/schety_bar.svg | 15 | ||||
-rw-r--r-- | images/schety_frame.svg | 131 |
4 files changed, 72 insertions, 211 deletions
diff --git a/abacus_window.py b/abacus_window.py index 715d77d..1427c2d 100644 --- a/abacus_window.py +++ b/abacus_window.py @@ -11,7 +11,10 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -from constants import BHEIGHT, BWIDTH, BOFFSET +BWIDTH = 40 +BHEIGHT = 30 +BOFFSET = 10 +FSTROKE = 30 import pygtk pygtk.require('2.0') @@ -53,13 +56,6 @@ 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_line(x1, y1, x2, y2): - """ Returns an SVG line """ - svg_string = "<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\"\n" % \ - (x1, y1, x2, y2) - svg_string += _svg_style("stroke-width:1.5;stroke-linecap:round;") - 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", @@ -134,8 +130,8 @@ class Abacus(): self.chinese = Suanpan(self) self.japanese = Soroban(self) - # self.russian = Schety(self) - self.russian = Fractions(self) + self.russian = Schety(self) + # self.russian = Fractions(self) self.mayan = Nepohualtzintzin(self) self.chinese.show() @@ -194,16 +190,22 @@ class AbacusGeneric(): def __init__(self, abacus): """ Specify parameters that define the abacus """ self.abacus = abacus - self.name = 'suanpan' + self.name = "suanpan" self.num_rods = 15 self.bot_beads = 2 self.top_beads = 5 - self.frame_width = 810 - self.frame_height = 420 self.base = 10 self.create() def create(self): + 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 +\ + FSTROKE*2 + dy = (self.top_beads+2)*BHEIGHT*self.abacus.scale + else: + self.frame_height = (self.bot_beads+2)*BHEIGHT + FSTROKE*2 + dy = -FSTROKE rod_colors = ["#006ffe", "#007ee7", "#0082c4", "#0089ab", "#008c8b", "#008e68", "#008e4c", "#008900", "#5e7700", "#787000", "#876a00", "#986200", "#ab5600", "#d60000", "#e30038"] @@ -228,7 +230,6 @@ class AbacusGeneric(): rod_h = (self.bot_beads+2+1+self.top_beads+2)*BHEIGHT*self.abacus.scale w = (self.num_rods+1)*(BWIDTH+BOFFSET)*self.abacus.scale dx = (BWIDTH+BOFFSET)*self.abacus.scale - dy = (self.top_beads+2)*BHEIGHT*self.abacus.scale x = (self.abacus.width-w)/2 y = (self.abacus.height-rod_h)/2 o = (BWIDTH+BOFFSET-5)*self.abacus.scale/2 @@ -236,10 +237,11 @@ class 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, @@ -253,8 +255,9 @@ class 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%len(rod_colors)], "#404040") +\ _svg_footer() self.rods.append(Sprite(self.abacus.sprites, x+i*dx+ro, @@ -277,8 +280,9 @@ class AbacusGeneric(): i.level = 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, @@ -288,9 +292,9 @@ class AbacusGeneric(): self.bar.set_label_color('white') # and finally, the mark. - o = (BWIDTH+BOFFSET-15)*self.abacus.scale/2 + 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, + y-(BHEIGHT-(FSTROKE/2))*self.abacus.scale, load_image(self.abacus.path, "indicator", 20*self.abacus.scale, 15*self.abacus.scale)) @@ -485,8 +489,6 @@ class Nepohualtzintzin(AbacusGeneric): self.num_rods = 13 self.bot_beads = 4 self.top_beads = 3 - self.frame_width = 715 - self.frame_height = 420 self.base = 20 self.create() @@ -523,6 +525,7 @@ class Nepohualtzintzin(AbacusGeneric): tens = v[len(v)-j-1]-units v[len(v)-j-1] = units v[len(v)-j-2] += tens/10 + # Convert values to a string. for j in v: if string != '' or j > 0: @@ -535,12 +538,10 @@ class Suanpan(AbacusGeneric): def __init__(self, abacus): """ Create a Chinese abacus: 15 by (5,2). """ self.abacus = abacus - self.name = "suanpan" + self.name = 'saunpan' self.num_rods = 15 self.bot_beads = 5 self.top_beads = 2 - self.frame_width = 810 - self.frame_height = 420 self.base = 10 self.create() @@ -550,12 +551,10 @@ class Soroban(AbacusGeneric): def __init__(self, abacus): """ create a Japanese abacus: 15 by (4,1) """ self.abacus = abacus - self.name = "soroban" + self.name = 'soroban' self.num_rods = 15 self.bot_beads = 4 self.top_beads = 1 - self.frame_width = 810 - self.frame_height = 360 self.base = 10 self.create() @@ -569,18 +568,27 @@ class Schety(AbacusGeneric): self.num_rods = 15 self.top_beads = 0 self.bot_beads = 10 - self.frame_width = 810 - self.frame_height = 420 self.base = 10 self.create() def create(self): + self.frame_width = self.num_rods*(BWIDTH+BOFFSET)+60 + if self.top_beads > 0: + self.frame_height = (self.bot_beads+self.top_beads+5)*BHEIGHT+60 + dy = (self.top_beads+2)*BHEIGHT*self.abacus.scale + else: + self.frame_height = (self.bot_beads+2)*BHEIGHT+60 + dy = -30 + rod_colors = ["#006ffe", "#007ee7", "#0082c4", "#0089ab", "#008c8b", + "#008e68", "#008e4c", "#008900", "#5e7700", "#787000", + "#876a00", "#986200", "#ab5600", "#d60000", "#e30038"] + """ Override default in order to make a short rod """ white = _svg_header(BWIDTH, BHEIGHT, self.abacus.scale) +\ _svg_bead("#ffffff", "#000000") +\ _svg_footer() black = _svg_header(BWIDTH, BHEIGHT, self.abacus.scale) +\ - _svg_bead("#ffffcc", "#000000") +\ + _svg_bead("#000000", "#000000") +\ _svg_footer() self.white = _svg_str_to_pixbuf(white) self.black = _svg_str_to_pixbuf(black) @@ -592,19 +600,33 @@ class Schety(AbacusGeneric): x = (self.abacus.width-w)/2 y = (self.abacus.height-rod_h)/2 - # Draw the frame. + # 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_footer() self.frame = Sprite(self.abacus.sprites, x-BHEIGHT*self.abacus.scale, y-BHEIGHT*self.abacus.scale, - load_image(self.abacus.path, self.name+"_frame", - self.frame_width*self.abacus.scale, - self.frame_height*self.abacus.scale)) + _svg_str_to_pixbuf(frame)) self.frame.type = 'frame' # and then the beads. self.beads = [] self.rods = [] o = (BWIDTH-BOFFSET)/2*self.abacus.scale/2 + 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_colors[(i+5)%len(rod_colors)], "#404040") +\ + _svg_footer() + self.rods.append(Sprite(self.abacus.sprites, x+i*dx+ro, + y, + _svg_str_to_pixbuf(rod))) if i == 10: for b in range(4): if b in [1,2]: @@ -628,10 +650,13 @@ class Schety(AbacusGeneric): i.type = 'bead' i.state = 0 - # Draw a bar for the label on top. - self.bar = Sprite(self.abacus.sprites, x, y-BHEIGHT*self.abacus.scale, - load_image(self.abacus.path, self.name+"_bar", - w, BHEIGHT*self.abacus.scale)) + # 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, + "#000000", "#000000") +\ + _svg_footer() + self.bar = Sprite(self.abacus.sprites, x, y+dy, + _svg_str_to_pixbuf(bar)) self.bar.type = 'frame' self.bar.set_label_color('white') @@ -785,9 +810,6 @@ class Fractions(AbacusGeneric): self.frame_width = 810 self.frame_height = 420 self.base = 10 - self.white = load_image(self.abacus.path, "white", - BWIDTH*self.abacus.scale, - BHEIGHT*self.abacus.scale) self.create() def create(self): @@ -808,6 +830,10 @@ class Fractions(AbacusGeneric): self.frame.type = 'frame' # and then the beads. + white = _svg_header(BWIDTH, BHEIGHT, self.abacus.scale) +\ + _svg_bead("#ffffff", "#000000") +\ + _svg_footer() + self.white = _svg_str_to_pixbuf(white) self.beads = [] self.rods = [] o = (BWIDTH-BOFFSET)/2*self.abacus.scale/2 diff --git a/constants.py b/constants.py deleted file mode 100644 index 0f5c6e7..0000000 --- a/constants.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- - -#Copyright (c) 2010, Walter Bender - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -BWIDTH = 40 -BHEIGHT = 30 -BOFFSET = 10 - - diff --git a/images/schety_bar.svg b/images/schety_bar.svg deleted file mode 100644 index 0c89eec..0000000 --- a/images/schety_bar.svg +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - version="1.1" - width="750" - height="30" - id="svg2"> - <rect - width="750" - height="30" - x="0" - y="0" - style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:3;stroke-opacity:1" /> -</svg> diff --git a/images/schety_frame.svg b/images/schety_frame.svg deleted file mode 100644 index fad7315..0000000 --- a/images/schety_frame.svg +++ /dev/null @@ -1,131 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- Created with Inkscape (http://www.inkscape.org/) --> - -<svg - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - version="1.1" - width="810" - height="420" - id="svg2"> - <defs - id="defs6" /> - <g - transform="translate(749.99997,3.8146973e-6)" - id="g4093"> - <rect - width="10" - height="360" - x="-199.99997" - y="29.999996" - id="rect2881-68" - style="fill:#006ffe;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="-149.99997" - y="29.999996" - id="rect2881-7-9" - style="fill:#007ee7;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="-99.999969" - y="29.999996" - id="rect2881-6-2" - style="fill:#0082c4;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="-49.999969" - y="29.999996" - id="rect2881-7-5-6" - style="fill:#0089ab;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="3.1629916e-05" - y="29.999996" - id="rect2881-69-6" - style="fill:#008c8b;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - </g> - <rect - width="10" - height="360" - x="50.000031" - y="30" - id="rect2881-7-3-49" - style="fill:#008e68;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="100.00005" - y="30" - id="rect2881-6-7-5" - style="fill:#008e4c;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="150.00003" - y="30" - id="rect2881-7-5-4-04" - style="fill:#008900;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="200.00003" - y="30" - id="rect2881-7-52-8" - style="fill:#5e7700;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="250.00006" - y="30" - id="rect2881-6-5-7" - style="fill:#787000;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="300.00003" - y="30" - id="rect2881-7-5-47-1" - style="fill:#876a00;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="350.00003" - y="30" - id="rect2881-69-4-7" - style="fill:#986200;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="400.00003" - y="30" - id="rect2881-7-3-4-2" - style="fill:#ab5600;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="450.00003" - y="30" - id="rect2881-6-7-3-7" - style="fill:#d60000;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="10" - height="360" - x="500.00003" - y="30" - id="rect2881-7-5-4-0-2" - style="fill:#e30038;fill-opacity:1;stroke:#404040;stroke-width:3;stroke-opacity:1" /> - <rect - width="780" - height="390" - rx="17.169811" - ry="15.457319" - x="15" - y="15" - id="rect2818" - style="fill:none;stroke:#000000;stroke-width:30;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> -</svg> |