Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/edittoolbar.py
blob: ad356efe93c6b67540ff04371d83c6862215e133 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# -*- 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 os.path import join, dirname

from gettext import gettext as _
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.objectchooser import ObjectChooser
import logging
from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT, TYPE_NONE, TYPE_INT

class EditToolbar(gtk.Toolbar):
    __gtype_name__ = 'EditToolbar'

    __gsignals__ = {
        'edit': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
        'add-x': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
        'add-circle': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
        'add-triangle': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
        'add-square': (SIGNAL_RUN_FIRST, TYPE_NONE, []), 
        'save-game': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
        'load-game': (SIGNAL_RUN_FIRST, TYPE_NONE, []), 
    }

    def __init__(self, activity):
        gtk.Toolbar.__init__(self)
        self.activity = activity
        self._is_editing = 0

        # Edit Button
        self._edit_button = ToolButton()
        self._edit_button.set_label(_('Edit'))
        self._edit_button.connect('clicked', self._edit_cb)
        self.insert(self._edit_button, -1)
        self._edit_button.show()

        # Separator
        separator = gtk.SeparatorToolItem()
        separator.set_draw(True)
        self.insert(separator, -1)

        # Add X Toggle Button
        add_x_icon = join(dirname(__file__), 'images', 'XWhite.gif')
        add_x_image = gtk.Image()
        add_x_image.set_from_file(add_x_icon)
        self._add_x_button = ToolButton()
        self._add_x_button.set_icon_widget(add_x_image)
        self._add_x_button.connect('clicked', self._add_x_cb)
        self.insert(self._add_x_button, -1)
        self._add_x_button.show()

        # Add Circle Toggle Button
        add_circle_icon = join(dirname(__file__), 'images', 'CircleWhite.gif')
        add_circle_image = gtk.Image()
        add_circle_image.set_from_file(add_circle_icon)
        self._add_circle_button = ToolButton()
        self._add_circle_button.set_icon_widget(add_circle_image)
        self._add_circle_button.connect('clicked', self._add_circle_cb)
        self.insert(self._add_circle_button, -1)
        self._add_circle_button.show()

        # Add Triangle Toggle Button
        add_triangle_icon = join(dirname(__file__), 'images', 'TriangleWhite.gif')
        add_triangle_image = gtk.Image()
        add_triangle_image.set_from_file(add_triangle_icon)
        self._add_triangle_button = ToolButton()
        self._add_triangle_button.set_icon_widget(add_triangle_image)
        self._add_triangle_button.connect('clicked', self._add_triangle_cb)
        self.insert(self._add_triangle_button, -1)
        self._add_triangle_button.show()

        # Add Square Toggle Button
        add_square_icon = join(dirname(__file__), 'images', 'SquareWhite.gif')
        add_square_image = gtk.Image()
        add_square_image.set_from_file(add_square_icon)
        self._add_square_button = ToolButton()
        self._add_square_button.set_icon_widget(add_square_image)
        self._add_square_button.connect('clicked', self._add_square_cb)
        self.insert(self._add_square_button, -1)
        self._add_square_button.show()

        # Separator
        separator = gtk.SeparatorToolItem()
        separator.set_draw(True)
        self.insert(separator, -1)

        # Load Button
        self._load_button = ToolButton()
        self._load_button.set_label(_('Load'))
        self._load_button.connect('clicked', self._load_cb)
        self.insert(self._load_button, -1)
        self._load_button.show()
	
        # Save Button
        self._save_button = ToolButton()
        self._save_button.set_label(_('Save'))
        self._save_button.connect('clicked', self._save_cb)
        self.insert(self._save_button, -1)
        self._save_button.show()

    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 _edit_cb(self, widget):
        if self._is_editing == 0:
            self._is_editing = 1
            self._edit_button.set_label(_('Finished'))
        else:
            self._is_editing = 0
            self._edit_button.set_label(_('Edit'))
        self._edit_button.set_sensitive(True)
        self.emit('edit')

    def activate_edit(self):
        self._edit_button.set_sensitive(True)
    
    def grey_out_edit(self):
        self._edit_button.set_sensitive(False)

    def _add_x_cb(self, widget):
        self._add_x_button.set_sensitive(False)
        self.emit('add-x')

    def activate_add_x(self):
        self._add_x_button.set_sensitive(True)
    
    def grey_out_add_x(self):
        self._add_x_button.set_sensitive(False)

    def _add_square_cb(self, widget):
        self._add_square_button.set_sensitive(False)
        self.emit('add-square')

    def activate_add_square(self):
        self._add_square_button.set_sensitive(True)
    
    def grey_out_add_square(self):
        self._add_square_button.set_sensitive(False)

    def _add_circle_cb(self, widget):
        self._add_circle_button.set_sensitive(False)
        self.emit('add-circle')

    def activate_add_circle(self):
        self._add_circle_button.set_sensitive(True)
    
    def grey_out_add_circle(self):
        self._add_circle_button.set_sensitive(False)

    def _add_triangle_cb(self, widget):
        self._add_triangle_button.set_sensitive(False)
        self.emit('add-triangle')

    def activate_add_triangle(self):
        self._add_triangle_button.set_sensitive(True)
    
    def grey_out_add_triangle(self):
        self._add_triangle_button.set_sensitive(False)

    def _save_cb(self, widget):
        self._save_button.set_sensitive(True)
        self.emit('save-game')

    def activate_save(self):
        self._save_button.set_sensitive(True)
    
    def grey_out_save(self):
        self._save_button.set_sensitive(False)

    def _load_cb(self, widget):
        self._load_button.set_sensitive(True)
        self.emit('load-game')

    def activate_load(self):
        self._load_button.set_sensitive(True)
    
    def grey_out_load(self):
        self._load_button.set_sensitive(False)