Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Quiñones <manuq@laptop.org>2013-01-16 17:42:09 (GMT)
committer Manuel Quiñones <manuq@laptop.org>2013-01-17 17:38:01 (GMT)
commitebac9a46b76f87c2b3247368f1088f99856e47ee (patch)
treebb528f67ec575f71f09a1a88cfa8022b70de202d
parent61c2379fb50ab83ed186ad8826f62c63ae7e888e (diff)
Add a message box while the PDF is being downloaded - SL #4384
The message box is designed in the same style as others in Sugar, like in the Journal and the "no matches" in the Home activities list view. A book icon displays the download progress. The icon is stolen from Read Activity. Signed-off-by: Manuel Quiñones <manuq@laptop.org> Acked-by: Manuel Kaufmann <humitos@gmail.com>
-rw-r--r--icons/book.svg11
-rw-r--r--pdfviewer.py64
2 files changed, 74 insertions, 1 deletions
diff --git a/icons/book.svg b/icons/book.svg
new file mode 100644
index 0000000..d0d1804
--- /dev/null
+++ b/icons/book.svg
@@ -0,0 +1,11 @@
+<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
+ <!ENTITY stroke_color "#010101">
+ <!ENTITY fill_color "#FFFFFF">
+]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="activity-read">
+ <path d="M27.904,11.023h-0.002 c0-0.002-1.71-2.053-9.376-2.504C10.86,8.07,6.843,10.121,6.84,10.122c-1.898,0.619-3.495,1.735-3.495,3.494v27.702 c0,2.025,1.235,3.494,3.495,3.494c0.003,0,4.41-1.35,10.004-1.35c5.589-0.001,11.061,2.253,11.061,2.253" display="inline" fill="&fill_color;" stroke="&stroke_color;" stroke-linejoin="round" stroke-width="3.5"/>
+ <path d="M27.898,11.023 L27.898,11.023c0-0.002,1.715-2.053,9.377-2.504c7.668-0.449,11.686,1.602,11.688,1.603c1.897,0.619,3.494,1.735,3.494,3.494 v27.702c0,2.025-1.233,3.494-3.494,3.494c-0.003,0-4.409-1.35-10.004-1.35c-5.589-0.001-11.062,2.253-11.062,2.253" display="inline" fill="&fill_color;" stroke="&stroke_color;" stroke-linejoin="round" stroke-width="3.5"/>
+
+ <line display="inline" fill="none" stroke="&stroke_color;" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.5" x1="27.898" x2="27.9" y1="11.023" y2="45.717"/>
+ <path d=" M32.566,44.275c0,0-0.031,2.906-4.666,2.906c-4.632,0-4.663-2.906-4.663-2.906" display="inline" fill="none" stroke="&stroke_color;" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.5"/>
+</g></svg>
+
diff --git a/pdfviewer.py b/pdfviewer.py
index 6cfbaed..d1f1ecf 100644
--- a/pdfviewer.py
+++ b/pdfviewer.py
@@ -29,6 +29,9 @@ from gi.repository import WebKit
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.graphics.toolbutton import ToolButton
+from sugar3.graphics.icon import Icon
+from sugar3.graphics.progressicon import ProgressIcon
+from sugar3.graphics import style
from sugar3.datastore import datastore
from sugar3.activity import activity
@@ -279,14 +282,61 @@ class DummyBrowser(GObject.GObject):
pass
+class PDFMessageBox(Gtk.EventBox):
+ def __init__(self, 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()
+
+ icon = ProgressIcon(icon_name='book',
+ pixel_size=style.LARGE_ICON_SIZE,
+ stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
+ fill_color=style.COLOR_SELECTION_GREY.get_svg())
+ self.progress_icon = icon
+
+ box.pack_start(icon, expand=True, fill=False, padding=0)
+ icon.show()
+
+ label = Gtk.Label()
+ color = style.COLOR_BUTTON_GREY.get_html()
+ label.set_markup('<span weight="bold" 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=_('Cancel'))
+ button.connect('clicked', button_callback)
+ button.props.image = Icon(icon_name='dialog-cancel',
+ icon_size=Gtk.IconSize.BUTTON)
+ 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.
+ When the file is remote, display a message while downloading.
+
"""
def __init__(self):
GObject.GObject.__init__(self)
self._browser = DummyBrowser(self)
+ self._message_box = None
self._evince_viewer = None
self._pdf_uri = None
self._requested_uri = None
@@ -358,6 +408,13 @@ class PDFTabPage(Gtk.HBox):
def _download_from_http(self, remote_uri):
"""Download the PDF from a remote location to a temporal file."""
+ # Display a message
+ self._message_box = PDFMessageBox(
+ message=_("Downloading document..."),
+ button_callback=self.cancel_download)
+ self.pack_start(self._message_box, True, True, 0)
+ self._message_box.show()
+
# Figure out download URI
temp_path = os.path.join(activity.get_activity_root(), 'instance')
if not os.path.exists(temp_path):
@@ -380,14 +437,19 @@ class PDFTabPage(Gtk.HBox):
def __download_progress_cb(self, download, data):
progress = download.get_progress()
self._browser.props.progress = progress
+ self._message_box.progress_icon.update(progress)
def __download_status_cb(self, download, data):
status = download.get_status()
if status == WebKit.DownloadStatus.STARTED:
self._browser.props.load_status = WebKit.LoadStatus.PROVISIONAL
+
elif status == WebKit.DownloadStatus.FINISHED:
self._browser.props.load_status = WebKit.LoadStatus.FINISHED
+ self.remove(self._message_box)
+ self._message_box = None
self._show_pdf()
+
elif status == WebKit.DownloadStatus.CANCELLED:
logging.debug('Download PDF canceled')
@@ -395,7 +457,7 @@ class PDFTabPage(Gtk.HBox):
logging.debug('Download error! code %s, detail %s: %s' % \
(err_code, err_detail, reason))
- def cancel_download(self):
+ def cancel_download(self, button=None):
self._download.cancel()
self._browser.emit_close_tab()