#!/usr/bin/env python

import gtk

# This function will be called whenever you click on the button:
def click_handler(widget) :
    # quit the application:
    gtk.main_quit()

# This function will be called whenever the drawing area is exposed:
def expose_handler(widget, event) :
    w, h = widget.window.get_size()
    xgc = widget.window.new_gc()

    xgc.set_rgb_fg_color(gtk.gdk.color_parse("yellow"))
    widget.window.draw_arc(xgc, True, 200, 100, 200, 200, 0, 360*64)
    xgc.set_rgb_fg_color(gtk.gdk.Color(0, 0, 0))             # black
    widget.window.draw_arc(xgc, True, 240, 145, 30, 40, 0, 360*64)
    widget.window.draw_arc(xgc, True, 330, 145, 30, 40, 0, 360*64)
    xgc.line_width = 6
    widget.window.draw_arc(xgc, False, 240, 150, 120, 110, 200*64, 140*64)

def button_event(widget, event) :
    print "Click!"

# Create the main window:
win = gtk.Window()
vbox = gtk.VBox()
win.add(vbox)

# Create the drawing area
drawing_area = gtk.DrawingArea()
drawing_area.set_size_request(600, 400)
vbox.pack_start(drawing_area)

# and set up signals for it:
drawing_area.connect("expose-event", expose_handler)
drawing_area.connect("button-release-event", button_event)
drawing_area.set_events(gtk.gdk.EXPOSURE_MASK |
#
# APPARENT BUG: button-release-event doesn't fire unless BUTTON_PRESS_MASK
# and BUTTON_RELEASE_MASK are both set. Try it with the next line either
# commented or uncommented:
#                        gtk.gdk.BUTTON_PRESS_MASK |
                        gtk.gdk.BUTTON_RELEASE_MASK )

drawing_area.show()

button = gtk.Button("Quit")
button.connect("clicked", click_handler)
vbox.pack_start(button)
button.show()
win.connect("destroy", gtk.main_quit)

vbox.show()
win.show()
gtk.main()

