#! /usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk, gobject, cairo
import sys

# Create a GTK+ widget on which we will draw using Cairo
class Window(gtk.Window):

    # Draw in response to an expose-event
    __gsignals__ = { "expose-event": "override", "delete-event": "override" }

    # Handle the expose-event by drawing
    def do_expose_event(self, event):

        # Create the cairo context
        cr = self.window.cairo_create()

        # Restrict Cairo to the exposed area; avoid extra work
        cr.rectangle(event.area.x, event.area.y,
                event.area.width, event.area.height)
        cr.clip()

        self.draw(cr, *self.window.get_size())

    def do_delete_event(self, event):
        gtk.main_quit()
        
    def draw(self, cr, width, height):
        # Fill the background with gray
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.set_source_rgba(0.0, 0.5, 0.5, 0.5)
        cr.paint()

if __name__ == "__main__":
    screen = gtk.gdk.screen_get_default()
    print screen.get_rgba_visual()
    print screen.get_system_visual()
    window = Window()
    
    if len(sys.argv) > 1:
        window.set_colormap(screen.get_rgba_colormap())

    window.set_app_paintable(True)
    window.show()
    gtk.main()

