[Sugar-devel] [PATCH v2 Browse] Busy indication SL #851

Manuel Kaufmann humitos at gmail.com
Fri Sep 21 18:53:09 EDT 2012


Show WATCH Cursor when the page is loading and LEFT_PTR when the load
finishes.

This changes take in consideration the tab that the user is watching,
so the cursor refers to the state of the current browser / tab.

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 browser.py     | 21 +++++++++++++++++++++
 webactivity.py | 16 ++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/browser.py b/browser.py
index de546f2..99b05d4 100644
--- a/browser.py
+++ b/browser.py
@@ -39,6 +39,8 @@ import globalhistory
 import downloadmanager
 from pdfviewer import PDFTabPage
 
+from webactivity import NORMAL_CURSOR, WATCH_CURSOR
+
 ZOOM_ORIGINAL = 1.0
 _ZOOM_AMOUNT = 0.1
 _LIBRARY_PATH = '/usr/share/library-common/index.html'
@@ -188,10 +190,26 @@ class TabbedView(BrowserNotebook):
         self.set_current_page(next_index)
         tab_page.setup(url)
 
+    def __load_status_changed_cb(self, widget, param):
+        # Do not change the cursor if the load-status changed is not
+        # on the current browser
+        if self.props.current_browser != widget:
+            return
+
+        status = widget.get_load_status()
+        if status in (WebKit.LoadStatus.PROVISIONAL,
+                      WebKit.LoadStatus.COMMITTED,
+                      WebKit.LoadStatus.FIRST_VISUALLY_NON_EMPTY_LAYOUT):
+            self.get_window().set_cursor(WATCH_CURSOR)
+        elif status in (WebKit.LoadStatus.FAILED,
+                        WebKit.LoadStatus.FINISHED):
+            self.get_window().set_cursor(NORMAL_CURSOR)
+
     def add_tab(self, next_to_current=False):
         browser = Browser()
         browser.connect('new-tab', self.__new_tab_cb)
         browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb)
+        browser.connect('notify::load-status', self.__load_status_changed_cb)
 
         if next_to_current:
             self._insert_tab_next(browser)
@@ -318,6 +336,8 @@ class TabbedView(BrowserNotebook):
                 browser = Browser()
                 browser.connect('new-tab', self.__new_tab_cb)
                 browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb)
+                browser.connect('notify::load-status',
+                                self.__load_status_changed_cb)
                 self._append_tab(browser)
                 browser.set_history(tab_history)
 
@@ -404,6 +424,7 @@ class TabLabel(Gtk.HBox):
 
     def __load_status_changed_cb(self, widget, param):
         status = widget.get_load_status()
+
         if status == WebKit.LoadStatus.FAILED:
             self._label.set_text(self._title)
         elif WebKit.LoadStatus.PROVISIONAL <= status \
diff --git a/webactivity.py b/webactivity.py
index 24f3b44..88555e6 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -54,6 +54,9 @@ from sugar3.graphics.toolbarbox import ToolbarButton
 
 PROFILE_VERSION = 2
 
+NORMAL_CURSOR = Gdk.Cursor(Gdk.CursorType.LEFT_PTR)
+WATCH_CURSOR = Gdk.Cursor(Gdk.CursorType.WATCH)
+
 _profile_version = 0
 _profile_path = os.path.join(activity.get_activity_root(), 'data/gecko')
 _version_file = os.path.join(_profile_path, 'version')
@@ -169,6 +172,7 @@ class WebActivity(activity.Activity):
         self._force_close = False
         self._tabbed_view = TabbedView()
         self._tabbed_view.connect('focus-url-entry', self._on_focus_url_entry)
+        self._tabbed_view.connect('switch-page', self.__switch_page_cb)
 
         self._tray = HTray()
         self.set_tray(self._tray, Gtk.PositionType.BOTTOM)
@@ -596,6 +600,18 @@ class WebActivity(activity.Activity):
             downloadmanager.remove_all_downloads()
             self.close()
 
+    def __switch_page_cb(self, tabbed_view, page, page_num):
+        browser = page._browser
+        status = browser.get_load_status()
+
+        if status in (WebKit.LoadStatus.COMMITTED,
+                      WebKit.LoadStatus.FIRST_VISUALLY_NON_EMPTY_LAYOUT):
+            self.get_window().set_cursor(WATCH_CURSOR)
+        elif status in (WebKit.LoadStatus.PROVISIONAL,
+                        WebKit.LoadStatus.FAILED,
+                        WebKit.LoadStatus.FINISHED):
+            self.get_window().set_cursor(NORMAL_CURSOR)
+
     def get_document_path(self, async_cb, async_err_cb):
         browser = self._tabbed_view.props.current_browser
         browser.get_source(async_cb, async_err_cb)
-- 
1.7.11.4



More information about the Sugar-devel mailing list