diff options
author | Wade Brainerd <wadetb@gmail.com> | 2009-10-29 23:41:56 (GMT) |
---|---|---|
committer | Wade Brainerd <wadetb@gmail.com> | 2009-10-29 23:41:56 (GMT) |
commit | 3f6c2502aa5359613c60eae73f9235d08faaee67 (patch) | |
tree | e1403e632115c5ccf776b541145f9099dcc7cdbf /test | |
parent | 914e220f76fde8f3a9bb06546c7f7549d8891746 (diff) |
Add test activity and Pygame script; add README.txt.
Diffstat (limited to 'test')
-rw-r--r-- | test/TestActivity.py | 75 | ||||
-rwxr-xr-x | test/TestGame.py | 60 | ||||
-rw-r--r-- | test/activity/activity-generic.svg | 23 | ||||
-rwxr-xr-x | test/activity/activity.info | 6 | ||||
-rw-r--r-- | test/activity/mimetypes.xml | 8 | ||||
-rwxr-xr-x | test/setup.py | 4 |
6 files changed, 176 insertions, 0 deletions
diff --git a/test/TestActivity.py b/test/TestActivity.py new file mode 100644 index 0000000..dd02d31 --- /dev/null +++ b/test/TestActivity.py @@ -0,0 +1,75 @@ +from gettext import gettext as _ + +import sys +import gtk + +import sugar.activity.activity +import sugar.graphics.toolbutton + +sys.path.append('..') # Import sugargame package from top directory. +import sugargame.activity + +import TestGame + +class TestActivity(sugargame.activity.PygameActivity): + def __init__(self, handle): + super(TestActivity, self).__init__(handle) + + self.metadata['mime_type'] = 'application/x-physics-activity' + + self._resume_path = None + + self.build_toolbar() + self.build_canvas() + + self.paused = False + + # Create the game instance. + self.game = TestGame.TestGame(self.get_pygame_screen()) + + # If resuming from the Journal, load the data. + if self._resume_path: + self.read_file(self._resume_path) + + # Start the main loop running. + self.run_pygame(self.game.run) + + def build_toolbar(self): + stop_play = sugar.graphics.toolbutton.ToolButton('media-playback-stop') + stop_play.set_tooltip(_("Stop")) + stop_play.set_accelerator(_('<ctrl>space')) + stop_play.connect('clicked', self._stop_play_cb) + + toolbar = gtk.Toolbar() + toolbar.insert(stop_play, 0) + toolbar.insert(gtk.SeparatorToolItem(), 1) + + toolbox = sugar.activity.activity.ActivityToolbox(self) + toolbox.add_toolbar(_("Pygame"), toolbar) + + toolbox.show_all() + self.set_toolbox(toolbox) + + def _stop_play_cb(self, button): + # Pause or unpause the game. + self.paused = not self.paused + self.game.set_paused(self.paused) + + # Update the button to show the next action. + if self.paused: + button.set_icon('media-playback-start') + button.set_tooltip(_("Start")) + else: + button.set_icon('media-playback-stop') + button.set_tooltip(_("Stop")) + + def read_file(self, file_path): + # Read file is called before the constructor returns when game is not yet valid. + # Caching the file path seems to work in this specific instance. + if not self.game: + self._resume_path = file_path + else: + self.game.read_file(file_path) + + def write_file(self, file_path): + self.game.write_file(file_path) diff --git a/test/TestGame.py b/test/TestGame.py new file mode 100755 index 0000000..06c1906 --- /dev/null +++ b/test/TestGame.py @@ -0,0 +1,60 @@ +#!/usr/bin/python +import pygame +import gtk + +class TestGame: + def __init__(self, screen): + self.screen = screen + + # Set up a clock for managing the framerate. + self.clock = pygame.time.Clock() + + # Set up a font for rendering. + self.font = pygame.font.Font(None, 24) + + def set_paused(self, paused): + self.paused = paused + + # Called to save the state of the game to the Journal. + def write_file(self, file_path): + pass + + # Called to load the state of the game from the Journal. + def read_file(self, file_path): + pass + + # The main game loop. + def run(self): + self.running = True + + while self.running: + # Pump GTK messages. + while gtk.events_pending(): + gtk.main_iteration() + + # Pump PyGame messages. + for event in pygame.event.get(): + pass + + # Clear Display + self.screen.fill((255,255,255)) #255 for white + + # Flip Display + pygame.display.flip() + + # Try to stay at 30 FPS + self.clock.tick(30) + +# This function is called when the game is run directly from the command line: +# ./TestGame.py +def main(): + pygame.init() + pygame.display.init() + width, height = pygame.display.list_modes()[0] + screen = pygame.display.set_mode((width,height)) + game = TestGame(screen) + game.run() + +if __name__ == '__main__': + main() + diff --git a/test/activity/activity-generic.svg b/test/activity/activity-generic.svg new file mode 100644 index 0000000..3a642f8 --- /dev/null +++ b/test/activity/activity-generic.svg @@ -0,0 +1,23 @@ +<?xml version="1.0" ?><!-- Created with Inkscape (http://www.inkscape.org/) --><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [ + <!ENTITY stroke_color "#ff0000"> + <!ENTITY fill_color "#000000"> +]><svg height="55" id="svg2" inkscape:output_extension="org.inkscape.output.svg.inkscape" inkscape:version="0.46+devel" sodipodi:docname="activity-generic.svg" sodipodi:version="0.32" style="" version="1.0" width="55" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg"> + <metadata id="metadata20"> + <rdf:RDF> + <cc:Work rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> + </cc:Work> + </rdf:RDF> + </metadata> + <sodipodi:namedview bordercolor="#666666" borderopacity="1" gridtolerance="10" guidetolerance="10" id="namedview18" inkscape:current-layer="svg2" inkscape:cx="-15.963983" inkscape:cy="27.5" inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:window-height="1125" inkscape:window-width="1920" inkscape:window-x="0" inkscape:window-y="25" inkscape:zoom="4.2909091" objecttolerance="10" pagecolor="#ffffff" showgrid="true"> + <inkscape:grid id="grid796" type="xygrid"/> + </sodipodi:namedview> + <defs id="defs4" style=""> + <inkscape:perspective id="perspective22" inkscape:persp3d-origin="27.5 : 18.333333 : 1" inkscape:vp_x="0 : 27.5 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="55 : 27.5 : 1" sodipodi:type="inkscape:persp3d"/> + </defs> + <g id="layer1" style="fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-opacity:1;stroke-width:3.002554;stroke-miterlimit:4;stroke-dasharray:none" transform="matrix(1.1689037,0,0,1.1624538,-4.6448521,-4.3634813)"> + <rect height="35" id="rect16" style="fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-width:3.002554;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" width="35" x="10" y="10"/> + <text id="text790" style="font-size:40px;font-style:normal;font-weight:normal;fill:&stroke_color;;fill-opacity:1;stroke:none;stroke-opacity:1;font-family:Bitstream Vera Sans;stroke-width:3.00255399999999995;stroke-miterlimit:4;stroke-dasharray:none" x="17.911133" xml:space="preserve" y="40"><tspan id="tspan792" style="font-size:36px;fill:&stroke_color;;fill-opacity:1;stroke:none;stroke-opacity:1;stroke-width:3.00255399999999995;stroke-miterlimit:4;stroke-dasharray:none" x="17.911133" y="40">?</tspan></text> + </g> +</svg>
\ No newline at end of file diff --git a/test/activity/activity.info b/test/activity/activity.info new file mode 100755 index 0000000..313c30d --- /dev/null +++ b/test/activity/activity.info @@ -0,0 +1,6 @@ +[Activity] +name = SugargameTest +service_name = org.sugarlabs.SugargameTest +class = TestActivity.TestActivity +icon = activity-generic +activity_version = 1 diff --git a/test/activity/mimetypes.xml b/test/activity/mimetypes.xml new file mode 100644 index 0000000..8fe1709 --- /dev/null +++ b/test/activity/mimetypes.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> + <mime-type type="application/x-physics-activity"> + <comment xml:lang="en">Physics Activity</comment> + <glob pattern="*.physics"/> + </mime-type> +</mime-info> + diff --git a/test/setup.py b/test/setup.py new file mode 100755 index 0000000..6ed89aa --- /dev/null +++ b/test/setup.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python +from sugar.activity import bundlebuilder +bundlebuilder.start() + |