diff options
author | Marco Pesenti Gritti <mpg@redhat.com> | 2006-05-22 02:21:42 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <mpg@redhat.com> | 2006-05-22 02:21:42 (GMT) |
commit | 67beb6298bf82155cb8f044e4af2474d2cabfb13 (patch) | |
tree | 60f3c9fcd3ea738fffb26e8621bc64e77a56f492 /sugar/chat/sketchpad | |
parent | 325fb8ff252e933aada3d6fccffa58e00c12f05b (diff) |
Merge
Diffstat (limited to 'sugar/chat/sketchpad')
-rw-r--r-- | sugar/chat/sketchpad/Sketch.py | 13 | ||||
-rw-r--r-- | sugar/chat/sketchpad/SketchPad.py | 10 | ||||
-rw-r--r-- | sugar/chat/sketchpad/Toolbox.py | 10 |
3 files changed, 25 insertions, 8 deletions
diff --git a/sugar/chat/sketchpad/Sketch.py b/sugar/chat/sketchpad/Sketch.py index 8c70f8d..3504b83 100644 --- a/sugar/chat/sketchpad/Sketch.py +++ b/sugar/chat/sketchpad/Sketch.py @@ -1,25 +1,27 @@ from SVGdraw import path class Sketch: - def __init__(self): + def __init__(self, rgb): self._points = [] + self._rgb = (float(rgb[0]), float(rgb[1]), float(rgb[2])) def add_point(self, x, y): - self._points.append([x, y]) + self._points.append((x, y)) def draw(self, ctx): start = True - for [x, y] in self._points: + for (x, y) in self._points: if start: ctx.move_to(x, y) start = False else: ctx.line_to(x, y) + ctx.set_source_rgb(self._rgb[0], self._rgb[1], self._rgb[2]) ctx.stroke() def draw_to_svg(self): i = 0 - for [x, y] in self._points: + for (x, y) in self._points: coords = str(x) + ' ' + str(y) + ' ' if i == 0: path_data = 'M ' + coords @@ -28,4 +30,5 @@ class Sketch: else: path_data += coords i += 1 - return path(path_data, fill = 'none', stroke = '#000000') + color = "#%02X%02X%02X" % (255 * self._rgb[0], 255 * self._rgb[1], 255 * self._rgb[2]) + return path(path_data, fill = 'none', stroke = color) diff --git a/sugar/chat/sketchpad/SketchPad.py b/sugar/chat/sketchpad/SketchPad.py index 9319378..d19ca40 100644 --- a/sugar/chat/sketchpad/SketchPad.py +++ b/sugar/chat/sketchpad/SketchPad.py @@ -13,6 +13,7 @@ class SketchPad(gtk.DrawingArea): gtk.DrawingArea.__init__(self) self._active_sketch = None + self._rgb = (0.0, 0.0, 0.0) self._sketches = [] self.add_events(gtk.gdk.BUTTON_PRESS_MASK | @@ -23,6 +24,7 @@ class SketchPad(gtk.DrawingArea): self.connect('expose_event', self.expose) def expose(self, widget, event): + """Draw the background of the sketchpad.""" rect = self.get_allocation() ctx = widget.window.cairo_create() @@ -38,6 +40,11 @@ class SketchPad(gtk.DrawingArea): return False + def set_color(self, color): + """Sets the current drawing color of the sketchpad. + color agument should be 3-item tuple of rgb values between 0 and 1.""" + self._rgb = color + def add_sketch(self, sketch): self._sketches.append(sketch) @@ -47,7 +54,7 @@ class SketchPad(gtk.DrawingArea): self.window.invalidate_rect(None, False) def __button_press_cb(self, widget, event): - self._active_sketch = Sketch() + self._active_sketch = Sketch(self._rgb) self.add_sketch(self._active_sketch) self.add_point(event) @@ -59,6 +66,7 @@ class SketchPad(gtk.DrawingArea): self.add_point(event) def to_svg(self): + """Return a string containing an SVG representation of this sketch.""" d = drawing() s = svg() for sketch in self._sketches: diff --git a/sugar/chat/sketchpad/Toolbox.py b/sugar/chat/sketchpad/Toolbox.py index bf56ccc..7ed814a 100644 --- a/sugar/chat/sketchpad/Toolbox.py +++ b/sugar/chat/sketchpad/Toolbox.py @@ -18,6 +18,9 @@ class ColorButton(gtk.RadioButton): self.add(drawing_area) drawing_area.show() + def color(self): + return self._rgb + def expose(self, widget, event): rect = widget.get_allocation() ctx = widget.window.cairo_create() @@ -31,7 +34,9 @@ class ColorButton(gtk.RadioButton): class Toolbox(gtk.VBox): __gsignals__ = { 'tool-selected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([gobject.TYPE_STRING])) + ([gobject.TYPE_STRING])), + 'color-selected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])) } def __init__(self): @@ -96,4 +101,5 @@ class Toolbox(gtk.VBox): self.emit("tool-selected", tool_id) def __color_clicked_cb(self, button, rgb): - pass + self.emit("color-selected", button.color()) + |