-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpbutton.py
133 lines (108 loc) · 4.67 KB
/
helpbutton.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2012, Gonzalo Odiard <[email protected]>
# Copyright (C) 2012, Walter Bender <[email protected]>
# 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 3 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
# HelpButton widget
from gettext import gettext as _
import gtk
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.icon import Icon
from sugar.graphics import style
import logging
''' Set up a help palette for the main toolbars '''
help_palettes = {}
help_windows = {}
help_box = gtk.VBox()
help_box.set_homogeneous(False)
help_palettes['main-toolbar'] = help_box
help_windows['main-toolbar'] = gtk.ScrolledWindow()
help_windows['main-toolbar'].set_size_request(
int(gtk.gdk.screen_width() / 3),
gtk.gdk.screen_height() - style.GRID_CELL_SIZE * 3)
help_windows['main-toolbar'].set_policy(
gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
help_windows['main-toolbar'].add_with_viewport(
help_palettes['main-toolbar'])
help_palettes['main-toolbar'].show()
class HelpButton(gtk.ToolItem):
def __init__(self, activity):
self._activity = activity
gtk.ToolItem.__init__(self)
help_button = ToolButton('toolbar-help')
help_button.set_tooltip(_('Ayuda'))
self.add(help_button)
help_button.show()
self._palette = help_button.get_palette()
help_button.connect('clicked', self.__help_button_clicked_cb)
def set_current_palette(self, name):
self._current_palette = name
def __help_button_clicked_cb(self, button):
self._palette.set_content(help_windows['main-toolbar'])
help_windows['main-toolbar'].show_all()
self._palette.popup(immediate=True, state=1)
def add_section(help_box, section_text, icon=None):
''' Add a section to the help palette. From helpbutton.py by
Gonzalo Odiard '''
max_text_width = int(gtk.gdk.screen_width() / 3) - 20
hbox = gtk.HBox()
label = gtk.Label()
label.set_use_markup(True)
label.set_markup('<b>%s</b>' % section_text)
label.set_line_wrap(True)
label.set_size_request(max_text_width, -1)
hbox.add(label)
if icon is not None:
_icon = Icon(icon_name=icon)
hbox.add(_icon)
label.set_size_request(max_text_width - 20, -1)
else:
label.set_size_request(max_text_width, -1)
hbox.show_all()
help_box.pack_start(hbox, False, False, padding=5)
def add_paragraph(help_box, text, icon=None):
''' Add an entry to the help palette. From helpbutton.py by
Gonzalo Odiard '''
max_text_width = int(gtk.gdk.screen_width() / 3) - 20
hbox = gtk.HBox()
label = gtk.Label(text)
label.set_justify(gtk.JUSTIFY_LEFT)
label.set_line_wrap(True)
hbox.add(label)
if icon is not None:
_icon = Icon(icon_name=icon)
hbox.add(_icon)
label.set_size_request(max_text_width - 20, -1)
else:
label.set_size_request(max_text_width, -1)
hbox.show_all()
help_box.pack_start(hbox, False, False, padding=5)
return hbox
add_section(help_box, "Cómo jugar")
add_paragraph(help_box, "Debes encontrar un compañero con quien jugar.")
add_paragraph(help_box, "Consigue los ocho puntos para obtener el consenso.")
add_paragraph(help_box, "El carro verde se controla con las flechas.", icon="flechitas")
add_paragraph(help_box, "El carro rojo se controla con: W A S D.", icon="wasd")
add_paragraph(help_box, "Si los carros chocan entre sí, no hay ganador.")
add_paragraph(help_box, "")
add_section(help_box, "Taller del Artesano")
add_paragraph(help_box, "Tu experiencia no es completa hasta que no hayas modificado el programa.")
add_paragraph(help_box, "")
add_section(help_box, "Cómo modificar este juego")
add_paragraph(help_box, "Vista de juego.", icon="gamecanvas")
add_paragraph(help_box, "Modifica el juego.", icon="view-source")
add_paragraph(help_box, "Guarda tus cambios.", icon="dialog-ok")
add_paragraph(help_box, "Reinicia para ver tus cambios en acción.", icon="system-restart")
add_paragraph(help_box, "La consola permite analizar tu programa y encontrar errores o realizar pruebas.", icon="sources")