diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2013-08-18 23:42:36 (GMT) |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2013-08-18 23:42:36 (GMT) |
commit | 24d156709a4b91bb8ee9bbd307eeffb863be49c8 (patch) | |
tree | aad2842a90af41e3eaf983dd40d2243c57ecb8ec /PascalTriangle.activity/pascaltriangle.py | |
parent | d21619c9bf82afe61e1e45d8b38d2a4b154fb42c (diff) |
Add a ‘New Game’ button
Diffstat (limited to 'PascalTriangle.activity/pascaltriangle.py')
-rwxr-xr-x | PascalTriangle.activity/pascaltriangle.py | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/PascalTriangle.activity/pascaltriangle.py b/PascalTriangle.activity/pascaltriangle.py index 49bf61c..4edb708 100755 --- a/PascalTriangle.activity/pascaltriangle.py +++ b/PascalTriangle.activity/pascaltriangle.py @@ -18,6 +18,7 @@ from sugar3.activity import activity, widgets from sugar3.graphics.toolbarbox import ToolbarBox +from sugar3.graphics.toolbutton import ToolButton import math, random from gi.repository import Gtk, Gdk import cairo @@ -37,6 +38,10 @@ class PascalTriangleActivity(activity.Activity): activity_toolbar.share.props.visible = False + new_game_button = NewGameButton(self) + new_game_button.show() + activity_toolbar.insert(new_game_button, 0) + stop_button = widgets.StopButton(self) stop_button.show() activity_toolbar.insert(stop_button, -1) @@ -55,17 +60,18 @@ class PascalTriangleActivity(activity.Activity): # Parent and show the drawing area. self.set_canvas(drawing_area) drawing_area.show() + self._drawing_area = drawing_area # Start a new game. - self._start_game(drawing_area) + self._start_game() """ Start a new game, clearing the previous game. """ - def _start_game(self, drawing_area): + def _start_game(self): # Focus the drawing area so it can receive keyboard events. - drawing_area.grab_focus() + self._drawing_area.grab_focus() # 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 @@ -83,7 +89,7 @@ class PascalTriangleActivity(activity.Activity): # Generate a list of blank cells which the user needs to fill in. self._blank_cells = self._generate_blank_cell_list() - drawing_area.queue_draw() + self._drawing_area.queue_draw() """ @@ -330,8 +336,19 @@ class PascalTriangleActivity(activity.Activity): if dialog.run() == Gtk.ResponseType.ACCEPT: # Start a new game. - self._start_game(widget) + self._start_game() dialog.destroy() else: # Quit. self.close() + + +class NewGameButton(ToolButton): + def __init__(self, activity, **kwargs): + ToolButton.__init__(self, 'add', **kwargs) + self.props.tooltip = 'New Game' + self.props.accelerator = '<Ctrl>N' + self.connect('clicked', self.__new_game_button_clicked_cb, activity) + + def __new_game_button_clicked_cb(self, button, activity): + activity._start_game() |