From bb7a835ef8c62e6dce52e6d82c5025019575dda5 Mon Sep 17 00:00:00 2001
From: Kalpa Welivitigoda <callkalpa@gmail.com>
Date: Sat, 13 Jul 2013 01:33:27 +0530
Subject: [PATCH 1/3] help viewer implemented

---
 extensions/globalkey/Makefile.am |   3 +-
 extensions/globalkey/viewhelp.py |  28 +++++++++++
 src/jarabe/view/helplink         |   3 ++
 src/jarabe/view/viewhelp.py      | 104 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 137 insertions(+), 1 deletion(-)
 create mode 100644 extensions/globalkey/viewhelp.py
 create mode 100644 src/jarabe/view/helplink
 create mode 100644 src/jarabe/view/viewhelp.py

diff --git a/extensions/globalkey/Makefile.am b/extensions/globalkey/Makefile.am
index b6cbbd6..dd44247 100644
--- a/extensions/globalkey/Makefile.am
+++ b/extensions/globalkey/Makefile.am
@@ -4,4 +4,5 @@ sugar_PYTHON = 		\
 	__init__.py	\
 	screenshot.py	\
 	speech.py	\
-	viewsource.py
+	viewsource.py	\
+	viewhelp.py
diff --git a/extensions/globalkey/viewhelp.py b/extensions/globalkey/viewhelp.py
new file mode 100644
index 0000000..e3dc23c
--- /dev/null
+++ b/extensions/globalkey/viewhelp.py
@@ -0,0 +1,28 @@
+# Copyright (C) 2008 One Laptop Per Child
+# Copyright (C) 2009 Tomeu Vizoso, Simon Schampijer
+#
+# 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 2 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
+
+from jarabe.view.viewhelp import setup_view_help
+from jarabe.model import shell
+
+BOUND_KEYS = ['<alt><shift>h']
+
+
+def handle_key_press(key):
+    shell_model = shell.get_model()
+    activity = shell_model.get_active_activity()
+
+    setup_view_help(activity)
diff --git a/src/jarabe/view/helplink b/src/jarabe/view/helplink
new file mode 100644
index 0000000..a53c400
--- /dev/null
+++ b/src/jarabe/view/helplink
@@ -0,0 +1,3 @@
+Read: read.html
+Browse: browse.html
+Chat: chat.html
diff --git a/src/jarabe/view/viewhelp.py b/src/jarabe/view/viewhelp.py
new file mode 100644
index 0000000..5c6e791
--- /dev/null
+++ b/src/jarabe/view/viewhelp.py
@@ -0,0 +1,104 @@
+# Copyright (C) 2008 One Laptop Per Child
+# Copyright (C) 2009 Tomeu Vizoso, Simon Schampijer
+# Copyright (C) 2011 Walter Bender
+#
+# 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 2 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
+
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import WebKit
+
+from sugar3.graphics import style
+from sugar3.bundle.activitybundle import ActivityBundle
+
+import logging
+import os
+
+links = {}
+LINK_FILE = 'src/jarabe/view/helplink'
+_logger = logging.getLogger('ViewHelp')
+
+
+def read_links():
+    global links
+    f = open(LINK_FILE, 'r')
+    for line in f.readlines():
+        temp = line.split(':')
+        activity = temp[0].strip()
+        help_file = temp[1].strip()
+        links[activity] = help_file
+
+
+def setup_view_help(activity):
+    read_links()
+    bundle_path = activity.get_bundle_path()
+    if bundle_path is None:
+        # display error message
+        return
+    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)
+
+    if activity_name in links.keys():
+        viewhelp = ViewHelp(activity_name, links[activity_name], activity_path)
+        viewhelp.show()
+    else:
+        # display error message
+        return
+
+
+class ViewHelp(Gtk.Window):
+    def __init__(self, activity_name, help_file, activity_path):
+        Gtk.Window.__init__(self)
+
+        self.set_title(help_file)
+
+        webview = WebKit.WebView()
+        webview.set_full_content_zoom(True)
+
+        scrolled_window = Gtk.ScrolledWindow()
+        scrolled_window.add(webview)
+        scrolled_window.show()
+
+        #self.set_decorated(False)
+        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
+        self.set_border_width(style.LINE_WIDTH)
+        self.set_has_resize_grip(False)
+
+        width = Gdk.Screen.width() - style.GRID_CELL_SIZE * 2
+        height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 2
+        self.set_size_request(width, height)
+
+        self.add(scrolled_window)
+
+        webview.show()
+        webview.load_uri('file://' + os.path.join(activity_path, 'Help.activity/help/' + help_file))
+
+
+class Toolbar(Gtk.Toolbar):
+    def __init__(self, activity_name):
+        Gtk.Toolbar.__init__(self)
+
+        label = Gtk.Label()
+        label.set_text(activity_name)
+        self.add_widget(label)
+
+    def add_widget(self, widget):
+        tool_item = Gtk.ToolItem()
+        tool_item.add(widget)
+        widget.show()
+        self.insert(tool_item, 1)
+        tool_item.show()
-- 
1.8.1.4

