Ticket #4384: 0001-Add-a-message-box-while-the-PDF-is-being-downloaded-.patch
File 0001-Add-a-message-box-while-the-PDF-is-being-downloaded-.patch, 6.7 KB (added by manuq, 11 years ago) |
---|
-
new file icons/book.svg
From 254c0946930c5bb2e84cb1906e0b96f79e757fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org> Date: Wed, 16 Jan 2013 14:42:09 -0300 Subject: [PATCH browse] Add a message box while the PDF is being downloaded - SL #? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mail-Followup-To: <sugar-devel@lists.sugarlabs.org> 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> --- icons/book.svg | 11 ++++++++++ pdfviewer.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 icons/book.svg diff --git a/icons/book.svg b/icons/book.svg new file mode 100644 index 0000000..d0d1804
- + 1 <?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [ 2 <!ENTITY stroke_color "#010101"> 3 <!ENTITY fill_color "#FFFFFF"> 4 ]><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"> 5 <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"/> 6 <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"/> 7 8 <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"/> 9 <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"/> 10 </g></svg> 11 -
pdfviewer.py
diff --git a/pdfviewer.py b/pdfviewer.py index 6cfbaed..a3ededa 100644
a b from gi.repository import WebKit 29 29 30 30 from sugar3.graphics.toolbarbox import ToolbarBox 31 31 from sugar3.graphics.toolbutton import ToolButton 32 from sugar3.graphics.icon import Icon 33 from sugar3.graphics.iconprogress import IconProgress 34 from sugar3.graphics import style 32 35 from sugar3.datastore import datastore 33 36 from sugar3.activity import activity 34 37 … … class DummyBrowser(GObject.GObject): 279 282 pass 280 283 281 284 285 class PDFMessageBox(Gtk.EventBox): 286 def __init__(self, message, button_callback): 287 Gtk.EventBox.__init__(self) 288 289 self.modify_bg(Gtk.StateType.NORMAL, 290 style.COLOR_WHITE.get_gdk_color()) 291 292 alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1) 293 self.add(alignment) 294 alignment.show() 295 296 box = Gtk.VBox() 297 alignment.add(box) 298 box.show() 299 300 icon = IconProgress(icon_name='book', 301 pixel_size=style.LARGE_ICON_SIZE, 302 stroke_color=style.COLOR_BUTTON_GREY.get_svg(), 303 fill_color=style.COLOR_SELECTION_GREY.get_svg()) 304 self.icon_progress = icon 305 306 box.pack_start(icon, expand=True, fill=False, padding=0) 307 icon.show() 308 309 label = Gtk.Label() 310 color = style.COLOR_BUTTON_GREY.get_html() 311 label.set_markup('<span weight="bold" color="%s">%s</span>' % ( \ 312 color, GLib.markup_escape_text(message))) 313 box.pack_start(label, expand=True, fill=False, padding=0) 314 label.show() 315 316 button_box = Gtk.HButtonBox() 317 button_box.set_layout(Gtk.ButtonBoxStyle.CENTER) 318 box.pack_start(button_box, False, True, 0) 319 button_box.show() 320 321 button = Gtk.Button(label=_('Cancel')) 322 button.connect('clicked', button_callback) 323 button.props.image = Icon(icon_name='dialog-cancel', 324 icon_size=Gtk.IconSize.BUTTON) 325 button_box.pack_start(button, expand=True, fill=False, padding=0) 326 button.show() 327 328 282 329 class PDFTabPage(Gtk.HBox): 283 330 """Shows a basic PDF viewer, download the file first if the PDF is 284 331 in a remote location. 285 332 333 When the file is remote, display a message while downloading. 334 286 335 """ 287 336 def __init__(self): 288 337 GObject.GObject.__init__(self) … … class PDFTabPage(Gtk.HBox): 358 407 def _download_from_http(self, remote_uri): 359 408 """Download the PDF from a remote location to a temporal file.""" 360 409 410 # Display a message 411 message_box = PDFMessageBox( 412 message=_("Downloading document..."), 413 button_callback=self.cancel_download) 414 self.pack_start(message_box, True, True, 0) 415 message_box.show() 416 361 417 # Figure out download URI 362 418 temp_path = os.path.join(activity.get_activity_root(), 'instance') 363 419 if not os.path.exists(temp_path): … … class PDFTabPage(Gtk.HBox): 381 437 progress = download.get_progress() 382 438 self._browser.props.progress = progress 383 439 440 # Update progress in the message box too 441 message_box = self.get_children()[0] 442 message_box.icon_progress.update(progress) 443 384 444 def __download_status_cb(self, download, data): 385 445 status = download.get_status() 386 446 if status == WebKit.DownloadStatus.STARTED: 387 447 self._browser.props.load_status = WebKit.LoadStatus.PROVISIONAL 388 448 elif status == WebKit.DownloadStatus.FINISHED: 389 449 self._browser.props.load_status = WebKit.LoadStatus.FINISHED 450 451 # Remove the message box 452 message_box = self.get_children()[0] 453 self.remove(message_box) 454 390 455 self._show_pdf() 391 456 elif status == WebKit.DownloadStatus.CANCELLED: 392 457 logging.debug('Download PDF canceled') … … class PDFTabPage(Gtk.HBox): 395 460 logging.debug('Download error! code %s, detail %s: %s' % \ 396 461 (err_code, err_detail, reason)) 397 462 398 def cancel_download(self ):463 def cancel_download(self, button=None): 399 464 self._download.cancel() 400 465 self._browser.emit_close_tab() 401 466