diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2013-08-19 00:16:57 (GMT) |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2013-08-19 00:16:57 (GMT) |
commit | b866e5563835a7fae36d026966de5373b726b2b7 (patch) | |
tree | 2186d002539d0a49ea734f75462de5f07a38008d /PascalTriangle.activity/pascaltriangle.py | |
parent | 24d156709a4b91bb8ee9bbd307eeffb863be49c8 (diff) |
Add a hint mode which shows the summands for the current cell
Diffstat (limited to 'PascalTriangle.activity/pascaltriangle.py')
-rwxr-xr-x | PascalTriangle.activity/pascaltriangle.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/PascalTriangle.activity/pascaltriangle.py b/PascalTriangle.activity/pascaltriangle.py index 4edb708..68513c5 100755 --- a/PascalTriangle.activity/pascaltriangle.py +++ b/PascalTriangle.activity/pascaltriangle.py @@ -19,6 +19,7 @@ from sugar3.activity import activity, widgets from sugar3.graphics.toolbarbox import ToolbarBox from sugar3.graphics.toolbutton import ToolButton +from sugar3.graphics.toggletoolbutton import ToggleToolButton import math, random from gi.repository import Gtk, Gdk import cairo @@ -42,6 +43,10 @@ class PascalTriangleActivity(activity.Activity): new_game_button.show() activity_toolbar.insert(new_game_button, 0) + hint_button = HintButton(self) + hint_button.show() + activity_toolbar.insert(hint_button, 1) + stop_button = widgets.StopButton(self) stop_button.show() activity_toolbar.insert(stop_button, -1) @@ -62,6 +67,9 @@ class PascalTriangleActivity(activity.Activity): drawing_area.show() self._drawing_area = drawing_area + # Start with hints off. + self._show_hints = False + # Start a new game. self._start_game() @@ -265,6 +273,10 @@ class PascalTriangleActivity(activity.Activity): def _get_cell_background(self, row_index, column_index): if (row_index, column_index) == self._current_cell: return cairo.SolidPattern(0.0, 0.7, 0.0) # green + elif self._show_hints and row_index == self._current_cell[0] - 1 and \ + (column_index == self._current_cell[1] - 1 or \ + column_index == self._current_cell[1]): + return cairo.SolidPattern(0.5, 0.5, 0.0) # yellow return cairo.SolidPattern(1.0, 1.0, 1.0) # white @@ -343,6 +355,16 @@ class PascalTriangleActivity(activity.Activity): self.close() + def get_show_hints(self): + return self._show_hints + + def set_show_hints(self, val): + self._show_hints = val + self._drawing_area.queue_draw() + + show_hints = property(get_show_hints, set_show_hints) + + class NewGameButton(ToolButton): def __init__(self, activity, **kwargs): ToolButton.__init__(self, 'add', **kwargs) @@ -352,3 +374,15 @@ class NewGameButton(ToolButton): def __new_game_button_clicked_cb(self, button, activity): activity._start_game() + + +class HintButton(ToggleToolButton): + def __init__(self, activity, **kwargs): + ToggleToolButton.__init__(self, 'toolbar-help', **kwargs) + #self.props.tooltip = 'Show Hints' + self.set_tooltip('Show Hints') + self.props.accelerator = '<Ctrl>H' + self.connect('clicked', self.__hint_button_clicked_cb, activity) + + def __hint_button_clicked_cb(self, button, activity): + activity.show_hints = self.get_active() |