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

(singke) #1
# Font #
#
DefaultFont='/usr/share/fonts/truetype/freefont/FreeSans.ttf'
PrezFont=font.Font(DefaultFont,60)
#
# Text #
#
IntroText1="Our Trip to the"
IntroText2="Raspberry Capital of the World"
IntroText1=PrezFont.render(IntroText1,True,RazPiRed)
IntroText2=PrezFont.render(IntroText2,True,RazPiRed)

Notice that a color called RazPiRed is being used for the text color to provide a nice contrast to the
presentation screen’s gray background.


Now you can place the text prior to the for loop in the presentation script, as follows:


Click here to view code image


# Introduction Screen ##############################
#
PrezScreen.fill(ScreenColor)
#
# Put Intro Text Line 1 above Center of Screen
IntroText1Location = IntroText1.get_rect()
IntroText1Location.center = AboveCenterScreen
PrezScreen.blit(IntroText1,IntroText1Location)
#
# Put Intro Text Line 2 at Center of Screen
IntroText2Location = IntroText2.get_rect()
IntroText2Location.center = CenterScreen
PrezScreen.blit(IntroText2,IntroText2Location)
#
display.update()
#
#Get HD Pictures ###################################
#
for Picture in listdir(PictureDirectory):

Adding Finer Mouse and/or Keyboard Controls


This last fix will provide you with another speed illusion. Many people give business presentations
while holding a remote or using a mouse to control the flow of the images shown on the screen.
Adding an event loop immediately after a picture is loaded allows you to incorporate this type of
control, as shown here:


Click here to view code image


Picture = image.load(Picture)
#
Continue = 0
# Show next Picture with Mouse
while Continue == 0:
for Event in event.get():
if Event.type == MOUSEBUTTONDOWN:
Continue = 1

This added event gives the illusion of picture display control by the presenter. You still have the
same long load time, but by knowing the approximate time between pictures, you can talk through
each image and then click the mouse after the approximate time. This gives the illusion of the pictures

Free download pdf