From a884b8b402039cfa679d4aef5b5f9020823e52ca Mon Sep 17 00:00:00 2001
From: Manuel Kaufmann <humitos@gmail.com>
Date: Mon, 10 Sep 2012 17:52:45 -0300
Subject: [PATCH v2 Browse] Busy indication SL #851
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@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
|
b
|
import globalhistory |
39 | 39 | import downloadmanager |
40 | 40 | from pdfviewer import PDFTabPage |
41 | 41 | |
| 42 | from webactivity import NORMAL_CURSOR, WATCH_CURSOR |
| 43 | |
42 | 44 | ZOOM_ORIGINAL = 1.0 |
43 | 45 | _ZOOM_AMOUNT = 0.1 |
44 | 46 | _LIBRARY_PATH = '/usr/share/library-common/index.html' |
… |
… |
class TabbedView(BrowserNotebook): |
188 | 190 | self.set_current_page(next_index) |
189 | 191 | tab_page.setup(url) |
190 | 192 | |
| 193 | def __load_status_changed_cb(self, widget, param): |
| 194 | # Do not change the cursor if the load-status changed is not |
| 195 | # on the current browser |
| 196 | if self.props.current_browser != widget: |
| 197 | return |
| 198 | |
| 199 | status = widget.get_load_status() |
| 200 | if status in (WebKit.LoadStatus.PROVISIONAL, |
| 201 | WebKit.LoadStatus.COMMITTED, |
| 202 | WebKit.LoadStatus.FIRST_VISUALLY_NON_EMPTY_LAYOUT): |
| 203 | self.get_window().set_cursor(WATCH_CURSOR) |
| 204 | elif status in (WebKit.LoadStatus.FAILED, |
| 205 | WebKit.LoadStatus.FINISHED): |
| 206 | self.get_window().set_cursor(NORMAL_CURSOR) |
| 207 | |
191 | 208 | def add_tab(self, next_to_current=False): |
192 | 209 | browser = Browser() |
193 | 210 | browser.connect('new-tab', self.__new_tab_cb) |
194 | 211 | browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb) |
| 212 | browser.connect('notify::load-status', self.__load_status_changed_cb) |
195 | 213 | |
196 | 214 | if next_to_current: |
197 | 215 | self._insert_tab_next(browser) |
… |
… |
class TabbedView(BrowserNotebook): |
318 | 336 | browser = Browser() |
319 | 337 | browser.connect('new-tab', self.__new_tab_cb) |
320 | 338 | browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb) |
| 339 | browser.connect('notify::load-status', |
| 340 | self.__load_status_changed_cb) |
321 | 341 | self._append_tab(browser) |
322 | 342 | browser.set_history(tab_history) |
323 | 343 | |
… |
… |
class TabLabel(Gtk.HBox): |
404 | 424 | |
405 | 425 | def __load_status_changed_cb(self, widget, param): |
406 | 426 | status = widget.get_load_status() |
| 427 | |
407 | 428 | if status == WebKit.LoadStatus.FAILED: |
408 | 429 | self._label.set_text(self._title) |
409 | 430 | elif WebKit.LoadStatus.PROVISIONAL <= status \ |
diff --git a/webactivity.py b/webactivity.py
index 24f3b44..88555e6 100644
a
|
b
|
from sugar3.graphics.toolbarbox import ToolbarButton |
54 | 54 | |
55 | 55 | PROFILE_VERSION = 2 |
56 | 56 | |
| 57 | NORMAL_CURSOR = Gdk.Cursor(Gdk.CursorType.LEFT_PTR) |
| 58 | WATCH_CURSOR = Gdk.Cursor(Gdk.CursorType.WATCH) |
| 59 | |
57 | 60 | _profile_version = 0 |
58 | 61 | _profile_path = os.path.join(activity.get_activity_root(), 'data/gecko') |
59 | 62 | _version_file = os.path.join(_profile_path, 'version') |
… |
… |
class WebActivity(activity.Activity): |
169 | 172 | self._force_close = False |
170 | 173 | self._tabbed_view = TabbedView() |
171 | 174 | self._tabbed_view.connect('focus-url-entry', self._on_focus_url_entry) |
| 175 | self._tabbed_view.connect('switch-page', self.__switch_page_cb) |
172 | 176 | |
173 | 177 | self._tray = HTray() |
174 | 178 | self.set_tray(self._tray, Gtk.PositionType.BOTTOM) |
… |
… |
class WebActivity(activity.Activity): |
596 | 600 | downloadmanager.remove_all_downloads() |
597 | 601 | self.close() |
598 | 602 | |
| 603 | def __switch_page_cb(self, tabbed_view, page, page_num): |
| 604 | browser = page._browser |
| 605 | status = browser.get_load_status() |
| 606 | |
| 607 | if status in (WebKit.LoadStatus.COMMITTED, |
| 608 | WebKit.LoadStatus.FIRST_VISUALLY_NON_EMPTY_LAYOUT): |
| 609 | self.get_window().set_cursor(WATCH_CURSOR) |
| 610 | elif status in (WebKit.LoadStatus.PROVISIONAL, |
| 611 | WebKit.LoadStatus.FAILED, |
| 612 | WebKit.LoadStatus.FINISHED): |
| 613 | self.get_window().set_cursor(NORMAL_CURSOR) |
| 614 | |
599 | 615 | def get_document_path(self, async_cb, async_err_cb): |
600 | 616 | browser = self._tabbed_view.props.current_browser |
601 | 617 | browser.get_source(async_cb, async_err_cb) |