[cairo-commit] [cairo-www] src/gdkpixbufpycairo.mdwn

Carl Worth cworth at freedesktop.org
Tue Jul 10 22:13:43 PDT 2007


 src/gdkpixbufpycairo.mdwn |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

New commits:
commit c68a51d9a7676625dfb5c92c8c05d4f26382fd4b
Author: frob <frob at df.ru>
Date:   Tue Jul 10 22:13:42 2007 -0700

    pycairo/pygtk recipe for not-only-png image loading

diff --git a/src/gdkpixbufpycairo.mdwn b/src/gdkpixbufpycairo.mdwn
new file mode 100644
index 0000000..87a67fa
--- /dev/null
+++ b/src/gdkpixbufpycairo.mdwn
@@ -0,0 +1,46 @@
+[[meta title="Loading images"]]
+Back to [[cookbook]]
+
+Based on the cworth recipe.
+Loads file in any gdk-pixbuf supported format (look into your gdk-pixbuf.loaders or run 'gdk-pixbuf-query-loaders | grep gtk20').
+Can be used as a very primitive image viewer.
+
+    #!/usr/bin/env python
+    import sys
+    import gtk
+    import cairo
+
+    def expose (da, event, pixbuf):
+      ctx = da.window.cairo_create()
+      # You can put ctx.scale(..) or ctx.rotate(..) here, if you need some
+      ct = gtk.gdk.CairoContext(ctx)
+      ct.set_source_pixbuf(pixbuf,0,0)
+      ctx.paint()
+      ctx.stroke()
+
+    def main():
+      filename = sys.argv[1]
+      input = open(filename)
+      imagebuf = input.read()
+      pixbufloader = gtk.gdk.PixbufLoader()
+      pixbufloader.write(imagebuf)
+      pixbufloader.close()
+      pixbuf = pixbufloader.get_pixbuf()
+      imgw=pixbuf.get_width()
+      imgh=pixbuf.get_height()
+      win = gtk.Window()
+      win.connect('destroy', gtk.main_quit)
+      win.set_default_size(imgw, imgh)
+      da = gtk.DrawingArea()
+      win.add(da)
+      da.connect('expose_event', expose, pixbuf)
+      win.show_all()
+      gtk.main()
+
+    if __name__ == '__main__':
+      if len(sys.argv) != 2:
+        program = sys.argv[0]
+        print program +':', 'usage:', program, '<filename>'
+        sys.exit(0)
+      else:
+        main()
\ No newline at end of file


More information about the cairo-commit mailing list