This commit is contained in:
Marco Pesenti Gritti
2006-05-21 22:21:42 -04:00
parent 325fb8ff25
commit 67beb6298b
7 changed files with 133 additions and 25 deletions
+8 -5
View File
@@ -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)
+9 -1
View File
@@ -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:
+8 -2
View File
@@ -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())