#!/usr/bin/env python

import gtk
import math

class Bar(gtk.DrawingArea):
    def __init__(self):
        gtk.DrawingArea.__init__(self)
        self.connect("expose_event", self.expose)
    
    def expose(self, widget, event):
        self.context = widget.window.cairo_create()
        
        # set a clip region for the expose event
        self.context.rectangle(event.area.x, event.area.y,
                               event.area.width, event.area.height)
        self.context.clip()

        self.draw(self.context)
        
        return False
        
    def draw(self, context):
        rect = self.get_allocation()
        
        print "width = {0}, height = {1}, x = {2}, y = {3}".format(rect.width,rect.height, rect.x, rect.y)
        
        context.rectangle(gtk.gdk.Rectangle(rect.x + rect.width/3,
                                            rect.y + 5,
                                            rect.width/3,
                                            rect.height - 10))
        context.set_source_rgba(0.0, 0.0, 0.0, 0.25)
        context.fill_preserve()
        context.set_source_rgba(0.0, 0.0, 0.0, 1.0)
        context.stroke()
        
def main():
    window = gtk.Window()
    window.set_default_size(200, 200)
    vbox = gtk.VBox()
    hbox = gtk.HBox()
    button = gtk.Button()
    bar = Bar()
    
    hbox.add(bar)
    hbox.add(button)
    vbox.add(hbox)
    window.add(vbox)
    window.connect("destroy", gtk.main_quit)
    window.show_all()
    
    window = gtk.Window()
    window.set_default_size(200, 200)
    vbox = gtk.VBox()
    hbox = gtk.HBox()
    button = gtk.Button()
    bar = Bar()
    
    hbox.add(button)
    hbox.add(bar)
    vbox.add(hbox)
    window.add(vbox)
    window.connect("destroy", gtk.main_quit)
    window.show_all()
    
    gtk.main()
    
if __name__ == "__main__":
    main()

