File: image-viewer.py

package info (click to toggle)
gnome-devel-docs 40.3-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 79,188 kB
  • sloc: javascript: 2,514; xml: 2,407; ansic: 2,229; python: 1,854; makefile: 805; sh: 499; cpp: 131
file content (51 lines) | stat: -rwxr-xr-x 1,163 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python

from gi.repository import Gtk, GdkPixbuf, Gdk
import os, sys

class GUI:
	image = 0

	def __init__(self):

		window = Gtk.Window()
		window.set_title ("Image Viewer")
		window.connect_after('destroy', self.destroy)

		box = Gtk.Box()
		box.set_spacing(5)
		box.set_orientation (Gtk.Orientation.VERTICAL)
		window.add (box)

		self.image = Gtk.Image()
		box.pack_start (self.image, True, True, 0)

		button = Gtk.Button ("Open a picture...")
		box.pack_start (button, False, False, 0)
		button.connect_after('clicked', self.on_open_clicked)

		window.show_all()

	def destroy(window, self):
		Gtk.main_quit()

	def on_open_clicked (self, button):
		dialog = Gtk.FileChooserDialog ("Open Image", button.get_toplevel(), Gtk.FileChooserAction.OPEN);
		dialog.add_button (Gtk.STOCK_CANCEL, 0)
		dialog.add_button (Gtk.STOCK_OPEN, 1)
		dialog.set_default_response(1)

		filefilter = Gtk.FileFilter ()
		filefilter.add_pixbuf_formats ()
		dialog.set_filter(filefilter)

		if dialog.run() == 1:
			self.image.set_from_file(dialog.get_filename())
		dialog.destroy()

def main():
	app = GUI()
	Gtk.main()

if __name__ == "__main__":
    sys.exit(main())