# Copyright (C) 2012-2013 S. Daniel Francis # # Based on helpbutton by Gonzalo Odiard # Copyright (C) 2012, Gonzalo Odiard # # 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 Street, Fifth Floor, Boston, # MA 02110-1301, USA. from gettext import gettext as _ from gi.repository import Gtk from gi.repository import Gdk from sugar3.graphics import style from sugar3.graphics.icon import Icon import stock from settingsitem import SettingsItem from itemgroup import ItemGroup import info import helpcontent class Help(SettingsItem): def __init__(self, box): title = stock.get_label(Gtk.STOCK_HELP, False) stock.register('sweetener-help-contents', title, 'H', 'toolbar-help') SettingsItem.__init__(self, None, 'sweetener-help-contents') sw = Gtk.ScrolledWindow() sw.set_size_request(int(Gdk.Screen.width() / 2.8), Gdk.Screen.height() - style.GRID_CELL_SIZE * 3) sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self._max_text_width = int(Gdk.Screen.width() / 3) - 20 self._vbox = Gtk.VBox() self._vbox.set_homogeneous(False) hbox = Gtk.HBox() hbox.pack_start(self._vbox, False, True, 0) sw.add_with_viewport(hbox) sw.show() self.content = sw item = self.get_tool_item() item.show_all() separator = Gtk.SeparatorToolItem() separator.show() box.toolbar.insert(separator, len(box.toolbar.get_children()[:-2])) box.toolbar.insert(item, len(box.toolbar.get_children()[:-2])) for i in helpcontent.help: self.add_section(i[0]) for text, icon in i[1:]: self.add_paragraph(text, icon) def add_section(self, section_text): hbox = Gtk.HBox() label = Gtk.Label() label.set_use_markup(True) label.set_markup('%s' % section_text) label.set_line_wrap(True) label.set_size_request(self._max_text_width, -1) hbox.add(label) hbox.show_all() self._vbox.pack_start(hbox, False, False, padding=5) def add_paragraph(self, text, icon=None): hbox = Gtk.HBox() label = Gtk.Label(label=text) label.set_justify(Gtk.Justification.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(self._max_text_width - 20, -1) else: label.set_size_request(self._max_text_width, -1) hbox.show_all() self._vbox.pack_start(hbox, False, False, padding=5)