Hardware Reference
In-Depth Information
determines which exit condition caused it to inish. If it was because the resulting text was
too wide, you remove one word from the list; otherwise, you set a variable to indicate that
the end of the line has been reached. Next, you gather the words into the string you will
inally use, and render it, printing it out again so that you can check it. hen those words
need to be removed from the news line so that you don't use them again. he line
newsLines[index] = newsLines[index][len(useLine) :]
does this. Finally, you check if the line has had all the words extracted from it by looking at
the wordsAvailable variable you set earlier. If it has, the index variable is incremented,
and inally the index variable is returned from the function.
he large initial size of the scrollSize variable, coupled with the printing out of each test
string in the setWords function, ensures that the results look very bad on the screen - due
to rapid scrolling and a pause while the next line is worked out. However, all that will disap-
pear when you remove the test prints in the inal version.
Your Final Pi Prompter Code
All that remains to do is add in some controls. hese are basically keyboard controls, so code
is added to the checkForEvents() function to set variables in response to key presses.
he controls to add are for pausing/resuming the display, controlling the speed, adjusting
the display to a mirror image and changing the ile to use to read in more news. You also
need to make some tweaks to the code to allow these variables to do their work. he inal
code is shown in Listing 4-3.
Listing 4-3 The Autocue Listing
#!/usr/bin/env python
“””
Here is the News
A Raspberry Pi Auto Cue
“””
import os, pygame, sys
pygame.init() # initialise graphics interface
os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
pygame.display.set_caption(“Auto Cue”)
screenWidth = 980
screenHeight =610
screen = pygame.display.set_mode([screenWidth, ;
screenHeight],0,32)
Search WWH ::




Custom Search