[Sugar-devel] [PATCH] Help Button with useful commands
Paul Fox
pgf at laptop.org
Thu Jun 21 21:24:10 EDT 2012
s. daniel francis wrote:
> 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'
isn't there a shell tutorial in the wikipedia content bundle you could
just point to? :-) it's a pretty big subject.
paul
>
> 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
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
=---------------------
paul fox, pgf at laptop.org
More information about the Sugar-devel
mailing list