#! /usr/bin/python
# pyview 
"""
(c) 2005 Joao S. O Bueno Calligaris
This program is FreeSoftware 
You can:
1) use
2) distribute
3) change and incorporate in other Free Software
4) distribute changes
4) incorporate into proprietary and closed source programs IF and ONLY IF
due credits are given to the author (Joao S. O. Bueno Calligaris)


"""
import sys

def display (filename):
   """
   filename can either be an image filename or a PIL Image object.
   this function will load the Tkinter module and create a window with
   a single object displaying the image.
   The intention is to replace the obtuse "Image.show ()" method in PIL which
   loads an external (and non-Free) xv program.
   """
   import Tkinter
   import ImageTk
   import Image

   tk = Tkinter.Tk()
   if isinstance (filename, Image.Image):
       img = ImageTk.PhotoImage (filename)
   else:
       img = ImageTk.PhotoImage (file = filename)

   l = Tkinter.Label (tk, image = img)
   l.pack ()
   tk.mainloop ()

if __name__ == "__main__":
   if len (sys.argv) <= 2:
      for img_name in sys.argv[1:]:
          display (img_name)
   else:
      print "Use:  pyview image_file [image_file ...]"

