diff options
author | Walter Bender <walter@sugarlabs.org> | 2010-04-08 00:40:46 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2010-04-08 00:40:46 (GMT) |
commit | d59025fac3d670b314c803773a2418765e28af2b (patch) | |
tree | c7b136b26074adc257504a935d4f31256c3bc58a | |
parent | 9a91d46bae8cbd7bfabb4fd1bbe112b18db04bd1 (diff) |
adding indicatorv4
-rw-r--r-- | abacus_window.py | 53 | ||||
-rw-r--r-- | images/indicator.svg | 10 |
2 files changed, 55 insertions, 8 deletions
diff --git a/abacus_window.py b/abacus_window.py index 04d6744..7e00abb 100644 --- a/abacus_window.py +++ b/abacus_window.py @@ -79,10 +79,14 @@ class Abacus(): def _button_press_cb(self, win, event): win.grab_focus() x, y = map(int, event.get_coords()) - self.dragpos = y self.press = self.sprites.find_sprite((x,y)) - if self.press is not None and self.press.type != 'bead': - self.press = None + if self.press is not None: + if self.press.type == 'bead': + self.dragpos = y + elif self.press.type == 'mark': + self.dragpos = x + else: + self.press = None return True def _mouse_move_cb(self, win, event): @@ -91,8 +95,11 @@ class Abacus(): return True win.grab_focus() x, y = map(int, event.get_coords()) - dy = y-self.dragpos - self.mode.move_bead(self.press, dy) + if self.press.type == 'bead': + self.mode.move_bead(self.press, y-self.dragpos) + elif self.press.type == 'mark': + mx, my = self.mode.mark.get_xy() + self.mode.move_mark(x-mx) def _button_release_cb(self, win, event): if self.press == None: @@ -174,7 +181,7 @@ class AbacusGeneric(): i.type = 'bead' i.state = 0 - # Draw the dividing bar on top. + # Draw the dividing bar... self.bar = Sprite(self.abacus.sprites, x, y+dy, load_image(self.abacus.path, "divider_bar", w, BHEIGHT*self.abacus.scale)) @@ -182,23 +189,34 @@ class AbacusGeneric(): self.bar.type = 'frame' self.bar.set_label_color('white') + # and the mark. + o = (BWIDTH+BOFFSET-15)*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)) + self.mark.type = 'mark' + def hide(self): - """ Hide the rod, beads and frame. """ + """ Hide the rod, beads, mark, and frame. """ for i in self.rods: i.hide() for i in self.beads: i.hide() self.bar.hide() self.frame.hide() + self.mark.hide() def show(self): - """ Show the rod, beads and frame. """ + """ Show the rod, beads, mark, and frame. """ self.frame.set_layer(99) for i in self.rods: i.set_layer(100) for i in self.beads: i.set_layer(101) self.bar.set_layer(102) + self.mark.set_layer(103) def set_value(self, string): """ Set abacus to value in string """ @@ -289,6 +307,17 @@ class AbacusGeneric(): """ Label the crossbar with the string. (Used with self.value) """ self.bar.set_label(string) + def move_mark(self, dx): + """ + if dx > 0: + dx = int(((dx+(BWIDTH+BOFFSET)/2*self.abacus.scale)/\ + (BWIDTH+BOFFSET))*(BWIDTH+BOFFSET)) + else: + dx = int(((dx-(BWIDTH+BOFFSET)/2*self.abacus.scale)/\ + (BWIDTH+BOFFSET))*(BWIDTH+BOFFSET)) + """ + self.mark.move_relative((dx, 0)) + def move_bead(self, bead, dy): """ Move a bead (or beads) up or down a rod. """ i = self.beads.index(bead) @@ -500,6 +529,14 @@ class Schety(AbacusGeneric): self.bar.type = 'frame' self.bar.set_label_color('white') + # and the mark. + 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)) + self.mark.type = 'mark' + def value(self, count_beads=False): """ Override to account for fourths """ string = '' diff --git a/images/indicator.svg b/images/indicator.svg new file mode 100644 index 0000000..d1786af --- /dev/null +++ b/images/indicator.svg @@ -0,0 +1,10 @@ +<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> |