diff options
Diffstat (limited to 'drawing.py')
-rw-r--r-- | drawing.py | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -20,6 +20,7 @@ from gettext import gettext as _ import logging import gtk +import gobject import cairo @@ -28,6 +29,11 @@ STROKE_MAX_POINTS = 80 class Drawing(gtk.DrawingArea): + __gsignals__ = {'width-changed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + (gobject.TYPE_INT,)), + } + def __init__(self, parent): super(Drawing, self).__init__() @@ -63,15 +69,16 @@ class Drawing(gtk.DrawingArea): self.connect("motion-notify-event", self._motion_cb) self.connect("button-release-event", self._release_cb) - def setup(self, width, height): + def setup(self, width, height, clear=True): """Setup a blank canvas of specified size.""" logging.debug("drawing set up") - self._drawing_canvas = cairo.ImageSurface(cairo.FORMAT_ARGB32, - width, height) - context = cairo.Context(self._drawing_canvas) - context.rectangle(0, 0, width, height) - context.set_source_rgb(1.0, 1.0, 1.0) - context.fill() + if clear: + self._drawing_canvas = cairo.ImageSurface(cairo.FORMAT_ARGB32, + width, height) + context = cairo.Context(self._drawing_canvas) + context.rectangle(0, 0, width, height) + context.set_source_rgb(1.0, 1.0, 1.0) + context.fill() self.queue_draw() def set_sharing(self, share=True): @@ -93,6 +100,7 @@ class Drawing(gtk.DrawingArea): def set_stroke_width(self, width): self._settings['stroke width'] = width + self.emit('width-changed', width) def get_stroke_width(self): return self._settings['stroke width'] @@ -184,3 +192,14 @@ class Drawing(gtk.DrawingArea): # Get context from widget and paint: self._set_stroke_context(context) self._paint_stroke(context, self._stroke_points) + + def load_png(self, file_path): + logging.debug("reading from png") + self._drawing_canvas = cairo.ImageSurface.create_from_png(file_path) + self.setup(self._drawing_canvas.get_width(), + self._drawing_canvas.get_height(), + clear=False) + + def save_png(self, file_path): + logging.debug("writing to png") + self._drawing_canvas.write_to_png(file_path) |