#!/usr/bin/env python

import math

import cairo
import gtk

ARC = True
#ARC = False

def expose_event(widget, event):
    ctx = widget.window.cairo_create()

    width = widget.get_allocation().width
    height = widget.get_allocation().height

    ctx.set_source_rgb(0,0,1.0)

    if ARC:
        ctx.arc(width - 20, 20, 20, - math.pi / 2, 0);
        ctx.arc(width - 20, height - 20, 20, 0, math.pi / 2);
        ctx.arc(20, height - 20, 20, math.pi / 2, math.pi);
        ctx.arc(20, 20, 20, - math.pi, - math.pi / 2);
        ctx.close_path()
        ctx.fill()
    else:
        ctx.move_to(20,0)
        ctx.rel_line_to(width + 20, 0);
        ctx.rel_line_to(0, height + 20);
        ctx.rel_line_to(-(width + 20), 0);
        ctx.close_path()
        ctx.fill()

    ctx.move_to(40, 40)
    ctx.set_source_rgb(0,0,0)
    ctx.set_font_size(20)
    ctx.show_text('Hello World')

win = gtk.Window()
win.connect('destroy', gtk.main_quit)

drawingarea = gtk.DrawingArea()
win.add(drawingarea)
drawingarea.connect('expose_event', expose_event)
drawingarea.set_size_request(400,150)

win.show_all()
gtk.main()
