@ -1,5 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python
import pygame
import pygame # pylint: disable=import-error
# Define some colors
# Define some colors
BLACK = ( 0 , 0 , 0 )
BLACK = ( 0 , 0 , 0 )
@ -17,21 +17,21 @@ class TextPrint:
textBitmap = self . font . render ( textString , True , BLACK )
textBitmap = self . font . render ( textString , True , BLACK )
screen . blit ( textBitmap , [ self . x , self . y ] )
screen . blit ( textBitmap , [ self . x , self . y ] )
self . y + = self . line_height
self . y + = self . line_height
def reset ( self ) :
def reset ( self ) :
self . x = 10
self . x = 10
self . y = 10
self . y = 10
self . line_height = 15
self . line_height = 15
def indent ( self ) :
def indent ( self ) :
self . x + = 10
self . x + = 10
def unindent ( self ) :
def unindent ( self ) :
self . x - = 10
self . x - = 10
pygame . init ( )
pygame . init ( )
# Set the width and height of the screen [width,height]
# Set the width and height of the screen [width,height]
size = [ 500 , 700 ]
size = [ 500 , 700 ]
screen = pygame . display . set_mode ( size )
screen = pygame . display . set_mode ( size )
@ -46,7 +46,7 @@ clock = pygame.time.Clock()
# Initialize the joysticks
# Initialize the joysticks
pygame . joystick . init ( )
pygame . joystick . init ( )
# Get ready to print
# Get ready to print
textPrint = TextPrint ( )
textPrint = TextPrint ( )
@ -56,14 +56,14 @@ while done==False:
for event in pygame . event . get ( ) : # User did something
for event in pygame . event . get ( ) : # User did something
if event . type == pygame . QUIT : # If user clicked close
if event . type == pygame . QUIT : # If user clicked close
done = True # Flag that we are done so we exit this loop
done = True # Flag that we are done so we exit this loop
# Possible joystick actions: JOYAXISMOTION JOYBALLMOTION JOYBUTTONDOWN JOYBUTTONUP JOYHATMOTION
# Possible joystick actions: JOYAXISMOTION JOYBALLMOTION JOYBUTTONDOWN JOYBUTTONUP JOYHATMOTION
if event . type == pygame . JOYBUTTONDOWN :
if event . type == pygame . JOYBUTTONDOWN :
print ( " Joystick button pressed. " )
print ( " Joystick button pressed. " )
if event . type == pygame . JOYBUTTONUP :
if event . type == pygame . JOYBUTTONUP :
print ( " Joystick button released. " )
print ( " Joystick button released. " )
# DRAWING STEP
# DRAWING STEP
# First, clear the screen to white. Don't put other drawing commands
# First, clear the screen to white. Don't put other drawing commands
# above this, or they will be erased with this command.
# above this, or they will be erased with this command.
@ -75,29 +75,29 @@ while done==False:
textPrint . printf ( screen , " Number of joysticks: {} " . format ( joystick_count ) )
textPrint . printf ( screen , " Number of joysticks: {} " . format ( joystick_count ) )
textPrint . indent ( )
textPrint . indent ( )
# For each joystick:
# For each joystick:
joystick = pygame . joystick . Joystick ( 0 )
joystick = pygame . joystick . Joystick ( 0 )
joystick . init ( )
joystick . init ( )
textPrint . printf ( screen , " Joystick {} " . format ( 0 ) )
textPrint . printf ( screen , " Joystick {} " . format ( 0 ) )
textPrint . indent ( )
textPrint . indent ( )
# Get the name from the OS for the controller/joystick
# Get the name from the OS for the controller/joystick
name = joystick . get_name ( )
name = joystick . get_name ( )
textPrint . printf ( screen , " Joystick name: {} " . format ( name ) )
textPrint . printf ( screen , " Joystick name: {} " . format ( name ) )
# Usually axis run in pairs, up/down for one, and left/right for
# Usually axis run in pairs, up/down for one, and left/right for
# the other.
# the other.
axes = joystick . get_numaxes ( )
axes = joystick . get_numaxes ( )
textPrint . printf ( screen , " Number of axes: {} " . format ( axes ) )
textPrint . printf ( screen , " Number of axes: {} " . format ( axes ) )
textPrint . indent ( )
textPrint . indent ( )
for i in range ( axes ) :
for i in range ( axes ) :
axis = joystick . get_axis ( i )
axis = joystick . get_axis ( i )
textPrint . printf ( screen , " Axis {} value: {:>6.3f} " . format ( i , axis ) )
textPrint . printf ( screen , " Axis {} value: {:>6.3f} " . format ( i , axis ) )
textPrint . unindent ( )
textPrint . unindent ( )
buttons = joystick . get_numbuttons ( )
buttons = joystick . get_numbuttons ( )
textPrint . printf ( screen , " Number of buttons: {} " . format ( buttons ) )
textPrint . printf ( screen , " Number of buttons: {} " . format ( buttons ) )
textPrint . indent ( )
textPrint . indent ( )
@ -110,15 +110,15 @@ while done==False:
textPrint . unindent ( )
textPrint . unindent ( )
# ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT
# ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT
# Go ahead and update the screen with what we've drawn.
# Go ahead and update the screen with what we've drawn.
pygame . display . flip ( )
pygame . display . flip ( )
# Limit to 20 frames per second
# Limit to 20 frames per second
clock . tick ( 20 )
clock . tick ( 20 )
# Close the window and quit.
# Close the window and quit.
# If you forget this line, the program will 'hang'
# If you forget this line, the program will 'hang'
# on exit if running from IDLE.
# on exit if running from IDLE.