[cairo-commit] pycairo/examples/gtk png_view.py,NONE,1.1

Steve Chaplin commit at pdx.freedesktop.org
Mon Apr 4 19:24:19 PDT 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/examples/gtk
In directory gabe:/tmp/cvs-serv3997/examples/gtk

Added Files:
	png_view.py 
Log Message:
SC 2005/04/05

--- NEW FILE: png_view.py ---
#!/usr/bin/env python
"""Display a png file
"""

import sys

import gtk
import cairo
import cairo.gtk

def expose_event(widget, event, surface):
    widget.window.clear()
    
    ctx = cairo.Context()
    tsurface = cairo.gtk.surface_create_for_window_with_visual(
        widget.window, widget.window.get_visual())
    ctx.set_target_surface (tsurface)

    ctx.show_surface(surface, Width, Height)


if len(sys.argv) != 2:
    raise SystemExit('usage: png_view.py png_file')

filename = sys.argv[1]

try:
    file_object = file(filename)
    surface, wh = cairo.Surface.create_for_png(file_object)
    Width, Height = wh
except Exception, exc:
    raise SystemExit(exc)

win = gtk.Window()
win.connect('destroy', lambda x: gtk.main_quit())
# TODO: fix seg fault on exit
# - problem with cairo.Surface.create_for_png(file_object) ref count?

drawingarea = gtk.DrawingArea()
win.add(drawingarea)
drawingarea.connect('expose_event', expose_event, surface)
drawingarea.set_size_request(Width,Height)
drawingarea.set_double_buffered(False)
    
win.show_all()
gtk.main()




More information about the cairo-commit mailing list