2010-07-31 06:52:47 +04:00
|
|
|
#
|
|
|
|
# The Python Imaging Library.
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# sequence support classes
|
|
|
|
#
|
|
|
|
# history:
|
|
|
|
# 1997-02-20 fl Created
|
|
|
|
#
|
|
|
|
# Copyright (c) 1997 by Secret Labs AB.
|
|
|
|
# Copyright (c) 1997 by Fredrik Lundh.
|
|
|
|
#
|
|
|
|
# See the README file for information on usage and redistribution.
|
|
|
|
#
|
|
|
|
|
|
|
|
##
|
|
|
|
|
2014-08-26 17:47:10 +04:00
|
|
|
|
2015-05-26 17:07:21 +03:00
|
|
|
class Iterator(object):
|
2013-10-14 08:49:35 +04:00
|
|
|
"""
|
|
|
|
This class implements an iterator object that can be used to loop
|
|
|
|
over an image sequence.
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2013-10-14 08:49:35 +04:00
|
|
|
You can use the ``[]`` operator to access elements by index. This operator
|
|
|
|
will raise an :py:exc:`IndexError` if you try to access a nonexistent
|
|
|
|
frame.
|
|
|
|
|
|
|
|
:param im: An image object.
|
|
|
|
"""
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
def __init__(self, im):
|
|
|
|
if not hasattr(im, "seek"):
|
|
|
|
raise AttributeError("im must have seek method")
|
|
|
|
self.im = im
|
|
|
|
|
|
|
|
def __getitem__(self, ix):
|
|
|
|
try:
|
|
|
|
if ix:
|
|
|
|
self.im.seek(ix)
|
|
|
|
return self.im
|
|
|
|
except EOFError:
|
2014-08-26 17:47:10 +04:00
|
|
|
raise IndexError # end of sequence
|