diff options
author | Sayamindu Dasgupta <sayamindu@gmail.com> | 2009-11-21 20:00:23 (GMT) |
---|---|---|
committer | Sayamindu Dasgupta <sayamindu@gmail.com> | 2009-11-21 20:00:23 (GMT) |
commit | 8ec0e742ee265879a5ada93f01b183ea09c79d03 (patch) | |
tree | d2dae1d152cf7992a231d8da6551b8df3653a808 | |
parent | 5bd36be1e7ca5f5f5bff44887e6f736ba5f63b93 (diff) |
Implement erase support
-rw-r--r-- | icons/tool-eraser.svg | 18 | ||||
-rw-r--r-- | scribbleactivity.py | 16 | ||||
-rw-r--r-- | scribblewidget.py | 17 |
3 files changed, 49 insertions, 2 deletions
diff --git a/icons/tool-eraser.svg b/icons/tool-eraser.svg new file mode 100644 index 0000000..41fc143 --- /dev/null +++ b/icons/tool-eraser.svg @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="55px"
+ height="55px" viewBox="0 0 55 55" enable-background="new 0 0 55 55" xml:space="preserve">
+
+<g id="Eraser" >
+ <g display="inline">
+ <path fill="#FFFFFF" d="M15.621,33.853c-1.1,0-1.424-0.691-0.721-1.536l14.249-17.109c0.704-0.845,2.18-1.537,3.28-1.537h7.805
+ c1.1,0,1.424,0.691,0.721,1.537L26.706,32.316c-0.704,0.845-2.18,1.536-3.28,1.536H15.621z"/>
+ <path fill="#FFFFFF" d="M24.709,41.155c-0.166,1.088-1.2,1.978-2.301,1.978h-8.525c-1.1,0-1.865-0.89-1.7-1.978l0.549-3.62
+ c0.165-1.088,1.2-1.978,2.3-1.978h8.525c1.101,0,1.865,0.89,1.701,1.978L24.709,41.155z"/>
+ <path fill="#FFFFFF" d="M40.446,23.333c-0.189,1.083-0.921,2.662-1.625,3.507L27.471,40.467c-0.705,0.846-1.125,0.65-0.936-0.434
+ l0.646-3.688c0.19-1.083,0.921-2.661,1.626-3.506l11.35-13.627c0.705-0.845,1.125-0.65,0.936,0.434L40.446,23.333z"/>
+ </g>
+</g>
+
+</svg>
diff --git a/scribbleactivity.py b/scribbleactivity.py index f1e69fd..20e51cb 100644 --- a/scribbleactivity.py +++ b/scribbleactivity.py @@ -66,10 +66,22 @@ class ScribbleActivity(Activity): rectbtn.connect('toggled', self._rect_cb) rectbtn.set_group(circlebtn) + sep = gtk.SeparatorToolItem() + sep.set_expand(False) + sep.set_draw(True) + + erasebtn = sugar.graphics.radiotoolbutton.RadioToolButton() + erasebtn.set_named_icon('tool-eraser') + erasebtn.set_tooltip(_("Erase")) + erasebtn.connect('toggled', self._erase_cb) + erasebtn.set_group(rectbtn) + toolbar = gtk.Toolbar() toolbar.insert(pencilbtn, -1) toolbar.insert(circlebtn, -1) toolbar.insert(rectbtn, -1) + toolbar.insert(sep, -1) + toolbar.insert(erasebtn, -1) sep = gtk.SeparatorToolItem() sep.set_expand(True) @@ -122,6 +134,10 @@ class ScribbleActivity(Activity): if button.props.active: self._scribblewidget.set_tool('rect') + def _erase_cb(self, button): + if button.props.active: + self._scribblewidget.set_tool('eraser') + def export(self, file_path, mimetype, options): window = self._scribblewidget.window width, height = window.get_size() diff --git a/scribblewidget.py b/scribblewidget.py index 3406890..5932a60 100644 --- a/scribblewidget.py +++ b/scribblewidget.py @@ -93,6 +93,8 @@ class ScribbleWidget(goocanvas.Canvas): self.item = goocanvas.Polyline(parent=self._root, \ points=goocanvas.Points(self.line_points), \ stroke_color_rgba = self._stroke_color, title=self.item_id) + elif self.tool == 'eraser': + self.item = self.get_item_at(x, y, True) else: pass @@ -121,6 +123,10 @@ class ScribbleWidget(goocanvas.Canvas): self.item.props.points = goocanvas.Points(self.line_points) self.item_orig_x = x self.item_orig_y = y + elif self.tool == 'eraser': + self.item = self.get_item_at(x, y, True) + else: + pass self.prev_time = time @@ -130,7 +136,7 @@ class ScribbleWidget(goocanvas.Canvas): def get_cmd_list(self): return self.cmd_list - def process_item_finalize(self): + def process_item_finalize(self, x, y): if self.tool == 'circle': self.cmd = "goocanvas.Ellipse(parent=self._root, center_x=%d, \ center_y=%d, radius_x = %d, radius_y = %d, \ @@ -151,6 +157,13 @@ class ScribbleWidget(goocanvas.Canvas): points=goocanvas.Points(%s), stroke_color_rgba = %d, \ title = '%s')" % (str(self.line_points), self._stroke_color, \ self.item_id) + elif self.tool == 'eraser': + if self.item is not None: + self.item.remove() + # Maybe we can use the item title (uuid) and use it instead + self.cmd = "self.get_item_at(%f, %f, True).remove()" % (x, y) + else: + pass #print self.cmd @@ -182,7 +195,7 @@ class ScribbleWidget(goocanvas.Canvas): def on_button_release(self, canvas, event): canvas.pointer_ungrab(self.item, event.time) - self.process_item_finalize() + self.process_item_finalize(event.x, event.y) return True def on_motion(self, canvas, event): |