[Sugar-devel] [PATCH] Help Button with useful commands
S. Daniel Francis
francis at sugarlabs.org
Thu Jun 21 20:56:06 EDT 2012
Great!
I think the help must be only the utility and the description. In the
start/end (I'm not sure), a paragraph describing something like 'Type:
"{command} --help" to see it's usage'
Regards,
DanielF.
2012/6/21 Agustin Zubiaga <aguz at sugarlabs.org>:
> Gonzalo's button ported to GTK3
> Bugs:
> Wrap mode doesn't work
> Grey background
>
> Signed-off-by: Agustin Zubiaga <aguz at sugarlabs.org>
> ---
> helpbutton.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++
> icons/help-icon.svg | 14 +++++++++
> terminal.py | 33 ++++++++++++++++++++
> 3 files changed, 132 insertions(+)
> create mode 100644 helpbutton.py
> create mode 100644 icons/help-icon.svg
>
> diff --git a/helpbutton.py b/helpbutton.py
> new file mode 100644
> index 0000000..1f01851
> --- /dev/null
> +++ b/helpbutton.py
> @@ -0,0 +1,85 @@
> +#!/usr/bin/env python
> +# -*- coding: utf-8 -*-
> +# Copyright (C) 2012, Gonzalo Odiard <godiard at gmail.com>
> +
> +# 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 _
> +
> +from gi.repository import Gtk
> +from gi.repository import Gdk
> +from gi.repository import GObject
> +
> +from sugar3.graphics.toolbutton import ToolButton
> +from sugar3.graphics.icon import Icon
> +from sugar3.graphics import style
> +
> +
> +class HelpButton(Gtk.ToolItem):
> +
> + def __init__(self, **kwargs):
> + GObject.GObject.__init__(self)
> +
> + help_button = ToolButton('help-icon')
> + help_button.set_tooltip(_('Help'))
> + self.add(help_button)
> +
> + self._palette = help_button.get_palette()
> +
> + 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) - 600
> + 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)
> +
> + self._palette.set_content(sw)
> + sw.show_all()
> +
> + help_button.connect('clicked', self.__help_button_clicked_cb)
> +
> + def __help_button_clicked_cb(self, button):
> + self._palette.popup(immediate=True, state=1)
> +
> + def add_section(self, section_text):
> + hbox = Gtk.HBox()
> + label = Gtk.Label()
> + label.set_use_markup(True)
> + label.set_markup('<b>%s</b>' % section_text)
> + label.set_line_wrap(True)
> + hbox.pack_start(label, False, False, 0)
> + 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.pack_start(label, False, False, 0)
> + if icon is not None:
> + _icon = Icon(icon_name=icon)
> + hbox.add(_icon)
> + hbox.show_all()
> + self._vbox.pack_start(hbox, False, False, padding=5)
> diff --git a/icons/help-icon.svg b/icons/help-icon.svg
> new file mode 100644
> index 0000000..f6c92bf
> --- /dev/null
> +++ b/icons/help-icon.svg
> @@ -0,0 +1,14 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="55px" height="55px">
> + <path
> + style="fill:none;stroke:#ffffff;stroke-width:3;stroke-linejoin:round"
> + d="M 48,28 A 20,20 0 1 1 8,28 A 20,20 0 1 1 48,28 z"/>
> + <path
> + style="fill:none;stroke:#ffffff;stroke-width:6;stroke-linecap:round;stroke-linejoin:round"
> + d="M 22,20 C 22,20 25,17 29,17 C 33,17 36,19 36,23 C 36,27 31,29 28,29 L 28,32" />
> + <path
> + style="fill:#ffffff"
> + d="M 25,40
> + a 3,3 0 1 1 6,0
> + a 3,3 0 1 1 -6,0 z" />
> +</svg>
> diff --git a/terminal.py b/terminal.py
> index a37e2ac..803fed9 100644
> --- a/terminal.py
> +++ b/terminal.py
> @@ -42,6 +42,9 @@ from sugar3 import env
> from widgets import BrowserNotebook
> from widgets import TabLabel
>
> +from helpbutton import HelpButton
> +
> +
> MASKED_ENVIRONMENT = [
> 'DBUS_SESSION_BUS_ADDRESS',
> 'PPID']
> @@ -104,6 +107,10 @@ class TerminalActivity(activity.Activity):
> toolbar_box.toolbar.insert(separator, -1)
> separator.show()
>
> + helpbutton = self._create_help_button()
> + toolbar_box.toolbar.insert(helpbutton, -1)
> + helpbutton.show_all()
> +
> stop_button = StopButton(self)
> stop_button.props.accelerator = '<Ctrl><Shift>Q'
> toolbar_box.toolbar.insert(stop_button, -1)
> @@ -183,6 +190,32 @@ class TerminalActivity(activity.Activity):
> def __fullscreen_cb(self, button):
> self.fullscreen()
>
> + def _create_help_button(self):
> + helpitem = HelpButton()
> +
> + helpitem.add_section(_('Useful commands'))
> + helpitem.add_section(_('cd'))
> + helpitem.add_paragraph(_('Change directory'))
> + helpitem.add_paragraph(_('To use it, write: cd directory'))
> + helpitem.add_paragraph(_('If you call it without parameters, will change\nto the user directory'))
> + helpitem.add_section(_('ls'))
> + helpitem.add_paragraph(_('List the content of a directory.'))
> + helpitem.add_paragraph(_('To use it, write: ls directory'))
> + helpitem.add_paragraph(_('If you call it without parameters, will list\nthe working directory'))
> + helpitem.add_section(_('cp'))
> + helpitem.add_paragraph(_('Copy a file to a specific location'))
> + helpitem.add_paragraph(_('Call it with the file and the new location'))
> + helpitem.add_paragraph(_('Use: cp file directory/'))
> + helpitem.add_section(_('rm'))
> + helpitem.add_paragraph(_('Removes a file in any path'))
> + helpitem.add_paragraph(_('Use: rm file'))
> + helpitem.add_section(_('su'))
> + helpitem.add_paragraph(_('Login as superuser (root)'))
> + helpitem.add_paragraph(_('The root user is the administrator of the system'))
> + helpitem.add_paragraph(_('You must be careful, because you can modify system files'))
> +
> + return helpitem
> +
> def _create_tab_toolbar(self):
> tab_toolbar = Gtk.Toolbar()
> new_tab_button = ToolButton('tab-add')
> --
> 1.7.10.2
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
More information about the Sugar-devel
mailing list