| 1 |
|
| 2 |
"""Display a png file |
| 3 |
""" |
| 4 |
|
| 5 |
import sys |
| 6 |
|
| 7 |
import cairo |
| 8 |
import gi |
| 9 |
gi.require_version("Gtk", "3.0") |
| 10 |
from gi.repository import Gtk |
| 11 |
|
| 12 |
|
| 13 |
def draw_event(widget, ctx, surface): |
| 14 |
ctx.set_source_surface(surface, 0, 0) |
| 15 |
ctx.paint() |
| 16 |
|
| 17 |
|
| 18 |
if len(sys.argv) != 2: |
| 19 |
raise SystemExit('usage: png_view.py png_file') |
| 20 |
|
| 21 |
filename = sys.argv[1] |
| 22 |
|
| 23 |
surface = cairo.ImageSurface.create_from_png(filename) |
| 24 |
width = surface.get_width() |
| 25 |
height = surface.get_height() |
| 26 |
|
| 27 |
win = Gtk.Window() |
| 28 |
win.connect('destroy', Gtk.main_quit) |
| 29 |
|
| 30 |
drawingarea = Gtk.DrawingArea() |
| 31 |
win.add(drawingarea) |
| 32 |
drawingarea.connect('draw', draw_event, surface) |
| 33 |
drawingarea.set_size_request(width, height) |
| 34 |
|
| 35 |
win.show_all() |
| 36 |
Gtk.main() |