From c5750a8909d346353bd334e82667c03e74046349 Mon Sep 17 00:00:00 2001
From: Manuel Kaufmann <humitos@gmail.com>
Date: Wed, 28 Mar 2012 09:34:23 -0300
Subject: [PATCH Maze] Buttons to generate a harder or an easier level
Addedi two buttons in the toolbar to generate a new level (harder or easier). These
butons do the same work than '+' and '-' keys respectively.
This commit solves ticket: #3376
Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
---
activity.py | 36 +++++++++++++++++++++++++++++++++++-
game.py | 5 +++++
2 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/activity.py b/activity.py
index f21efdd..d5ea2eb 100755
a
|
b
|
|
| 1 | import gtk |
1 | 2 | import olpcgames |
2 | | from gettext import gettext as _ |
| 3 | import pygame |
3 | 4 | |
| 5 | from sugar.graphics.toolbutton import ToolButton |
| 6 | from gettext import gettext as _ |
4 | 7 | |
5 | 8 | |
6 | 9 | class MazeActivity(olpcgames.PyGameActivity): |
7 | 10 | game_name = 'game' |
8 | 11 | game_title = _('Maze') |
9 | 12 | game_size = None # let olpcgames pick a nice size for us |
| 13 | |
| 14 | def build_toolbar(self): |
| 15 | """Build our Activity toolbar for the Sugar system.""" |
| 16 | toolbar = super(MazeActivity, self).build_toolbar() |
| 17 | |
| 18 | separator = gtk.SeparatorToolItem() |
| 19 | separator.set_expand(True) |
| 20 | separator.set_draw(False) |
| 21 | toolbar.insert(separator, 0) |
| 22 | |
| 23 | easier_button = ToolButton('list-remove') |
| 24 | easier_button.set_tooltip(_('Easier level')) |
| 25 | easier_button.connect('clicked', self._easier_button_cb) |
| 26 | toolbar.insert(easier_button, 2) |
| 27 | easier_button.show() |
| 28 | |
| 29 | harder_button = ToolButton('list-add') |
| 30 | harder_button.set_tooltip(_('Harder level')) |
| 31 | harder_button.connect('clicked', self._harder_button_cb) |
| 32 | toolbar.insert(harder_button, 2) |
| 33 | harder_button.show() |
| 34 | |
| 35 | return toolbar |
| 36 | |
| 37 | def _easier_button_cb(self, button): |
| 38 | pygame.event.post(olpcgames.eventwrap.Event( |
| 39 | pygame.USEREVENT, action='easier_button')) |
| 40 | |
| 41 | def _harder_button_cb(self, button): |
| 42 | pygame.event.post(olpcgames.eventwrap.Event( |
| 43 | pygame.USEREVENT, action='harder_button')) |
diff --git a/game.py b/game.py
index 579c5c4..5f2c09b 100644
a
|
b
|
class MazeGame: |
283 | 283 | (event, sys.exc_info()) |
284 | 284 | else: |
285 | 285 | print "Message from unknown buddy?" |
| 286 | if event.type == pygame.USEREVENT: |
| 287 | if event.action == 'harder_button': |
| 288 | self.harder() |
| 289 | elif event.action == 'easier_button': |
| 290 | self.easier() |
286 | 291 | else: |
287 | 292 | print "Unknown event:", event |
288 | 293 | |