CairoPathGladeApp

This example requires SimpleGladeApp.py, don't forget to download it.

PathGladeApp.png

PathGladeApp.png

pathgladeapp.glade

PathGladeApp.py

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from SimpleGladeApp import SimpleGladeApp
import gtk
import cairo
import cairo.gtk

class PathGladeApp(SimpleGladeApp):

        def on_expose_event(self, area, event):
                self.ctx = cairo.Context()
                cairo.gtk.set_target_drawable(self.ctx, self.drawingarea1.window)
                width, height = self.drawingarea1.window.get_size()

                self.ctx.rectangle(0, 0, width, height)
                self.ctx.set_rgb_color(1, 1, 1)
                self.ctx.fill()

                self.ctx.scale(width/50.0, height/50.0)
                self.draw_path()

        def draw_path(self):
                self.ctx.move_to(10, 20)
                self.ctx.line_to(40, 20)
                self.ctx.curve_to(30, 35, 20, 35, 10, 20)
#               self.ctx.close_path()
                self.ctx.set_rgb_color(0, 0, 0)
                self.ctx.set_line_width(1.5)
#               self.ctx.save()
#               self.ctx.set_rgb_color(0.5, 0.2, 0.3)
#               self.ctx.fill()
#               self.ctx.restore()
                self.ctx.stroke()

app = PathGladeApp("pathgladeapp.glade")
app.run()