Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorialtoolbar.py
blob: 8e41a2d6c71c3fb2a7af1f17612b8eeaca34d801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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)