Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pdfviewer.py
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2013-02-14 15:44:14 (GMT)
committer Manuel QuiƱones <manuq@laptop.org>2013-02-18 19:13:16 (GMT)
commit5e48a0361734df2dcf6993d1b33de6192cc0994b (patch)
treebbcc051a5c88f75149c5f8312b12b75cb3e20779 /pdfviewer.py
parent7371daa2e595a0e79cd5b5dac82bcdad52f26249 (diff)
Show error page when downloading a PDF fails SL #4011
When the 'error' signal is emitted while a PDF file is being downloaded, Browse shows an error page similar to the one showed when a web page could not be reached. Signed-off-by: Manuel Kaufmann <humitos@gmail.com> Signed-off-by: Manuel QuiƱones <manuq@laptop.org>
Diffstat (limited to 'pdfviewer.py')
-rw-r--r--pdfviewer.py77
1 files changed, 75 insertions, 2 deletions
diff --git a/pdfviewer.py b/pdfviewer.py
index 40de7ec..7557594 100644
--- a/pdfviewer.py
+++ b/pdfviewer.py
@@ -34,6 +34,7 @@ from sugar3.graphics.progressicon import ProgressIcon
from sugar3.graphics import style
from sugar3.datastore import datastore
from sugar3.activity import activity
+from sugar3.bundle.activitybundle import ActivityBundle
class EvinceViewer(Gtk.Overlay):
@@ -301,7 +302,7 @@ class DummyBrowser(GObject.GObject):
pass
-class PDFMessageBox(Gtk.EventBox):
+class PDFProgressMessageBox(Gtk.EventBox):
def __init__(self, message, button_callback):
Gtk.EventBox.__init__(self)
@@ -345,6 +346,61 @@ class PDFMessageBox(Gtk.EventBox):
button.show()
+class PDFErrorMessageBox(Gtk.EventBox):
+ def __init__(self, title, message, button_callback):
+ Gtk.EventBox.__init__(self)
+
+ self.modify_bg(Gtk.StateType.NORMAL,
+ style.COLOR_WHITE.get_gdk_color())
+
+ alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1)
+ self.add(alignment)
+ alignment.show()
+
+ box = Gtk.VBox()
+ alignment.add(box)
+ box.show()
+
+ # Get the icon of this activity through the bundle path.
+ bundle_path = activity.get_bundle_path()
+ activity_bundle = ActivityBundle(bundle_path)
+ icon = Icon(pixel_size=style.LARGE_ICON_SIZE,
+ file=activity_bundle.get_icon(),
+ stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
+ fill_color=style.COLOR_TRANSPARENT.get_svg())
+
+ box.pack_start(icon, expand=True, fill=False, padding=0)
+ icon.show()
+
+ color = style.COLOR_BUTTON_GREY.get_html()
+
+ label = Gtk.Label()
+ label.set_markup('<span weight="bold" color="%s">%s</span>' % ( \
+ color, GLib.markup_escape_text(title)))
+ box.pack_start(label, expand=True, fill=False, padding=0)
+ label.show()
+
+ label = Gtk.Label()
+ label.set_markup('<span color="%s">%s</span>' % ( \
+ color, GLib.markup_escape_text(message)))
+ box.pack_start(label, expand=True, fill=False, padding=0)
+ label.show()
+
+ button_box = Gtk.HButtonBox()
+ button_box.set_layout(Gtk.ButtonBoxStyle.CENTER)
+ box.pack_start(button_box, False, True, 0)
+ button_box.show()
+
+ button = Gtk.Button(label=_('Try again'))
+ button.connect('clicked', button_callback)
+ button.props.image = Icon(icon_name='entry-refresh',
+ icon_size=Gtk.IconSize.BUTTON,
+ stroke_color=style.COLOR_WHITE.get_svg(),
+ fill_color=style.COLOR_TRANSPARENT.get_svg())
+ button_box.pack_start(button, expand=True, fill=False, padding=0)
+ button.show()
+
+
class PDFTabPage(Gtk.HBox):
"""Shows a basic PDF viewer, download the file first if the PDF is
in a remote location.
@@ -428,7 +484,7 @@ class PDFTabPage(Gtk.HBox):
"""Download the PDF from a remote location to a temporal file."""
# Display a message
- self._message_box = PDFMessageBox(
+ self._message_box = PDFProgressMessageBox(
message=_("Downloading document..."),
button_callback=self.close_tab)
self.pack_start(self._message_box, True, True, 0)
@@ -475,6 +531,23 @@ class PDFTabPage(Gtk.HBox):
def __download_error_cb(self, download, err_code, err_detail, reason):
logging.debug('Download error! code %s, detail %s: %s' % \
(err_code, err_detail, reason))
+ title = _('This document could not be loaded')
+ self._browser.props.title = title
+
+ if self._message_box is not None:
+ self.remove(self._message_box)
+
+ self._message_box = PDFErrorMessageBox(
+ title=title,
+ message=_('Please make sure you are connected to the Internet.'),
+ button_callback=self.reload)
+ self.pack_start(self._message_box, True, True, 0)
+ self._message_box.show()
+
+ def reload(self, button=None):
+ self.remove(self._message_box)
+ self._message_box = None
+ self.setup(self._requested_uri)
def close_tab(self, button=None):
self._browser.emit_close_tab()