[Sugar-devel] [PATCH Help v3] Migrated to Gtk3 and WebKit.WebView SL #3466

Manuel Kaufmann humitos at gmail.com
Wed Apr 25 09:43:11 EDT 2012


 - All the code was migrated to Gtk3 following this guide[1]
 - Toolbar View's icon was changed from "camera" to the right one:
  "toolbar-view"
 - Back and Forward buttons are working properly
 - WebKit.WebView inside a Gtk.ScrolledWindow to be able to scroll the page.

[1] http://wiki.sugarlabs.org/go/Features/GTK3/Porting

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 browser.py      |   43 -------------------------------------------
 helpactivity.py |   38 ++++++++++++++------------------------
 viewtoolbar.py  |    3 +--
 3 files changed, 15 insertions(+), 69 deletions(-)
 delete mode 100644 browser.py

diff --git a/browser.py b/browser.py
deleted file mode 100644
index 85017cb..0000000
--- a/browser.py
+++ /dev/null
@@ -1,43 +0,0 @@
-# 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 WebKit
-
-_ZOOM_AMOUNT = 0.1
-
-
-class Browser(WebKit.WebView):
-    def __init__(self):
-        WebKit.WebView.__init__(self)
-
-    def do_setup(self):
-        WebKit.WebView.do_setup(self)
-
-    def zoom_in(self):
-        # contentViewer = self.doc_shell.queryInterface( \
-        #         interfaces.nsIDocShell).contentViewer
-        # if contentViewer is not None:
-        #     markupDocumentViewer = contentViewer.queryInterface( \
-        #             interfaces.nsIMarkupDocumentViewer)
-        #     markupDocumentViewer.fullZoom += _ZOOM_AMOUNT
-        pass
-
-    def zoom_out(self):
-        # contentViewer = self.doc_shell.queryInterface( \
-        #         interfaces.nsIDocShell).contentViewer
-        # if contentViewer is not None:
-        #     markupDocumentViewer = contentViewer.queryInterface( \
-        #             interfaces.nsIMarkupDocumentViewer)
-        #     markupDocumentViewer.fullZoom -= _ZOOM_AMOUNT
-        pass
diff --git a/helpactivity.py b/helpactivity.py
index f8e3435..908a0d4 100755
--- a/helpactivity.py
+++ b/helpactivity.py
@@ -15,16 +15,13 @@
 import os
 from gettext import gettext as _
 
-from gi.repository import Gtk
-from gi.repository import GObject
+from gi.repository import Gtk, GObject, WebKit
 
 from sugar3.activity import activity
 from sugar3.graphics.toolbutton import ToolButton
 from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton
-from sugar3.activity.widgets import ActivityToolbarButton
-from sugar3.activity.widgets import StopButton
+from sugar3.activity.widgets import ActivityToolbarButton, StopButton
 
-from browser import Browser
 from viewtoolbar import ViewToolbar
 
 HOME = 'file://' + os.path.join(activity.get_bundle_path(),
@@ -37,8 +34,10 @@ class HelpActivity(activity.Activity):
 
         self.props.max_participants = 1
 
-        self._web_view = Browser()
-
+        self._web_view = WebKit.WebView()
+        _scrolled_window = Gtk.ScrolledWindow()
+        _scrolled_window.add(self._web_view)
+        _scrolled_window.show()
 
         toolbar_box = ToolbarBox()
 
@@ -48,7 +47,7 @@ class HelpActivity(activity.Activity):
 
         viewtoolbar = ViewToolbar(self)
         viewbutton = ToolbarButton(page=viewtoolbar, \
-                                   icon_name='camera')
+                                   icon_name='toolbar-view')
         toolbar_box.toolbar.insert(viewbutton, -1)
         viewbutton.show()
 
@@ -96,9 +95,8 @@ class HelpActivity(activity.Activity):
         self.set_toolbar_box(toolbar_box)
         toolbar_box.show()
 
-        self.set_canvas(self._web_view)
+        self.set_canvas(_scrolled_window)
         self._web_view.show()
-
         self._web_view.load_uri(HOME)
 
 
@@ -128,31 +126,23 @@ class Toolbar(Gtk.Toolbar):
         self.insert(self._home, -1)
         self._home.show()
 
-        """
-        progress_listener = self._web_view.progress
-        progress_listener.connect('location-changed',
-                                  self._location_changed_cb)
-        progress_listener.connect('loading-stop', self._loading_stop_cb)
-        """
+        self._web_view.connect('notify::uri', self._uri_changed_cb)
 
-    def _location_changed_cb(self, progress_listener, uri):
+    def _uri_changed_cb(self, progress_listener, uri):
         self.update_navigation_buttons()
 
     def _loading_stop_cb(self, progress_listener):
         self.update_navigation_buttons()
 
     def update_navigation_buttons(self):
-        can_go_back = self._web_view.web_navigation.canGoBack
-        self._back.props.sensitive = can_go_back
-
-        can_go_forward = self._web_view.web_navigation.canGoForward
-        self._forward.props.sensitive = can_go_forward
+        self._back.props.sensitive = self._web_view.can_go_back()
+        self._forward.props.sensitive = self._web_view.can_go_forward()
 
     def _go_back_cb(self, button):
-        self._web_view.web_navigation.goBack()
+        self._web_view.go_back()
 
     def _go_forward_cb(self, button):
-        self._web_view.web_navigation.goForward()
+        self._web_view.go_forward()
 
     def _go_home_cb(self, button):
         self._web_view.load_uri(HOME)
diff --git a/viewtoolbar.py b/viewtoolbar.py
index 13a1ce5..fbbdb10 100644
--- a/viewtoolbar.py
+++ b/viewtoolbar.py
@@ -16,8 +16,7 @@
 
 from gettext import gettext as _
 
-from gi.repository import Gtk
-from gi.repository import GObject
+from gi.repository import Gtk, GObject
 
 from sugar3.graphics.toolbutton import ToolButton
 
-- 
1.7.10



More information about the Sugar-devel mailing list