Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/PascalTriangle.activity
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2013-08-19 00:34:37 (GMT)
committer Philip Withnall <philip@tecnocode.co.uk>2013-08-19 00:34:37 (GMT)
commit9dad3344b2e2f8912a78a1a89828a7f44767c082 (patch)
tree2b4818b7743d534fa6f615bc2a18216123f8e652 /PascalTriangle.activity
parentb866e5563835a7fae36d026966de5373b726b2b7 (diff)
Replace message dialogue with an alert bar
Much tidier.
Diffstat (limited to 'PascalTriangle.activity')
-rwxr-xr-xPascalTriangle.activity/pascaltriangle.py46
1 files changed, 30 insertions, 16 deletions
diff --git a/PascalTriangle.activity/pascaltriangle.py b/PascalTriangle.activity/pascaltriangle.py
index 68513c5..6042031 100755
--- a/PascalTriangle.activity/pascaltriangle.py
+++ b/PascalTriangle.activity/pascaltriangle.py
@@ -17,6 +17,8 @@
# along with Pascal Triangle. If not, see <http://www.gnu.org/licenses/>.
from sugar3.activity import activity, widgets
+from sugar3.graphics.alert import Alert
+from sugar3.graphics.icon import Icon
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics.toggletoolbutton import ToggleToolButton
@@ -67,8 +69,9 @@ class PascalTriangleActivity(activity.Activity):
drawing_area.show()
self._drawing_area = drawing_area
- # Start with hints off.
+ # Start with hints off and no 'game over' alert.
self._show_hints = False
+ self._alert = None
# Start a new game.
self._start_game()
@@ -81,6 +84,11 @@ class PascalTriangleActivity(activity.Activity):
# Focus the drawing area so it can receive keyboard events.
self._drawing_area.grab_focus()
+ # Clear any alerts from the previous game.
+ if self._alert:
+ self.remove_alert(self._alert)
+ self._alert = None
+
# Set the initial size of the Pascal triangle to be drawn. This is
# the number of cells on its base (equivalently, the number of rows in
# the triangle).
@@ -338,21 +346,27 @@ class PascalTriangleActivity(activity.Activity):
# Check whether all blank cells have been filled.
if len(self._blank_cells) == 0:
- dialog = Gtk.MessageDialog(self,
- Gtk.DialogFlags.DESTROY_WITH_PARENT,
- Gtk.MessageType.INFO, Gtk.ButtonsType.NONE,
- 'Well done! You’ve completed the Pascal Triangle. ' +
- 'Do you want to play again?')
- dialog.add_buttons('_New Game', Gtk.ResponseType.ACCEPT,
- '_Quit', Gtk.ResponseType.CLOSE)
-
- if dialog.run() == Gtk.ResponseType.ACCEPT:
- # Start a new game.
- self._start_game()
- dialog.destroy()
- else:
- # Quit.
- self.close()
+ alert = Alert()
+ alert.props.title = 'You’ve won!'
+ alert.props.msg = 'Well done! You’ve completed the Pascal ' + \
+ 'Triangle. Do you want to play again?'
+ icon = Icon(icon_name = 'emblem-favorite')
+ alert.props.icon = icon
+ icon.show()
+
+ icon = Icon(icon_name = 'add')
+ alert.add_button(Gtk.ResponseType.ACCEPT, 'New Game', icon)
+ icon.show()
+
+ alert.connect('response', self._alert_response_cb)
+
+ alert.show()
+ self._alert = alert
+ self.add_alert(alert)
+
+
+ def _alert_response_cb(self, alert, response_id):
+ self._start_game()
def get_show_hints(self):