Files
@thin TennisForTwo.py
@thin widgets.py
@thin widgetsdemo.py
@thin pygame2exe.py
@thin pygame2app.py
Tasks
Starting menu
__init__
<< Menu layout >>
Utilities
@run TennisForTwo.py
@run TennisForTwo.py client localhost 7554
@run widgetsdemo.py
@run PyGame2Exe.py py2exe
@run python2.4 pygame2app.py py2app
@ignore
@language python
#make standalone, needs at least pygame-1.5.3 and py2exe-0.3.1
from distutils.core import setup
import sys, os, pygame, shutil, glob
import py2exe
#setup the project variables here.
#i can't claim these will cover all the cases
#you need, but they seem to work for all my
#projects, just change as neeeded.
script = "TennisForTwo.py" #name of starting .PY
icon_file = "" #ICO file for the .EXE (not working well)
optimize = 2 #0, 1, or 2; like -O and -OO
dos_console = 0 #set to 0 for no dos shell when run
extra_data = ['data'] #extra files/dirs copied to game
extra_modules = ['pygame.locals'] #extra python modules not auto found
#use the default pygame icon, if none given
if not icon_file:
path = os.path.split(pygame.__file__)[0]
icon_file = '"' + os.path.join(path, 'pygame.ico') + '"'
#unfortunately, this cool icon stuff doesn't work in current py2exe :(
#icon_file = ''
project_name = os.path.splitext(os.path.split(script)[1])[0]
#this will create the executable and all dependencies
setup(#name=project_name,
windows=[script],
data_files=[("data", glob.glob("data\\*"))]
)
def __init__( self ):
"""Initialize Demo Class"""
# instead of pygame.init(), initialize modules manually to
# avoid initing pygame.sound
pygame.display.init()
pygame.font.init()
# setup screen
screen = pygame.display.set_mode( (640, 480), DOUBLEBUF )
pygame.display.set_caption( 'WidgetsDemo' )
# request regular event for updating animation
self.DRAWEVENT = USEREVENT + 1
pygame.time.set_timer( self.DRAWEVENT, 33 ) #33 == 30fps
# filter events
badevents = [NOEVENT, ACTIVEEVENT, JOYAXISMOTION, JOYBALLMOTION, JOYHATMOTION, JOYBUTTONDOWN ,JOYBUTTONUP, VIDEORESIZE, SYSWMEVENT, NUMEVENTS]
goodevents = [self.DRAWEVENT, KEYDOWN, KEYUP, MOUSEMOTION, MOUSEBUTTONDOWN, MOUSEBUTTONUP, QUIT ]
pygame.event.set_blocked( badevents )
# initialize the WidgetWindow base class
WidgetWindow.__init__( self, screen )
# create special widgets
edit = EditClass( self, self.editaction, (325, 300, 265, 25), "text" )
self.page = PageClass( self, (325, 25, 265, 275), GRAY )
# put the widgets in the window
self.addwidget( MultiLineTextClass( self, (25, 25, 250, 145), "MultiLineTextClass\n(transparent)\nHas automatic word wrapping.", 36 ) )
self.addwidget( MultiLineTextClass( self, (25, 195, 250, 145), "MultiLineTextClass\n(with background)\nHas automatic word wrapping.", 36, WHITE, BLACK ) )
self.addwidget( EditClass( self, self.editaction, (25, 350, 150, 30), "second edit box" ), TABTARGET )
self.addwidget( TextClass( self, (25, 400, 590, 19), "TextClass (transparent)", 20 ) )
self.addwidget( TextClass( self, (25, 440, 590, 19), "TextClass (with background)", 20, WHITE, BLACK ) )
self.addwidget( self.page )
self.addwidget( edit, TABTARGET )
self.addwidget( ButtonClass( self, self.buttonaction, (205, 110, 200, 105), "This button overlaps" ) )
# set keyboard focus to the edit widget
edit.focus()
# initial screen draw
self.eventproc( pygame.event.Event( NOEVENT, {} ) )
# animation data
self.animrect = Rect( (325, 350, 265, 50) )
self.animline = Rect( self.animrect )
self.animline.width = 5
self.animline.left = self.animrect.left
self.addwidget(TextClass(self, (120, 40, 400, 30), "Tennis For Two", 36))
self.addwidget(ButtonClass(self, self.startSingle, (120, 120, 400, 30), "Start Single-Player Game"))
self.addwidget(TextClass(self, (120, 190, 400, 20), "Your IP Address: " + getMyIP()))
self.addwidget(TextClass(self, (120, 215, 60, 20), "Port:"))
self.serverPort = EditClass(self, None, (180, 215, 60, 20), "7554")
self.addwidget(self.serverPort)
self.addwidget(ButtonClass(self, self.startServer, (120, 240, 400, 30), "Start Server"))
self.addwidget(TextClass(self, (120, 310, 160, 20), "Server Address:"))
self.clientAddr = EditClass(self, None, (280, 310, 240, 20))
self.addwidget(self.clientAddr)
self.addwidget(TextClass(self, (120, 335, 60, 20), "Port:"))
self.clientPort = EditClass(self, None, (180, 335, 60, 20), "7554")
self.addwidget(self.clientPort)
self.addwidget(ButtonClass(self, self.startClient, (120, 360, 400, 30), "Start Client"))