Skip to content

Commit

Permalink
Merge pull request #154 from francesco-vannini/master
Browse files Browse the repository at this point in the history
New script for animations
  • Loading branch information
francesco-vannini authored Sep 15, 2017
2 parents 6a37c7b + 0c7547a commit 75954d0
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ papirus-twitter

# Composite text and graphics
papirus-composite-write

# Display image sequences or slide-show
papirus-animation path [rotation] [delay] [fullupdate] [loop]
```

### Tips for using images
Expand Down
89 changes: 89 additions & 0 deletions bin/papirus-animation
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python

import time
import os
import argparse

import Image

from papirus import Papirus

PICTURES_TYPES = ['jpg', 'png', 'bmp', 'gif']

# Create an instance of papirus
papirus = Papirus()

def main():
"""main program"""
p = argparse.ArgumentParser()
p.add_argument('filepath', type=str, help="Path to pictures")
p.add_argument('--delay', '-d', type=int, default=0, help="Extra delay between pictures")
p.add_argument('--rotation', '-r', type=int, default=0, help="Rotation one of 0, 90, 180, 270")
p.add_argument('--fullupdate', '-f', action='store_true', default=False, help="Force full update between each picture")
p.add_argument('--loop', '-l', action='store_true', default=False, help="Sets the script in a continuous loop. CTRL^C to stop it")
args = p.parse_args()

papirus = Papirus(rotation=args.rotation)
if args.filepath:
print("Animation on PaPiRus.......")
animate(papirus, args.filepath, args.delay, args.fullupdate, args.loop)
print("Finished!")

def animate(papirus, imagepath, extradelay, fullupdate, loop):
"""animation"""

reps = 0 # Counts the times the screen has been used even when in loop to ensure a refresh every 10

papirus.clear()

print('Displaying the animation')

try: # Extract name and extension of the first file in the list
name = os.listdir(imagepath)[0].split(".")[0]
extension = os.listdir(imagepath)[0].split(".")[1]
if name.isdigit() and extension in PICTURES_TYPES: # If it is a number assumes it is an animated sequence
stringnamepictures = False
print('Numbered sequence')
elif name[0].isalpha() and extension in PICTURES_TYPES: # If it is an alpha then it is a slideshow
stringnamepictures = True
print('Unnumbered sequence')
else:
print('There are no compatible files in the chosen directory')
exit()
except Exception as e:
raise e
print "No file found"

try:
while loop or reps == 0:
for i in range(0, len(os.listdir(imagepath))):
if not stringnamepictures:
extension = os.listdir(imagepath)[i].split(".")[1]
filename = imagepath + '/' + str(i+1) + '.' + extension
else:
extension = os.listdir(imagepath)[i].split(".")[1]
filename = imagepath + '/' + os.listdir(imagepath)[i]
reps = reps + 1
if os.path.isfile(filename) and extension in PICTURES_TYPES:
image = Image.open(filename)
image = image.resize((papirus.width, papirus.height), Image.ANTIALIAS)
image = image.convert("1", dither=Image.FLOYDSTEINBERG)

papirus.display(image)
if fullupdate or reps % 10 == 0: # Refresh every ten partials
papirus.update()
else:
papirus.partial_update()

if extradelay > 0:
time.sleep(extradelay)
except KeyboardInterrupt:
# quit
papirus.clear()
sys.exit()

papirus.update()

# main
if "__main__" == __name__:
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
author_email='sales@pi-supply.com',
url='pi-supply.com',
packages=['papirus'],
scripts=['bin/papirus-buttons', 'bin/papirus-clear', 'bin/papirus-clock', 'bin/papirus-composite-write', 'bin/papirus-config', 'bin/papirus-draw', 'bin/papirus-gol', 'bin/papirus-radar', 'bin/papirus-set', 'bin/papirus-setup', 'bin/papirus-temp', 'bin/papirus-test', 'bin/papirus-system', 'bin/papirus-textfill', 'bin/papirus-twitter', 'bin/papirus-write'],
scripts=['bin/papirus-animation','bin/papirus-buttons', 'bin/papirus-clear', 'bin/papirus-clock', 'bin/papirus-composite-write', 'bin/papirus-config', 'bin/papirus-draw', 'bin/papirus-gol', 'bin/papirus-radar', 'bin/papirus-set', 'bin/papirus-setup', 'bin/papirus-temp', 'bin/papirus-test', 'bin/papirus-system', 'bin/papirus-textfill', 'bin/papirus-twitter', 'bin/papirus-write'],
data_files=[('bitmaps', ['bitmaps/papirus-logo.bmp', 'bitmaps/0.gif', 'bitmaps/1.gif', 'bitmaps/2.gif', 'bitmaps/3.gif', 'bitmaps/4.gif', 'bitmaps/5.gif', 'bitmaps/6.gif', 'bitmaps/7.gif', 'bitmaps/8.gif', 'bitmaps/9.gif', 'bitmaps/10.gif', 'bitmaps/11.gif', 'bitmaps/12.gif', 'bitmaps/13.gif', 'bitmaps/14.gif', 'bitmaps/15.gif'])]
)

0 comments on commit 75954d0

Please sign in to comment.