diff options
author | Walter Bender <walter.bender@gmail.com> | 2012-03-23 19:18:17 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2012-03-23 19:18:17 (GMT) |
commit | 69d7ba3bf324228f916c657a4fd4ec9f83782f9d (patch) | |
tree | b9e5c38e41432aca2e3d3d9e64fdf7aad8265a96 | |
parent | ee985331abe3c9610e5c3ff9d2eb027ed854b569 (diff) |
new help system
-rw-r--r-- | TurtleArt/tapalette.py | 78 | ||||
-rw-r--r-- | TurtleArt/tawindow.py | 18 | ||||
-rw-r--r-- | TurtleArtActivity.py | 55 | ||||
-rw-r--r-- | icons/help-off.svg | 54 | ||||
-rw-r--r-- | icons/help-on.svg | 57 | ||||
-rw-r--r-- | images/help.svg | 50 | ||||
-rw-r--r-- | util/helpbutton.py | 61 |
7 files changed, 340 insertions, 33 deletions
diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py index be9d999..276e830 100644 --- a/TurtleArt/tapalette.py +++ b/TurtleArt/tapalette.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#Copyright (c) 2011 Walter Bender +#Copyright (c) 2011,12 Walter Bender #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal @@ -19,6 +19,8 @@ #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN #THE SOFTWARE. +help_palettes = {} +help_windows = {} palette_names = [] palette_blocks = [] block_colors = [] @@ -75,6 +77,12 @@ block_styles = {'basic-style': [], 'portfolio-style-2x1': [], 'portfolio-style-1x2': []} + +import gtk + +from sugar.graphics.icon import Icon +from sugar.graphics import style + from taconstants import EXPANDABLE_STYLE from tautils import debug_output @@ -94,6 +102,25 @@ class Palette(): self._special_name = _(name) self._colors = colors self._help = None + self._max_text_width = int(gtk.gdk.screen_width() / 3) - 20 + + # Prepare a vbox for the help palette + if not (self._name in help_palettes): + self._help_box = gtk.VBox() + self._help_box.set_homogeneous(False) + help_palettes[self._name] = self._help_box + else: + self._help_box = help_palettes[self._name] + + help_windows[self._name] = gtk.ScrolledWindow() + help_windows[self._name].set_size_request( + int(gtk.gdk.screen_width() / 3), + gtk.gdk.screen_height() - style.GRID_CELL_SIZE * 3) + help_windows[self._name].set_policy( + gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + help_windows[self._name].add_with_viewport( + help_palettes[self._name]) + help_palettes[self._name].show() ''' self._fd = open('/home/walter/Desktop/turtleblocks/doc/%s-palette.page' % (name), 'a') @@ -150,8 +177,48 @@ class Palette(): else: help_strings[self._name] = '' + def add_section(self, section_text, icon=None): + ''' Add a section to the help palette. From helpbutton.py by + Gonzalo Odiard ''' + 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(self._max_text_width, -1) + 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._help_box.pack_start(hbox, False, False, padding=5) + + def add_paragraph(self, text, icon=None): + ''' Add an entry to the help palette. From helpbutton.py by + Gonzalo Odiard ''' + 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(self._max_text_width - 20, -1) + else: + label.set_size_request(self._max_text_width, -1) + + hbox.show_all() + self._help_box.pack_start(hbox, False, False, padding=5) + def set_help(self, help): self._help = help + if hasattr(self, '_help_box'): + self.add_section(self._help, icon=self._name + 'off') def set_special_name(self, name): self._special_name = name @@ -176,8 +243,15 @@ class Palette(): block.set_prim_name(prim_name) if logo_command is not None: block.set_logo_command(logo_command) - if help_string is not None: + if not hidden and help_string is not None: block.set_help(help_string) + if special_name is None: + if type(label) == list: + self.add_paragraph('%s: %s' % (label[0], help_string)) + else: + self.add_paragraph('%s: %s' % (label, help_string)) + else: + self.add_paragraph('%s: %s' % (special_name, help_string)) if colors is not None: block.set_colors(colors) block.set_value_block(value_block) diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index b324c7b..3771484 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -124,6 +124,8 @@ class TurtleArtWindow(): self.height = gtk.gdk.screen_height() self.rect = gtk.gdk.Rectangle(0, 0, 0, 0) + self.no_help = False + self.keypress = '' self.keyvalue = 0 self.dead_key = '' @@ -1729,6 +1731,8 @@ class TurtleArtWindow(): def _do_show_popup(self, block_name): """ Fetch the help text and display it. """ + if self.no_help: + return 0 if block_name in special_names: special_block_name = special_names[block_name] elif block_name in block_names: @@ -1738,18 +1742,16 @@ class TurtleArtWindow(): else: special_block_name = _(block_name) if block_name in help_strings: + label = help_strings[block_name] + ''' if special_block_name == '': label = help_strings[block_name] else: label = special_block_name + ": " + help_strings[block_name] + ''' else: label = special_block_name - if self.running_sugar: - self.activity.hover_help_label.set_text(label) - self.activity.hover_help_label.show() - else: - if self.interactive_mode: - self.parent.set_title(_("Turtle Art") + " — " + label) + self.showlabel('help', label=label) return 0 def _buttonrelease_cb(self, win, event): @@ -3073,7 +3075,9 @@ class TurtleArtWindow(): if shp == 'info': self.status_spr.move((PALETTE_WIDTH, self.height - 400)) else: - self.status_spr.move((PALETTE_WIDTH, self.height - 200)) + # Adjust vertical position based on scrolled window adjustment + self.status_spr.move((0, self.height - 200 + \ + self.activity.sw.get_vadjustment().get_value())) def calc_position(self, template): """ Relative placement of portfolio objects (deprecated) """ diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index fb32fd1..f532f47 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -58,6 +58,9 @@ from TurtleArt.tautils import data_to_file, data_to_string, data_from_string, \ from TurtleArt.tawindow import TurtleArtWindow from TurtleArt.tacollaboration import Collaboration +if HAS_TOOLBARBOX: + from util.helpbutton import HelpButton + class TurtleArtActivity(activity.Activity): ''' Activity subclass for Turtle Art ''' @@ -87,7 +90,8 @@ class TurtleArtActivity(activity.Activity): _logger.debug('_setup_palette_toolbar') self._setup_palette_toolbar() self._setup_extra_controls() - self._setup_help_toolbar() + if not self.has_toolbarbox: + self._setup_help_toolbar() _logger.debug('_setup_sharing') self._setup_sharing() @@ -258,9 +262,26 @@ class TurtleArtActivity(activity.Activity): return if not self.has_toolbarbox: self.palette_buttons[i].set_icon(palette_names[i] + 'on') + else: + _logger.debug('setting help button palette to %s' % (palette_names[i])) + self._help_button.set_current_palette(palette_names[i]) self.tw.show_palette(n=i) self.do_showpalette() + def _do_hover_help_toggle(self, button): + ''' Toggle hover help ''' + if self.tw.no_help: + _logger.debug('turning hover help on') + self.tw.no_help = False + self._hover_help_toggle.set_icon('help-off') + self._hover_help_toggle.set_tooltip(_('Turn off hover help')) + else: + _logger.debug('turning hover help off') + self.tw.no_help = True + self.tw.status_spr.hide() + self._hover_help_toggle.set_icon('help-on') + self._hover_help_toggle.set_tooltip(_('Turn on hover help')) + # These methods are called both from toolbar buttons and blocks. def do_hidepalette(self): @@ -484,10 +505,9 @@ class TurtleArtActivity(activity.Activity): self._palette_toolbar = gtk.Toolbar() self._palette_toolbar_button = ToolbarButton( page=self._palette_toolbar, icon_name='palette') - self._help_toolbar = gtk.Toolbar() - self._help_toolbar_button = ToolbarButton(label=_('Help'), - page=self._help_toolbar, - icon_name='help-toolbar') + + + self._help_button = HelpButton() self._make_load_save_buttons(activity_toolbar_button) @@ -515,8 +535,6 @@ class TurtleArtActivity(activity.Activity): self._toolbox.add_toolbar(_('Edit'), edit_toolbar) journal_toolbar = gtk.Toolbar() self._toolbox.add_toolbar(_('Save/Load'), journal_toolbar) - self._help_toolbar = gtk.Toolbar() - self._toolbox.add_toolbar(_('Help'), self._help_toolbar) self._make_palette_buttons(self._project_toolbar, palette_button=True) @@ -549,10 +567,13 @@ class TurtleArtActivity(activity.Activity): self.resize_down_button = self._add_button( 'resize-', _('Shrink blocks'), self.do_shrink_blocks_cb, view_toolbar) + self._hover_help_toggle = self._add_button( + 'help-off', _('Turn off hover help'), self._do_hover_help_toggle, + view_toolbar) + edit_toolbar.show() view_toolbar.show() - self._help_toolbar.show() self._toolbox.show() if not self.has_toolbarbox: @@ -574,28 +595,14 @@ class TurtleArtActivity(activity.Activity): 'ta-open', _('Load example'), self.do_samples_cb, self._toolbox.toolbar) - self._help_toolbar_button.show() - self._toolbox.toolbar.insert(self._help_toolbar_button, -1) + self._toolbox.toolbar.insert(self._help_button, -1) + self._help_button.show() stop_button = StopButton(self) stop_button.props.accelerator = '<Ctrl>Q' self._toolbox.toolbar.insert(stop_button, -1) stop_button.show() - def _setup_help_toolbar(self): - ''' The help toolbar must be setup we determine what hardware - is in use. ''' - # FIXME: Temporary work-around gtk problem with XO175 - if get_hardware() not in [XO1, XO15, XO175, XO30] and \ - (gtk.gtk_version[0] > 2 or gtk.gtk_version[1] > 16): - self.hover_help_label = self._add_label( - _('Move the cursor over the orange palette for help.'), - self._help_toolbar, gtk.gdk.screen_width() - 2 * ICON_SIZE) - else: - self.hover_help_label = self._add_label( - _('Move the cursor over the orange palette for help.'), - self._help_toolbar) - def _setup_palette_toolbar(self): ''' The palette toolbar must be setup *after* plugins are loaded. ''' if self.has_toolbarbox: diff --git a/icons/help-off.svg b/icons/help-off.svg new file mode 100644 index 0000000..7a038b6 --- /dev/null +++ b/icons/help-off.svg @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.0" + width="55" + height="55" + viewBox="0 0 55 55" + id="svg2"> + <metadata + id="metadata11"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs9"> + +</defs> + <path + d="m 50,27.625 c 0,12.3431 -10.1569,22.5 -22.5,22.5 C 15.1569,50.125 5,39.9681 5,27.625 5,15.2819 15.1569,5.125 27.5,5.125 c 12.3431,0 22.5,10.1569 22.5,22.5 z" + id="path3" + style="fill:#ffffff" /> + <path + d="m 23.956,27.167 c 0,-1.621 1.8,-1.89 3.645,-2.386 1.8,-0.495 3.6,-1.215 3.6,-3.825 0,-1.98 -1.845,-3.42 -3.734,-3.42 -3.78,0 -4.365,4.455 -7.246,4.455 -1.62,0 -2.745,-1.26 -2.745,-3.24 0,-4.726 5.94,-7.425 9.991,-7.425 5.806,0 10.756,3.6 10.756,9.631 0,4.995 -3.15,7.921 -7.785,9.091 l 0,1.619 c 0,1.801 -1.351,3.105 -3.241,3.105 -2.025,0 -3.24,-1.305 -3.24,-3.105 l 0,-4.5 -0.001,0 z m -0.27,13.77 c 0,-1.935 1.575,-3.51 3.51,-3.51 1.936,0 3.51,1.575 3.51,3.51 0,1.936 -1.574,3.512 -3.51,3.512 -1.935,-10e-4 -3.51,-1.577 -3.51,-3.512 z" + id="path5" + style="fill:#282828;stroke:#282828;stroke-width:0.25;stroke-miterlimit:4" /> + <g + transform="matrix(0.90000005,0,0,0.90000005,1.5999984,5.2999976)" + id="g3850"> + <rect + width="12" + height="12" + x="40" + y="37" + id="rect3848" + style="fill:#ffffff;fill-opacity:1;stroke:none" /> + <path + d="M 45.999999,33 C 40.475555,33 36,37.478222 36,42.998666 36,48.524 40.475555,53 45.999999,53 c 5.524889,0 10,-4.476 10,-10.001334 0,-5.520444 -4.475555,-9.998666 -10,-9.998666 z m 4.532889,12.515111 c 0.557334,0.558222 0.558667,1.462666 0,2.02 -0.279111,0.279555 -0.644889,0.419111 -1.010666,0.419111 -0.365334,0 -0.730667,-0.139556 -1.008889,-0.417778 l -2.56,-2.560444 -2.56,2.560444 c -0.278667,0.278222 -0.644,0.417778 -1.009334,0.417778 -0.365777,0 -0.732,-0.139556 -1.011111,-0.419111 -0.557333,-0.557334 -0.557333,-1.461778 0.0018,-2.02 L 43.933777,42.956 41.374666,40.396889 c -0.559111,-0.557334 -0.559111,-1.463112 -0.0018,-2.020445 0.557778,-0.557333 1.463111,-0.559555 2.020445,0 l 2.56,2.559556 2.56,-2.559556 c 0.556444,-0.559555 1.461333,-0.557333 2.019555,0 0.558667,0.557333 0.557334,1.463111 0,2.020445 l -2.559111,2.559111 2.559111,2.559111 z" + id="path3067" + style="fill:#282828;fill-opacity:1;display:inline" /> + </g> +</svg> diff --git a/icons/help-on.svg b/icons/help-on.svg new file mode 100644 index 0000000..c818f84 --- /dev/null +++ b/icons/help-on.svg @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.0" + width="55" + height="55" + viewBox="0 0 55 55" + id="svg2"> + <metadata + id="metadata3971"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs3969" /> + <path + d="m 50,27.625 c 0,12.3431 -10.1569,22.5 -22.5,22.5 C 15.1569,50.125 5,39.9681 5,27.625 5,15.2819 15.1569,5.125 27.5,5.125 c 12.3431,0 22.5,10.1569 22.5,22.5 z" + id="path3963" + style="fill:#ffffff" /> + <path + d="m 23.956,27.167 c 0,-1.621 1.8,-1.89 3.645,-2.386 1.8,-0.495 3.6,-1.215 3.6,-3.825 0,-1.98 -1.845,-3.42 -3.734,-3.42 -3.78,0 -4.365,4.455 -7.246,4.455 -1.62,0 -2.745,-1.26 -2.745,-3.24 0,-4.726 5.94,-7.425 9.991,-7.425 5.806,0 10.756,3.6 10.756,9.631 0,4.995 -3.15,7.921 -7.785,9.091 l 0,1.619 c 0,1.801 -1.351,3.105 -3.241,3.105 -2.025,0 -3.24,-1.305 -3.24,-3.105 l 0,-4.5 -0.001,0 z m -0.27,13.77 c 0,-1.935 1.575,-3.51 3.51,-3.51 1.936,0 3.51,1.575 3.51,3.51 0,1.936 -1.574,3.512 -3.51,3.512 -1.935,-10e-4 -3.51,-1.577 -3.51,-3.512 z" + id="path3965" + style="fill:#282828;stroke:#282828;stroke-width:0.25;stroke-miterlimit:4" /> + <g + id="g4559"> + <rect + width="12" + height="12" + x="37" + y="38" + id="rect3848" + style="fill:#ffffff;fill-opacity:1;stroke:none" /> + <g + transform="matrix(0.4,0,0,0.4,32,33)" + id="dialog-ok" + style="fill:#282828;fill-opacity:1;display:block"> + <path + d="M 27.498,5 C 15.071,5 5,15.071 5,27.498 5,39.923 15.071,50 27.498,50 39.927,50 50,39.923 50,27.498 50,15.071 39.927,5 27.498,5 z M 41.419,19.886 24.706,40.208 13.789,29.29 c -1.258,-1.254 -1.258,-3.292 -0.003,-4.546 1.254,-1.255 3.292,-1.255 4.547,0 L 24.241,30.648 36.452,15.8 c 1.127,-1.368 3.153,-1.568 4.525,-0.438 1.37,1.127 1.569,3.153 0.442,4.524 z" + id="path4021" + style="fill:#282828;fill-opacity:1;display:inline" /> + +</g> + </g> +</svg> diff --git a/images/help.svg b/images/help.svg new file mode 100644 index 0000000..3281351 --- /dev/null +++ b/images/help.svg @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.0" + width="767" + height="38" + id="svg2"> + <metadata + id="metadata17"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs27" /> + <path + d="M 15,37.5 C 11.5,37.5 8,35 5.5,32.5 3,30 0.5,26.5 0.5,23 l 0,-8 c 0,-3.25 2.5,-8.5 5,-10.5 2.5,-2 6,-4 9.5,-4 l 736.5,0 c 2.5,0 7,1 10.5,4 3.5,2.75 4.5,7.5 4.5,10.5 l 0,8 c 0,3.5 -2,7 -4.5,9.5 -2.5,2.5 -6.5,5 -10.5,5 L 15,37.5 z" + id="path4" + style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#e0e0e0;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + <g + transform="translate(656,65.625)" + id="g6"> + <path + d="m 79.5,438.5 c 0,4.5 -3.75,8 -8.5,8 -4.5,0 -8.25,-3.5 -8.25,-8 0,-4.5 3.75,-8.25 8.25,-8.25 4.75,0 8.5,3.75 8.5,8.25 l 0,0 z" + transform="translate(24,-485)" + id="path8" + style="fill:#ff4040;fill-opacity:1;fill-rule:nonzero;stroke:#ff4040;stroke-width:1;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + <text + id="text10" + style="font-size:12px;font-weight:bold;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"> + <tspan + x="91" + y="-42" + id="tspan12" + style="font-size:12px">X</tspan> + </text> + </g> +</svg> diff --git a/util/helpbutton.py b/util/helpbutton.py new file mode 100644 index 0000000..879320e --- /dev/null +++ b/util/helpbutton.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2012, Gonzalo Odiard <godiard@gmail.com> +# Copyright (C) 2012, Walter Bender <walter@sugarlabs.org> + +# 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 TurtleArt.tapalette import palette_names, help_windows + +import logging +_logger = logging.getLogger('turtleart-activity') + + +class HelpButton(gtk.ToolItem): + + def __init__(self, **kwargs): + self._current_palette = 'turtle' + + gtk.ToolItem.__init__(self) + + help_button = ToolButton('help-toolbar') + help_button.set_tooltip(_('Help')) + 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): + _logger.debug(name) + self._current_palette = name + + def __help_button_clicked_cb(self, button): + if not (self._current_palette in help_windows): + _logger.debug('name %s not found' % (self._current_palette)) + return + self._palette.set_content(help_windows[self._current_palette]) + help_windows[self._current_palette].show_all() + + self._palette.popup(immediate=True, state=1) |