Added Slovenian translation
[tbo.git] / test / cairo1.py
1 #! /usr/bin/env python
2 import pygtk
3 pygtk.require('2.0')
4 import gtk, gobject, cairo
5
6 # Create a GTK+ widget on which we will draw using Cairo
7 class Screen(gtk.DrawingArea):
8
9     # Draw in response to an expose-event
10     __gsignals__ = { "expose-event": "override" }
11
12     # Handle the expose-event by drawing
13     def do_expose_event(self, event):
14
15         # Create the cairo context
16         cr = self.window.cairo_create()
17
18         # Restrict Cairo to the exposed area; avoid extra work
19         cr.rectangle(event.area.x, event.area.y,
20                 event.area.width, event.area.height)
21         cr.clip()
22
23         self.draw(cr, *self.window.get_size())
24
25     def draw(self, cr, width, height):
26         # Fill the background with gray
27         cr.set_source_rgb(0.5, 0.5, 0.5)
28         cr.rectangle(0, 0, width, height)
29         cr.fill()
30
31 # GTK mumbo-jumbo to show the widget in a window and quit when it's closed
32 def run(Widget):
33     window = gtk.Window()
34     window.connect("delete-event", gtk.main_quit)
35     widget = Widget()
36     widget.show()
37     window.add(widget)
38     window.present()
39     gtk.main()
40
41 if __name__ == "__main__":
42     run(Screen)