Get something basic working
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
||||
from SVGdraw import path
|
||||
|
||||
class Sketch:
|
||||
def __init__(self):
|
||||
self._points = []
|
||||
@@ -14,3 +16,16 @@ class Sketch:
|
||||
else:
|
||||
ctx.line_to(x, y)
|
||||
ctx.stroke()
|
||||
|
||||
def draw_to_svg(self):
|
||||
i = 0
|
||||
for [x, y] in self._points:
|
||||
coords = str(x) + ' ' + str(y) + ' '
|
||||
if i == 0:
|
||||
path_data = 'M ' + coords
|
||||
elif i == 1:
|
||||
path_data += 'L ' + coords
|
||||
else:
|
||||
path_data += coords
|
||||
i += 1
|
||||
return path(path_data, fill = 'none', stroke = '#000000')
|
||||
|
||||
@@ -5,6 +5,9 @@ import cairo
|
||||
|
||||
from Sketch import Sketch
|
||||
|
||||
from SVGdraw import drawing
|
||||
from SVGdraw import svg
|
||||
|
||||
class SketchPad(gtk.DrawingArea):
|
||||
def __init__(self):
|
||||
gtk.DrawingArea.__init__(self)
|
||||
@@ -42,7 +45,19 @@ class SketchPad(gtk.DrawingArea):
|
||||
if self._active_sketch:
|
||||
self._active_sketch.add_point(event.x, event.y)
|
||||
self.window.invalidate_rect(None, False)
|
||||
|
||||
|
||||
def to_svg(self):
|
||||
d = drawing()
|
||||
s = svg()
|
||||
for sketch in self._sketches:
|
||||
s.addElement(sketch.draw_to_svg())
|
||||
d.setSVG(s)
|
||||
return d.toXml()
|
||||
|
||||
def test_quit(w, sketchpad):
|
||||
print sketchpad.to_svg()
|
||||
gtk.main_quit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
window = gtk.Window()
|
||||
window.set_default_size(400, 300)
|
||||
@@ -54,4 +69,6 @@ if __name__ == "__main__":
|
||||
|
||||
window.show()
|
||||
|
||||
window.connect("destroy", test_quit, sketchpad)
|
||||
|
||||
gtk.main()
|
||||
|
||||
Reference in New Issue
Block a user