Hardware Reference
In-Depth Information
Listing 11-3 continued
# the step source control
stepInt = not stepInt
if stepInt :
drawControl(350,132,;
“Auto Step”)
else:
drawControl(350,132,;
“External Step”)
pygame.display.update()
else:
#print “mouse “,x,y
def terminate(): # close down the program
print (“Closing down please wait”)
pfio.deinit() # close the pfio
pygame.quit()
sys.exit()
def checkForEvent():
# see if we need to quit or look at the mouse
#print “checking for quit”
event = pygame.event.poll()
if event.type == pygame.QUIT :
terminate()
elif event.type == pygame.MOUSEBUTTONDOWN :
mouseGet()
elif event.type == pygame.KEYDOWN and ;
event.key == pygame.K_ESCAPE :
terminate()
if __name__ == '__main__':
main()
So let's walk through the major sections of the code. It starts of by importing the required
libraries and then initialising them and the program's window. Next comes the section where
you can customise the colours for the program. I found a black background looks best when
you are using the program but a white background looks a lot better when viewed in a topic.
he next section deines the few global variables needed by the program.
he main function is simple, just four lines: Set up the screen, and then loop forever check-
ing for events to quit or mouse clicks to change what is happening. Finally check if you need
to advance the sequence. his sequence advance function follows next, although as you
know, the order of the function deinitions is not important.
Search WWH ::




Custom Search