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
|
#!/usr/bin/env python
#
# Copyright (C) 2007, Joseph C. Lee
#
# 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 logging
_logger = logging.getLogger('implode-activity')
from gettext import gettext as _
from sugar.activity.activity import Activity, ActivityToolbox
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.radiotoolbutton import RadioToolButton
import implodegame
#import sys, os
import gtk
import gobject
_EASY = 0
_MEDIUM = 1
_HARD = 2
class ImplodeActivity(Activity):
def hello(self, widget, data=None):
logging.info("Hello World")
def __init__(self, handle):
super(ImplodeActivity, self).__init__(handle)
_logger.debug('Starting implode activity...')
self._game = implodegame.ImplodeGame()
toolbox = _Toolbox(self)
self.set_toolbox(toolbox)
toolbox.show()
for (signal, func) in (('new-game-clicked' , self._game.new_game),
('replay-game-clicked', self._game.replay_game),
('undo-clicked' , self._game.undo),
('redo-clicked' , self._game.redo)):
def callback(source, func=func):
func()
toolbox.connect(signal, callback)
for (signal, level) in (('easy-clicked' , 0),
('medium-clicked', 1),
('hard-clicked' , 2)):
def callback(source, level=level):
self._game.set_level(level)
toolbox.connect(signal, callback)
self.set_canvas(self._game)
self.show_all()
class _Toolbox(ActivityToolbox):
__gsignals__ = {
'new-game-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
'replay-game-clicked': (gobject.SIGNAL_RUN_LAST, None, ()),
'undo-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
'redo-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
'easy-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
'medium-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
'hard-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
}
def __init__(self, activity):
super(_Toolbox, self).__init__(activity)
toolbar = gtk.Toolbar()
def add_button(icon_name, tooltip, signal_name):
button = ToolButton(icon_name)
toolbar.add(button)
def callback(source):
self.emit(signal_name)
button.connect('clicked', callback)
button.set_tooltip(tooltip)
return button
add_button('new-game' , _("New") , 'new-game-clicked')
add_button('replay-game', _("Replay"), 'replay-game-clicked')
add_button('edit-undo' , _("Undo") , 'undo-clicked')
add_button('edit-redo' , _("Redo") , 'redo-clicked')
toolbar.add(gtk.SeparatorToolItem())
levels = []
def add_level_button(icon_name, tooltip, signal_name):
if levels:
button = RadioToolButton(icon_name, levels[0])
else:
button = RadioToolButton(icon_name)
levels.append(button)
toolbar.add(button)
def callback(source):
if source.get_active():
self.emit(signal_name)
button.connect('clicked', callback)
button.set_tooltip(tooltip)
add_level_button('easy-level' , _("Easy") , 'easy-clicked')
add_level_button('medium-level', _("Medium"), 'medium-clicked')
add_level_button('hard-level' , _("Hard") , 'hard-clicked')
self.add_toolbar(_("Game"), toolbar)
self.set_current_toolbar(1)
|