Skip to content

Bug fixes and button improvements to animated Gif Player #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions examples/rgb_display_pillow_animated_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,29 @@ def __init__(self, display, width=None, height=None, folder=None):
self.run()

def advance(self, loop=False):
initial_index = self._index
if self._index < len(self._gif_files) - 1:
self._index += 1
elif loop and self._index == len(self._gif_files) - 1:
self._index = 0
return initial_index != self._index

def back(self, loop=False):
initial_index = self._index
if self._index > 0:
self._index -= 1
elif loop and self._index == 0:
self._index = len(self._gif_files) - 1
return initial_index != self._index

def load_files(self, folder):
self._gif_files = [f for f in os.listdir(folder) if f[-4:] == '.gif']
gif_files = [f for f in os.listdir(folder) if f[-4:] == '.gif']
for gif_file in gif_files:
image = Image.open(gif_file)
# Only add animated Gifs
if image.is_animated:
self._gif_files.append(gif_file)

print("Found", self._gif_files)
if not self._gif_files:
print("No Gif files found in current folder")
Expand Down Expand Up @@ -133,24 +143,27 @@ def play(self):
# Check if we have loaded any files first
if not self._gif_files:
print("There are no Gif Images to Play")

for frame_object in self._frames:
self.display.image(frame_object.image)
if not self.advance_button.value:
self.advance()
elif not self.back_button.value:
self.back()
time.sleep(frame_object.duration / 1000)

if self._loop == 1:
return
if self._loop > 0:
self._loop -= 1
while True:
for frame_object in self._frames:
self.display.image(frame_object.image)
if not self.advance_button.value:
if self.advance():
return False
elif not self.back_button.value:
if self.back():
return False
time.sleep(frame_object.duration / 1000)

if self._loop == 1:
return True
if self._loop > 0:
self._loop -= 1

def run(self):
while True:
self.play()
self.advance(True)
auto_advance = self.play()
if auto_advance:
self.advance(True)

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 64000000
Expand Down