2013-04-21 10:38:36 +04:00
|
|
|
#!/usr/bin/env python
|
2010-07-31 06:52:47 +04:00
|
|
|
#
|
|
|
|
# The Python Imaging Library
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
|
2012-10-16 06:27:35 +04:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2017-03-24 11:42:58 +03:00
|
|
|
import sys
|
|
|
|
|
|
|
|
if sys.version_info[0] > 2:
|
|
|
|
import tkinter
|
|
|
|
else:
|
|
|
|
import Tkinter as tkinter
|
2012-10-17 06:58:29 +04:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
from PIL import Image, ImageTk
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# an image animation player
|
|
|
|
|
2017-03-24 11:42:58 +03:00
|
|
|
class UI(tkinter.Label):
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
def __init__(self, master, im):
|
2012-10-17 07:39:56 +04:00
|
|
|
if isinstance(im, list):
|
2010-07-31 06:52:47 +04:00
|
|
|
# list of images
|
|
|
|
self.im = im[1:]
|
|
|
|
im = self.im[0]
|
|
|
|
else:
|
|
|
|
# sequence
|
|
|
|
self.im = im
|
|
|
|
|
|
|
|
if im.mode == "1":
|
|
|
|
self.image = ImageTk.BitmapImage(im, foreground="white")
|
|
|
|
else:
|
|
|
|
self.image = ImageTk.PhotoImage(im)
|
|
|
|
|
2017-03-24 11:42:58 +03:00
|
|
|
tkinter.Label.__init__(self, master, image=self.image, bg="black", bd=0)
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
self.update()
|
|
|
|
|
2017-02-25 05:49:05 +03:00
|
|
|
duration = im.info.get("duration", 100)
|
2010-07-31 06:52:47 +04:00
|
|
|
self.after(duration, self.next)
|
|
|
|
|
|
|
|
def next(self):
|
|
|
|
|
2012-10-17 07:39:56 +04:00
|
|
|
if isinstance(self.im, list):
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
try:
|
|
|
|
im = self.im[0]
|
|
|
|
del self.im[0]
|
|
|
|
self.image.paste(im)
|
|
|
|
except IndexError:
|
2015-04-24 02:41:33 +03:00
|
|
|
return # end of list
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
try:
|
|
|
|
im = self.im
|
|
|
|
im.seek(im.tell() + 1)
|
|
|
|
self.image.paste(im)
|
|
|
|
except EOFError:
|
2015-04-24 02:41:33 +03:00
|
|
|
return # end of file
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2017-02-25 05:49:05 +03:00
|
|
|
duration = im.info.get("duration", 100)
|
2010-07-31 06:52:47 +04:00
|
|
|
self.after(duration, self.next)
|
|
|
|
|
|
|
|
self.update_idletasks()
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# script interface
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
if not sys.argv[1:]:
|
2012-10-16 06:27:35 +04:00
|
|
|
print("Syntax: python player.py imagefile(s)")
|
2010-07-31 06:52:47 +04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
filename = sys.argv[1]
|
|
|
|
|
2017-03-24 11:42:58 +03:00
|
|
|
root = tkinter.Tk()
|
2010-07-31 06:52:47 +04:00
|
|
|
root.title(filename)
|
|
|
|
|
|
|
|
if len(sys.argv) > 2:
|
|
|
|
# list of images
|
2012-10-16 06:27:35 +04:00
|
|
|
print("loading...")
|
2010-07-31 06:52:47 +04:00
|
|
|
im = []
|
|
|
|
for filename in sys.argv[1:]:
|
|
|
|
im.append(Image.open(filename))
|
|
|
|
else:
|
|
|
|
# sequence
|
|
|
|
im = Image.open(filename)
|
|
|
|
|
|
|
|
UI(root, im).pack()
|
|
|
|
|
|
|
|
root.mainloop()
|