From 5837ac4caec0a945b450117f48e41e13dc607ff4 Mon Sep 17 00:00:00 2001 From: Kalpa Welivitigoda Date: Sat, 13 Jul 2013 10:29:37 +0530 Subject: [PATCH 2/3] implemented the toolbar --- src/jarabe/view/viewhelp.py | 58 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/jarabe/view/viewhelp.py b/src/jarabe/view/viewhelp.py index 5c6e791..7cc9d68 100644 --- a/src/jarabe/view/viewhelp.py +++ b/src/jarabe/view/viewhelp.py @@ -16,11 +16,16 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +from gettext import gettext as _ + from gi.repository import Gtk +from gi.repository import GObject from gi.repository import Gdk from gi.repository import WebKit from sugar3.graphics import style +from sugar3.graphics.icon import Icon +from sugar3.graphics.toolbutton import ToolButton from sugar3.bundle.activitybundle import ActivityBundle import logging @@ -50,7 +55,7 @@ def setup_view_help(activity): activity_bundle = ActivityBundle(bundle_path) activity_name = activity_bundle.get_name() activity_path = str.join(os.sep, activity.get_bundle_path().split(os.sep)[:-1]) - _logger.exception('ACTIVITY PATH:' + activity_path) +# _logger.exception('ACTIVITY PATH:' + activity_path) if activity_name in links.keys(): viewhelp = ViewHelp(activity_name, links[activity_name], activity_path) @@ -63,8 +68,15 @@ def setup_view_help(activity): class ViewHelp(Gtk.Window): def __init__(self, activity_name, help_file, activity_path): Gtk.Window.__init__(self) + box = Gtk.Box() + box.set_orientation(Gtk.Orientation.VERTICAL) + self.add(box) + box.show() - self.set_title(help_file) + toolbar = Toolbar(activity_name) + box.pack_start(toolbar, False, False, 0) + toolbar.show() + toolbar.connect('stop-clicked', self.stop_clicked_cb) webview = WebKit.WebView() webview.set_full_content_zoom(True) @@ -73,7 +85,7 @@ class ViewHelp(Gtk.Window): scrolled_window.add(webview) scrolled_window.show() - #self.set_decorated(False) + self.set_decorated(False) self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) self.set_border_width(style.LINE_WIDTH) self.set_has_resize_grip(False) @@ -82,23 +94,57 @@ class ViewHelp(Gtk.Window): height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 2 self.set_size_request(width, height) - self.add(scrolled_window) + #self.add(scrolled_window) + box.pack_start(scrolled_window, True, True, 0) webview.show() webview.load_uri('file://' + os.path.join(activity_path, 'Help.activity/help/' + help_file)) + def stop_clicked_cb(self, widget): + self.destroy() class Toolbar(Gtk.Toolbar): + + __gsignals__ = { + 'stop-clicked': (GObject.SignalFlags.RUN_FIRST, None, ([])), + } + def __init__(self, activity_name): Gtk.Toolbar.__init__(self) + title = 'Help: ' + activity_name + + self.add_separator(False) + label = Gtk.Label() - label.set_text(activity_name) + label.set_markup('%s' % title) + label.set_alignment(0, 0.5) self.add_widget(label) + self.add_separator(True) + + stop = ToolButton(icon_name='dialog-cancel') + stop.set_tooltip(_('Close')) + stop.connect('clicked', self.stop_clicked_cb) + self.insert(stop, -1) + stop.show() + + def stop_clicked_cb(self, widget): + self.emit('stop-clicked') + def add_widget(self, widget): tool_item = Gtk.ToolItem() tool_item.add(widget) widget.show() - self.insert(tool_item, 1) + self.insert(tool_item, -1) tool_item.show() + + def add_separator(self, expand=False): + separator = Gtk.SeparatorToolItem() + separator.props.draw = False + if expand: + separator.set_expand(True) + else: + separator.set_size_request(style.DEFAULT_SPACING, -1) + self.insert(separator, -1) + separator.show() -- 1.8.1.4