diff options
Diffstat (limited to 'tutorialtoolbar.py')
-rw-r--r-- | tutorialtoolbar.py | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/tutorialtoolbar.py b/tutorialtoolbar.py new file mode 100644 index 0000000..8e41a2d --- /dev/null +++ b/tutorialtoolbar.py @@ -0,0 +1,134 @@ +# -*- coding: UTF-8 -*- +# Copyright 2007-2008 One Laptop Per Child +# Copyright 2007 Gerard J. Cerchio <www.circlesoft.com> +# Copyright 2008 Andrés Ambrois <andresambrois@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import gtk + +from gettext import gettext as _ +from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.toolcombobox import ToolComboBox +from sugar.graphics.objectchooser import ObjectChooser +import logging +from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT, TYPE_NONE, TYPE_INT, TYPE_STRING + +class TutorialToolbar(gtk.Toolbar): + __gtype_name__ = 'TutorialToolbar' + + __gsignals__ = { + 'begin': (SIGNAL_RUN_FIRST, TYPE_NONE, []), + 'previous': (SIGNAL_RUN_FIRST, TYPE_NONE, []), + 'next': (SIGNAL_RUN_FIRST, TYPE_NONE, []), + 'change-category': (SIGNAL_RUN_FIRST, TYPE_NONE, [TYPE_STRING]), + } + + def __init__(self, activity): + gtk.Toolbar.__init__(self) + self.activity = activity + + + # Begin Button + + self._begin_button = ToolButton() + self._begin_button.set_label(_('Begin!')) + self._begin_button.connect('clicked', self._begin_cb) + self.insert(self._begin_button, -1) + self._begin_button.show() + + # Separator + + separator = gtk.SeparatorToolItem() + separator.set_draw(True) + self.insert(separator, -1) + + # Previous Button + + self._previous_button = ToolButton() + self._previous_button.set_label(_('Previous')) + self._previous_button.connect('clicked', self._previous_cb) + self.insert(self._previous_button, -1) + self._previous_button.show() + + # Next Button + + self._next_button = ToolButton() + self._next_button.set_label(_('Next')) + self._next_button.connect('clicked', self._next_cb) + self.insert(self._next_button, -1) + self._next_button.show() + + # Second Separator + + self.insert(separator, -1) + + # Quick Category Dropdown Menu + + self._add_widget(gtk.Label(_('Categories') + ': ')) + self._category_combo = ToolComboBox() + self._categories = [' ', 'Board', 'Play', 'Territory', 'Scoring', 'Liberties', 'Capturing', 'Seki', 'Ko', 'Superko', 'Life and Death', 'Ko Fight', 'Semeai', 'Sente/Gote', 'End Game'] + for i, f in enumerate(self._categories): + self._category_combo.combo.append_item(i, f) + self._category_combo.combo.connect('changed', self._category_cb) + self._add_widget(self._category_combo) + self._category_combo.combo.set_active(0) + + + def _add_widget(self, widget, expand = False): + tool_item = gtk.ToolItem() + tool_item.set_expand(expand) + tool_item.add(widget) + widget.show() + self.insert(tool_item, -1) + tool_item.show() + + def activate_begin(self): + self._begin_button.set_sensitive(True) + + def _begin_cb(self, widget): + self._begin_button.set_sensitive(False) + self.emit('begin') + + def grey_out_previous(self): + self._previous_button.set_sensitive(False) + + def activate_previous(self): + self._previous_button.set_sensitive(True) + + def _previous_cb(self, widget): + self._previous_button.set_sensitive(True) + self.emit('previous') + + def grey_out_next(self): + self._next_button.set_sensitive(False) + + def activate_next(self): + self._next_button.set_sensitive(True) + + def _next_cb(self, widget): + self._next_button.set_sensitive(True) + self.emit('next') + + def grey_out_category(self): + self._category_combo.set_sensitive(False) + + def activate_category(self): + self._category_combo.set_sensitive(True) + + def _category_cb(self, widget): + self.category = int(self._categories[self._category_combo.combo.get_active()]) + self.emit('change-category', self.category) + |