Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/snippet.py
diff options
context:
space:
mode:
Diffstat (limited to 'snippet.py')
-rwxr-xr-xsnippet.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/snippet.py b/snippet.py
new file mode 100755
index 0000000..e3e5a2e
--- /dev/null
+++ b/snippet.py
@@ -0,0 +1,42 @@
+#! /usr/bin/env python
+import pygtk
+pygtk.require('2.0')
+import gtk, gobject, cairo
+
+# Create a GTK+ widget on which we will draw using Cairo
+class Screen(gtk.DrawingArea):
+
+ # Draw in response to an expose-event
+ __gsignals__ = { "expose-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 draw(self, cr, width, height):
+ # Fill the background with gray
+ cr.set_source_rgb(0.5, 0.5, 0.5)
+ cr.rectangle(0, 0, width, height)
+ cr.fill()
+
+# GTK mumbo-jumbo to show the widget in a window and quit when it's closed
+def run(Widget):
+ window = gtk.Window()
+ window.connect("delete-event", gtk.main_quit)
+ widget = Widget()
+ widget.show()
+ window.add(widget)
+ window.present()
+ gtk.main()
+
+if __name__ == "__main__":
+ run(Screen)