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
94 | 94 | |
95 | 95 | self._memorizeToolbarBuilder = \ |
96 | 96 | memorizetoolbar.MemorizeToolbarBuilder(self) |
97 | ||
98 | toolbar_box.toolbar.insert(gtk.SeparatorToolItem(), -1) | |
97 | 99 | |
98 | 100 | self._createToolbarBuilder = \ |
99 | 101 | 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>⏎ |
22 | 22 | from sugar.graphics.toolcombobox import ToolComboBox |
23 | 23 | from sugar.graphics.alert import Alert |
24 | 24 | from sugar.graphics.icon import Icon |
25 | from sugar.activity.widgets import RadioMenuButton | |
26 | from sugar.graphics.menuitem import MenuItem | |
25 | 27 | |
26 | 28 | import logging |
27 | 29 | from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT |
33 | 35 | |
34 | 36 | __gtype_name__ = 'MemoryToolbarBuilder' |
35 | 37 | |
36 | standard_game_names = ['Load demo games', | |
37 | 'addition', | |
38 | standard_game_names = ['addition', | |
38 | 39 | 'letters', |
39 | 40 | 'sounds' |
40 | 41 | ] |
41 | translated_game_names = [_('Load demo games'), | |
42 | _('addition'), | |
43 | _('letters'), | |
44 | _('sounds') | |
42 | translated_game_names = [_('Addition'), | |
43 | _('Letters'), | |
44 | _('Sounds') | |
45 | 45 | ] |
46 | 46 | |
47 | 47 | __gsignals__ = { |
64 | 64 | self.toolbar.insert(self._size_combo, -1) |
65 | 65 | self._size_combo.combo.set_active(0) |
66 | 66 | |
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) | |
75 | 77 | |
76 | 78 | # Reset Button |
77 | 79 | self._restart_button = ToolButton('game-new') |
88 | 90 | |
89 | 91 | def update_controls(self, active): |
90 | 92 | self._size_combo.set_sensitive(active) |
91 | self._game_combo.set_sensitive(active) | |
93 | self._demo_games.set_sensitive(active) | |
92 | 94 | self._restart_button.set_sensitive(active and |
93 | 95 | self.activity.game.model.count > 0) |
94 | 96 | |
99 | 101 | game_size = int(self._sizes[self._size_combo.combo.get_active()][0]) |
100 | 102 | self.emit('game_changed', None, game_size, 'size', None, None) |
101 | 103 | |
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 | |
105 | 106 | if self.activity.game.model.is_demo: |
106 | 107 | self._change_game() |
107 | 108 | else: |
121 | 122 | self._change_game() |
122 | 123 | |
123 | 124 | 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] | |
127 | 126 | game_size = int(self._sizes[self._size_combo.combo.get_active()][0]) |
128 | 127 | |
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] | |
132 | 129 | |
133 | 130 | game_file = join(dirname(__file__), 'demos', game_name + '.zip') |
134 | self._game_combo.combo.set_active(0) | |
135 | 131 | self.emit('game_changed', game_file, game_size, 'demo', title, None) |
136 | 132 | |
137 | 133 | def update_toolbar(self, widget, data, grid): |