Monday, September 21, 2009

H2 Image Viewer (Python)










Here is the code:


import pygtk
pygtk.require('2.0')
import gtk
import Image

class ImageViewer:
global image
global button


def close_application(self, widget, event, data=None):
gtk.main_quit()
return False

def button_clicked(self, widget, data=None):
print "You are now viewing %s" % data

window1 = gtk.Window(gtk.WINDOW_TOPLEVEL)
window1.set_title(data)
window1.set_border_width(10)
window1.show()
image = gtk.Image()
image.set_from_file(data)
image.show()
window1.add(image)


def __init__(self):

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("delete_event", self.close_application)
window.set_title("H2 Image View 1.0")
window.set_border_width(10)
window.show()
hbox = gtk.HBox()
hbox.show()
window.add(hbox)

button = gtk.Button("Image 1")
button.show()
button.connect("clicked", self.button_clicked, "BioDome.jpg")
hbox.pack_start(button)

button = gtk.Button("Image 2")
button.show()
button.connect("clicked", self.button_clicked, "Cosmos.jpg")
hbox.pack_start(button)

button = gtk.Button("Image 3")
button.show()
button.connect("clicked", self.button_clicked, "Crucible.jpg")
hbox.pack_start(button)

button = gtk.Button("Image 4")
button.show()
button.connect("clicked", self.button_clicked, "EndlessBlue.jpg")
hbox.pack_start(button)

button = gtk.Button("Image 5")
button.show()
button.connect("clicked", self.button_clicked, "ForestLord.jpg")
hbox.pack_start(button)

button = gtk.Button("Image 6")
button.show()
button.connect("clicked", self.button_clicked, "HiddenFalls.tif")
hbox.pack_start(button)

button = gtk.Button("Image 7")
button.show()
button.connect("clicked", self.button_clicked, "OverSeer.tif")
hbox.pack_start(button)

button = gtk.Button("Image 8")
button.show()
button.connect("clicked", self.button_clicked, "Planitia.tif")
hbox.pack_start(button)

button = gtk.Button("Image 9")
button.show()
button.connect("clicked", self.button_clicked, "ThetisMoon.tif")
hbox.pack_start(button)


def main():
gtk.main()
return 0

if __name__ == "__main__":
ImageViewer()
main()

No comments:

Post a Comment