1
0
mirror of https://github.com/gryf/pygtktalog.git synced 2025-12-17 19:40:21 +01:00

* Imporved simple image viewer. Now it have scrollbar, when needed.

This commit is contained in:
2008-11-02 19:47:45 +00:00
parent e7b0288fc5
commit 301161926f

View File

@@ -30,11 +30,39 @@ class ImageView(object):
def __init__(self, image_filename): def __init__(self, image_filename):
window = gtk.Window(gtk.WINDOW_TOPLEVEL) window = gtk.Window(gtk.WINDOW_TOPLEVEL)
image = gtk.Image() image = gtk.Image()
image.set_from_file(image_filename) image.set_from_file(image_filename)
pixbuf = image.get_pixbuf()
pic_width = pixbuf.get_width() + 23
pic_height = pixbuf.get_height() + 23
screen_width = gtk.gdk.screen_width()
screen_height = gtk.gdk.screen_height()
need_vieport = False
if pic_height > (screen_height - 128):
height = screen_height - 128
need_vieport = True
else:
height = screen_height - 128
if pic_width > (screen_width - 128):
width = screen_width - 128
need_vieport = True
else:
width = pic_width
if need_vieport:
window.resize(width, height)
viewport = gtk.ScrolledWindow()
viewport.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
viewport.add_with_viewport(image)
window.add(viewport)
else:
window.add(image) window.add(image)
image.show() window.show_all()
window.show()
return return
pass # end of class pass # end of class