Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1

Click here to view code image


#script2301.py - HD Presentation
#Written by Blum and Bresnahan
#
##########################################
#
##### Import Modules & Variables ######
import os #Import OS module
import pygame #Import PyGame library
import sys #Import System module
#
from pygame.locals import * #Load PyGame constants
#
pygame.init() #Initialize PyGame
#
# Set up Picture Variables #####################
#
PictureDirectory = '/home/pi/pictures'
PictureFileExtension = '.jpg'
PictureDisk = '/dev/sda1'
#
# Mount the Picture Drive ######################
#
Command = "sudo umount " + PictureDisk + " 2>/dev/null"
os.system(Command)
Command = "sudo mount -t vfat " + PictureDisk + " " + PictureDirectory
os.system(Command)
#
# Set up Presentation Screen ###################
#
ScreenColor = Gray = 125,125,125
#
ScreenFlag = FULLSCREEN | NOFRAME
PrezScreen = pygame.display.set_mode((0,0),ScreenFlag)
#
PrezScreenRect = PrezScreen.get_rect()
CenterScreen = PrezScreenRect.center
#
PrezScreenSize = PrezScreen.get_size()
Scale=PrezScreenSize[0]-20,PrezScreenSize[1]-20
#
###### Run the Presentation #######################################
#
while True:
#
#Get HD Pictures ###################################
#
for Picture in os.listdir(PictureDirectory):
if Picture.endswith(PictureFileExtension):
Picture=PictureDirectory + '/' + Picture
Picture=pygame.image.load(Picture).convert_alpha()
#
# If Picture is bigger than screen, scale it down.
if Picture.get_size() > PrezScreenSize:
Picture = pygame.transform.scale(Picture,Scale)
#
PictureLocation=Picture.get_rect() #Current location
PictureLocation.center=CenterScreen #Put picture in center of screen
#
Free download pdf