Modify the solution from Exercise 24.6 so that the program displays the time in the fol- lowing format: “00:00/00:00.” The first “00:00” represents the current time. The second “00:00” rep- resents the total time.
What will be an ideal response?
```
# Simple movie player using pygame.
import os
import sys, string
import pygame, pygame.movie, pygame.font
import pygame.mouse, pygame.image
from pygame.locals import *
def createGUI( file ):
global movie, width, height, screen, playImageSize
global stopImageSize, pauseImageSize, rewindImageSize
# load movie
movie = pygame.movie.Movie( file )
width, height = movie.get_size()
# initialize display window
screen = pygame.display.set_mode( ( width, height + 100 ) )
pygame.display.set_caption( "Movie Player" )
pygame.mouse.set_visible( 1 )
# play button
playImageFile = os.path.join( "data", "play.png" )
playImage, playImageSize = addButton( playImageFile, 50 )
# stop button
stopImageFile = os.path.join( "data", "stop.png" )
stopImage, stopImageSize = addButton( stopImageFile, 130 )
# pause button
pauseImageFile = os.path.join( "data", "pause.png" )
pauseImage, pauseImageSize = addButton( pauseImageFile, 210 )
# rewind button
rewindImageFile = os.path.join( "data", "rwd.png" )
rewindImage, rewindImageSize = addButton(
rewindImageFile, 290 )
# display time
movieLength = int ( movie.get_length() )
endMinutes = movieLength / 60
endSeconds = movieLength - ( endMinutes * 60 )
global oldTimeRectangle, currentTime, endTime
oldTimeRectangle = ( width/2, height+20, width/2, height+20 )
currentTime = 0
endTime = string.zfill( str( endMinutes ), 2 ) + \
":" + string.zfill( str( endSeconds ), 2 )
updateTime()
# copy play button to screen
screen.blit( playImage, playImageSize )
screen.blit( stopImage, stopImageSize )
screen.blit( pauseImage, pauseImageSize )
screen.blit( rewindImage, rewindImageSize )
pygame.display.flip()
# set output surface for the movie's video
movie.set_display( screen )
def addButton( imageFile, centerX ):
buttonImage = pygame.image.load( imageFile ).convert()
buttonImage.set_colorkey( buttonImage.get_at( ( 0, 0 ) ) )
buttonImageSize = buttonImage.get_rect()
buttonImageSize.centerx = centerX
buttonImageSize.centery = height + 65
return buttonImage, buttonImageSize
def updateTime():
global currentTime, endTime, screen, oldTimeRectangle
font = pygame.font.Font( None, 24 )
# remove old time
screen.fill( ( 0, 0, 0 ), oldTimeRectangle )
# display new time
currentMinutes = currentTime / 60
currentSeconds = currentTime - ( currentMinutes * 60 )
currentTime = string.zfill( str( currentMinutes ), 2 ) + \
":" + string.zfill( str( currentSeconds ), 2 )
text = font.render( currentTime + "/" + endTime, 1,
( 250, 250, 250 ), ( 0, 0, 0 ) )
textPosition = text.get_rect()
textPosition.centerx = width / 2
textPosition.centery = height + 20
oldTimeRectangle = screen.blit( text, textPosition )
pygame.display.flip()
def main():
# check command line arguments
if len( sys.argv ) != 2:
sys.exit( "Incorrect number of arguments." )
else:
file = sys.argv[ 1 ]
# initialize pygame
pygame.init()
# initialize GUI
createGUI( file )
# issue a USEREVENT every 1000 milliseconds
pygame.time.set_timer( USEREVENT, 1000 )
# wait until player wants to close program
while 1:
event = pygame.event.poll()
# close window
if event.type == QUIT or \
( event.type == KEYDOWN and event.key == K_ESCAPE ):
break
elif event.type == USEREVENT and movie.get_busy():
global currentTime
oldTime = currentTime
currentTime = int ( movie.get_time() )
updateTime()
# click play button and play movie
pressed = pygame.mouse.get_pressed()[ 0 ]
position = pygame.mouse.get_pos()
if pressed:
if playImageSize.collidepoint( position ):
movie.play()
elif stopImageSize.collidepoint( position ):
movie.stop()
movie.rewind()
elif pauseImageSize.collidepoint( position ):
movie.pause()
elif rewindImageSize.collidepoint( position ):
movie.rewind()
screen.fill(
( 250, 250, 250 ), ( 0, 0, width, height ) )
pygame.display.flip()
currentTime = 0
updateTime()
if __name__ == "__main__":
main()
```

You might also like to view...
200 ppi is considered a high resolution for any file that will be professionally printed.
Answer the following statement true (T) or false (F)
The _______ and _______ operators are used to shift the bits of a value to the left or to the right, respectively.
Fill in the blank(s) with the appropriate word(s).
The _blank value causes a blank window to open when a link is clicked
Indicate whether the statement is true or false
It is best when designing a query to add all the fields from a table in case you need them later.
Answer the following statement true (T) or false (F)