@@ -66,19 +66,29 @@ def __init__(self, display, width=None, height=None, folder=None):
66
66
self .run ()
67
67
68
68
def advance (self , loop = False ):
69
+ initial_index = self ._index
69
70
if self ._index < len (self ._gif_files ) - 1 :
70
71
self ._index += 1
71
72
elif loop and self ._index == len (self ._gif_files ) - 1 :
72
73
self ._index = 0
74
+ return initial_index != self ._index
73
75
74
76
def back (self , loop = False ):
77
+ initial_index = self ._index
75
78
if self ._index > 0 :
76
79
self ._index -= 1
77
80
elif loop and self ._index == 0 :
78
81
self ._index = len (self ._gif_files ) - 1
82
+ return initial_index != self ._index
79
83
80
84
def load_files (self , folder ):
81
- self ._gif_files = [f for f in os .listdir (folder ) if f [- 4 :] == '.gif' ]
85
+ gif_files = [f for f in os .listdir (folder ) if f [- 4 :] == '.gif' ]
86
+ for gif_file in gif_files :
87
+ image = Image .open (gif_file )
88
+ # Only add animated Gifs
89
+ if image .is_animated :
90
+ self ._gif_files .append (gif_file )
91
+
82
92
print ("Found" , self ._gif_files )
83
93
if not self ._gif_files :
84
94
print ("No Gif files found in current folder" )
@@ -133,24 +143,27 @@ def play(self):
133
143
# Check if we have loaded any files first
134
144
if not self ._gif_files :
135
145
print ("There are no Gif Images to Play" )
136
-
137
- for frame_object in self ._frames :
138
- self .display .image (frame_object .image )
139
- if not self .advance_button .value :
140
- self .advance ()
141
- elif not self .back_button .value :
142
- self .back ()
143
- time .sleep (frame_object .duration / 1000 )
144
-
145
- if self ._loop == 1 :
146
- return
147
- if self ._loop > 0 :
148
- self ._loop -= 1
146
+ while True :
147
+ for frame_object in self ._frames :
148
+ self .display .image (frame_object .image )
149
+ if not self .advance_button .value :
150
+ if self .advance ():
151
+ return False
152
+ elif not self .back_button .value :
153
+ if self .back ():
154
+ return False
155
+ time .sleep (frame_object .duration / 1000 )
156
+
157
+ if self ._loop == 1 :
158
+ return True
159
+ if self ._loop > 0 :
160
+ self ._loop -= 1
149
161
150
162
def run (self ):
151
163
while True :
152
- self .play ()
153
- self .advance (True )
164
+ auto_advance = self .play ()
165
+ if auto_advance :
166
+ self .advance (True )
154
167
155
168
# Config for display baudrate (default max is 24mhz):
156
169
BAUDRATE = 64000000
0 commit comments