Codebase list sugar-memorize-activity / 05811f4
Replace demo games combo by a button with a menu The combo with the text can be wide depending of the laguage and buttons fall out of the toolbar. Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org> Gonzalo Odiard 12 years ago
3 changed file(s) with 49 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
9494
9595 self._memorizeToolbarBuilder = \
9696 memorizetoolbar.MemorizeToolbarBuilder(self)
97
98 toolbar_box.toolbar.insert(gtk.SeparatorToolItem(), -1)
9799
98100 self._createToolbarBuilder = \
99101 createtoolbar.CreateToolbarBuilder(self)
0 <?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
1 <!ENTITY stroke_color "#010101">
2 <!ENTITY fill_color "#ffffff">
3 ]>
4 <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="55" height="55" viewBox="0 0 55 55" xml:space="preserve">
5 <g transform="matrix(0.58,0,0,0.58,24.53,0.11)">
6 <rect display="inline" fill="&fill_color;" height="10" stroke="&fill_color;" stroke-width="3.5" width="10" x="7.291" y="7.833"/>
7 <rect display="inline" fill="&stroke_color;" height="10" stroke="&fill_color;" stroke-width="3.5" width="10" x="22.625" y="7.833"/>
8 <rect display="inline" fill="&fill_color;" height="10" stroke="&fill_color;" stroke-width="3.5" width="10" x="37.375" y="7.833"/>
9 <rect display="inline" fill="&fill_color;" height="10" stroke="&fill_color;" stroke-width="3.5" width="10" x="7.291" y="22.75"/>
10 <rect display="inline" fill="&fill_color;" height="10" stroke="&fill_color;" stroke-width="3.5" width="10" x="22.625" y="22.75"/>
11 <rect display="inline" fill="&stroke_color;" height="10" stroke="&fill_color;" stroke-width="3.5" width="10" x="37.375" y="22.75"/>
12 <rect display="inline" fill="&stroke_color;" height="10" stroke="&fill_color;" stroke-width="3.5" width="10" x="7.291" y="37.625"/>
13 <rect display="inline" fill="&stroke_color;" height="10" stroke="&fill_color;" stroke-width="3.5" width="10" x="22.625" y="37.625"/>
14 <rect display="inline" fill="&stroke_color;" height="10" stroke="&fill_color;" stroke-width="3.5" width="10" x="37.375" y="37.625"/>
15 </g>
16 <g transform="translate(-0.2743801,0.51351)" id="g3036">
17 <path d="M 9.57,38.95 9.39,32.9 M 25.66,50.97 3.63,51.24 3.52,39.25 l 5.85,-6.36 21.26,0 -0.11,12.12 z M 3.63,39.38 l 21.48,0.27 0.33,10.92 m -0.31,-11.05 5.53,-6.64" style="fill:none;stroke:&fill_color;;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
18 <g transform="matrix(0,-1,-1,0,47.31,85.98)">
19 <g transform="translate(34.08,-1006.42)">
20 <polyline points="51.56,15.31 41.17,16.19 42.05,5.79" style="fill:none;stroke:&fill_color;;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round" transform="matrix(-0.47,0.47,-0.47,-0.47,66.29,1019.03)" />
21 <path d="m 39.36,1033.13 -0.06,9.91 -8.75,0.07" style="fill:none;stroke:&fill_color;;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
22 </g>
23 </g>
24 </g>
25 </svg>
2222 from sugar.graphics.toolcombobox import ToolComboBox
2323 from sugar.graphics.alert import Alert
2424 from sugar.graphics.icon import Icon
25 from sugar.activity.widgets import RadioMenuButton
26 from sugar.graphics.menuitem import MenuItem
2527
2628 import logging
2729 from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
3335
3436 __gtype_name__ = 'MemoryToolbarBuilder'
3537
36 standard_game_names = ['Load demo games',
37 'addition',
38 standard_game_names = ['addition',
3839 'letters',
3940 'sounds'
4041 ]
41 translated_game_names = [_('Load demo games'),
42 _('addition'),
43 _('letters'),
44 _('sounds')
42 translated_game_names = [_('Addition'),
43 _('Letters'),
44 _('Sounds')
4545 ]
4646
4747 __gsignals__ = {
6464 self.toolbar.insert(self._size_combo, -1)
6565 self._size_combo.combo.set_active(0)
6666
67 # Change demo games combobox
68 self._game_combo = ToolComboBox()
69 for i, f in enumerate(self.standard_game_names):
70 f = _(f)
71 self._game_combo.combo.append_item(i, f)
72 self._game_combo.combo.set_active(0)
73 self._game_combo.combo.connect('changed', self._game_changed_cb)
74 self.toolbar.insert(self._game_combo, -1)
67 # Change demo games button
68 self._demo_games = RadioMenuButton(icon_name='memorize-collection')
69 self._demo_games.props.tooltip = _('Load demo games')
70
71 for i, game in enumerate(self.translated_game_names):
72 menu_item = MenuItem(game)
73 menu_item.connect('activate', self.__activate_game_cb, i)
74 self._demo_games.props.palette.menu.append(menu_item)
75 menu_item.show()
76 self.toolbar.insert(self._demo_games, -1)
7577
7678 # Reset Button
7779 self._restart_button = ToolButton('game-new')
8890
8991 def update_controls(self, active):
9092 self._size_combo.set_sensitive(active)
91 self._game_combo.set_sensitive(active)
93 self._demo_games.set_sensitive(active)
9294 self._restart_button.set_sensitive(active and
9395 self.activity.game.model.count > 0)
9496
99101 game_size = int(self._sizes[self._size_combo.combo.get_active()][0])
100102 self.emit('game_changed', None, game_size, 'size', None, None)
101103
102 def _game_changed_cb(self, combobox):
103 if combobox.get_active() == 0:
104 return
104 def __activate_game_cb(self, menu, i):
105 self._game_selected_index = i
105106 if self.activity.game.model.is_demo:
106107 self._change_game()
107108 else:
121122 self._change_game()
122123
123124 def _change_game(self):
124 current_game = self._game_combo.combo.get_active()
125 game_name = self.standard_game_names[current_game]
126 title = game_name
125 title = self.translated_game_names[self._game_selected_index]
127126 game_size = int(self._sizes[self._size_combo.combo.get_active()][0])
128127
129 if game_name in self.translated_game_names:
130 index = self.translated_game_names.index(game_name)
131 game_name = self.standard_game_names[index]
128 game_name = self.standard_game_names[self._game_selected_index]
132129
133130 game_file = join(dirname(__file__), 'demos', game_name + '.zip')
134 self._game_combo.combo.set_active(0)
135131 self.emit('game_changed', game_file, game_size, 'demo', title, None)
136132
137133 def update_toolbar(self, widget, data, grid):