CurvesGladeApp

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

CurvesGladeApp.png

CurvesGladeApp.png

CurvesGladeApp.glade

CurvesGladeApp.py

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

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

class CurvesGladeApp(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.scale(width/100.0, height/100.0)

                self.ctx.set_rgb_color(1, 1, 1)
                self.ctx.rectangle(0, 0, 100, 100)
                self.ctx.fill()

                self.ctx.translate(-0.5, 0)
                self.draw_curve()
                self.draw_lines()

        def draw_curve(self):
                self.ctx.move_to(10, 50)
                self.ctx.curve_to(40, 90, 60, 10, 90, 50)
                self.ctx.set_rgb_color(0,0,0)
                self.ctx.set_line_width(3)
                self.ctx.stroke()

        def draw_lines(self):
                self.ctx.move_to(10, 50)
                self.ctx.line_to(40, 90)
                self.ctx.move_to(60, 10)
                self.ctx.line_to(90, 50)
                self.ctx.set_alpha(0.6)
                self.ctx.set_rgb_color(1, 0.2, 0.2)
                self.ctx.stroke()

app = CurvesGladeApp('CurvesGladeApp.glade')
app.run()