diff options
author | Walter Bender <walter.bender@gmail.com> | 2013-08-20 13:27:55 (GMT) |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2013-08-20 13:27:55 (GMT) |
commit | 9f834e103326d0fa31ec3f50f7e7e82adc55e74c (patch) | |
tree | 6654cbcf09e83b8fc462861c229af2ba7aefcf4f | |
parent | f07493c294eaddd6839e2f9920fc3f18e5471a4c (diff) |
Toolbar consistency fixes
-rw-r--r--[-rwxr-xr-x] | PascalTriangle.activity/pascaltriangle.py | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/PascalTriangle.activity/pascaltriangle.py b/PascalTriangle.activity/pascaltriangle.py index 63ccd3c..e478821 100755..100644 --- a/PascalTriangle.activity/pascaltriangle.py +++ b/PascalTriangle.activity/pascaltriangle.py @@ -17,8 +17,11 @@ # along with Pascal Triangle. If not, see <http://www.gnu.org/licenses/>. from sugar3.activity import activity, widgets +from sugar3.activity.widgets import ActivityToolbarButton +from sugar3.activity.widgets import StopButton from sugar3.graphics.alert import Alert from sugar3.graphics.icon import Icon +from sugar3.graphics.toolbarbox import ToolbarButton from sugar3.graphics.toolbarbox import ToolbarBox from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.toggletoolbutton import ToggleToolButton @@ -39,30 +42,59 @@ class PascalTriangleActivity(activity.Activity): cells which contribute to the currently selected one. """ def __init__(self, handle): - activity.Activity.__init__(self, handle, False) + super(PascalTriangleActivity, self).__init__(handle) + + self.max_participants = 1 # No sharing # Create the standard activity toolbox. toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) toolbar_box.show() - activity_toolbar = widgets.ActivityToolbar(self) - toolbar_box.add(activity_toolbar) - activity_toolbar.show() + main_toolbar = toolbar_box.toolbar - activity_toolbar.share.props.visible = False + activity_toolbar_button = ActivityToolbarButton(self) + main_toolbar.insert(activity_toolbar_button, 0) + activity_toolbar_button.show() new_game_button = NewGameButton(self) new_game_button.show() - activity_toolbar.insert(new_game_button, 0) + main_toolbar.insert(new_game_button, -1) hint_button = HintButton(self) hint_button.show() - activity_toolbar.insert(hint_button, 1) + main_toolbar.insert(hint_button, -1) + + separator = Gtk.SeparatorToolItem() + separator.props.draw = True + separator.set_expand(False) + separator.show() + main_toolbar.insert(separator, -1) + + slider = Gtk.HScale() + slider.props.digits = 0 # integers only + slider.props.draw_value = False + slider.props.has_origin = False + slider.set_range(2, 10) + slider.set_increments(1, 2) + slider.set_value(5) # initial triangle size + slider.set_size_request(150, 15) + slider.show() + + toolitem = Gtk.ToolItem() + toolitem.add(slider) + toolitem.show() + main_toolbar.insert(toolitem, -1) + + separator = Gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_expand(True) + separator.show() + main_toolbar.insert(separator, -1) stop_button = widgets.StopButton(self) stop_button.show() - activity_toolbar.insert(stop_button, -1) + main_toolbar.insert(stop_button, -1) # Create a new GTK+ drawing area drawing_area = Gtk.DrawingArea() @@ -82,20 +114,6 @@ class PascalTriangleActivity(activity.Activity): overlay.add(drawing_area) overlay.show() - slider = Gtk.VScale() - slider.props.digits = 0 # integers only - slider.props.draw_value = False - slider.props.has_origin = False - slider.set_range(2, 10) - slider.set_increments(1, 2) - slider.set_value(5) # initial triangle size - - slider.props.halign = Gtk.Align.START - slider.props.valign = Gtk.Align.START - slider.set_size_request(70, 150) - slider.show() - overlay.add_overlay(slider) - self._triangle_size = int(slider.get_value()) slider.connect('value-changed', self.__slider_value_changed_cb, None) @@ -117,7 +135,6 @@ class PascalTriangleActivity(activity.Activity): # Start a new game. self.start_game() - def start_game(self): """Start a new game, clearing the previous game and any alerts.""" # Focus the drawing area so it can receive keyboard events. @@ -138,7 +155,6 @@ class PascalTriangleActivity(activity.Activity): self._drawing_area.queue_draw() - def _update_current_cell(self, index): """Change position of the currently selected cell and clear any pending text edits.""" @@ -147,7 +163,6 @@ class PascalTriangleActivity(activity.Activity): self._current_cell_text = '' self._drawing_area.queue_draw() - def _calculate_number_of_cells(self): """Calculate the number of cells in the triangle. @@ -156,7 +171,6 @@ class PascalTriangleActivity(activity.Activity): """ return self._triangle_size * (self._triangle_size + 1) / 2 - def _generate_blank_cell_list(self): """Generate a non-empty list of random cell indices. @@ -177,7 +191,6 @@ class PascalTriangleActivity(activity.Activity): # list after this. return list(set(blank_cells)) - def _calculate_pascal_number(self, index): """Calculate the Pascal number for the (row, column) cell. @@ -191,7 +204,6 @@ class PascalTriangleActivity(activity.Activity): denom = math.factorial(column) * math.factorial(row - column) return num / denom - def __drawing_area_button_press_cb(self, widget, event, data = None): """Handle a mouse button press in the drawing area.""" # Check whether the click fell within a cell; if so, change the cell @@ -227,7 +239,6 @@ class PascalTriangleActivity(activity.Activity): self._update_current_cell((-1, -1)) return True - def _is_cursor_in_radius(self, radius, cell_position, cursor_position): """Calculate whether cursor_position falls within radius of cell_position.""" @@ -235,7 +246,6 @@ class PascalTriangleActivity(activity.Activity): (cell_position[1] - cursor_position[1]) ** 2 return (actual_radius_sq <= radius ** 2) - def __drawing_area_key_press_cb(self, widget, event, data = None): """Handle a keyboard button press in the drawing area.""" if event.type != Gdk.EventType.KEY_PRESS: @@ -284,7 +294,6 @@ class PascalTriangleActivity(activity.Activity): # If the key pressed wasn't a digit or control character, ignore it. return True - def __drawing_area_draw_cb(self, widget, ctx, data = None): """Redraw the drawing area and all its contents.""" # Widget allocation and sizes. The cell_height is calculated weirdly @@ -318,7 +327,6 @@ class PascalTriangleActivity(activity.Activity): return True - def _calculate_cell_position(self, base_width, cell_width, cell_height, index): """Calculate the cell position. @@ -334,7 +342,6 @@ class PascalTriangleActivity(activity.Activity): (cell_height * index[0] * (2.0 / 3.0)) return (cell_x, cell_y) - def _get_cell_background(self, index): """Get the background colour to use for the given cell.""" if index == self._current_cell: @@ -355,7 +362,6 @@ class PascalTriangleActivity(activity.Activity): # Non-selected, normal cell background. return cairo.SolidPattern(1.0, 1.0, 1.0) # white - def _draw_cell(self, ctx, index, cell_width, cell_height): """Draw a single cell. @@ -404,7 +410,6 @@ class PascalTriangleActivity(activity.Activity): ctx.set_font_size(font_size) ctx.show_text(cell_text) - def _check_current_cell_text(self): """Check the user-entered text for the current cell. @@ -439,12 +444,10 @@ class PascalTriangleActivity(activity.Activity): self._alert = alert self.add_alert(alert) - def __alert_response_cb(self, alert, response_id): """Callback from the 'game over' alert.""" self.start_game() - def get_show_hints(self): """Get whether hints should be rendered.""" return self._show_hints @@ -456,7 +459,6 @@ class PascalTriangleActivity(activity.Activity): show_hints = property(get_show_hints, set_show_hints) - def __slider_value_changed_cb(self, widget, data = None): """Handle value changes on the triangle size slider.""" new_triangle_size = int(widget.get_value()) |