Ticket #4398: 0001-Adapt-Browse-to-new-MessageBox-widget-VERSION2.patch

File 0001-Adapt-Browse-to-new-MessageBox-widget-VERSION2.patch, 8.4 KB (added by svineet, 9 years ago)
  • pdfviewer.py

    From 3d9c8259f4433466a5e510d226010f180cb1dcc4 Mon Sep 17 00:00:00 2001
    From: Sai Vineet <saivineet89@gmail.com>
    Date: Tue, 2 Dec 2014 11:17:00 +0530
    Subject: [PATCH 1/1] Adapt Browse to new MessageBox widget in toolkit (with
     manuq)
    
    ---
     pdfviewer.py | 153 +++++++++++++++++------------------------------------------
     1 file changed, 43 insertions(+), 110 deletions(-)
    
    diff --git a/pdfviewer.py b/pdfviewer.py
    index 3834b00..9d161c4 100644
    a b from gettext import gettext as _ 
    2121
    2222from gi.repository import GObject
    2323from gi.repository import Gtk
    24 from gi.repository import GLib
    2524from gi.repository import WebKit
    2625
    2726from sugar3.graphics.toolbarbox import ToolbarBox
    from sugar3.graphics import style 
    3231from sugar3.datastore import datastore
    3332from sugar3.activity import activity
    3433from sugar3.bundle.activitybundle import ActivityBundle
     34from sugar3.graphics.messagebox import MessageBox
    3535
    3636
    3737class EvinceViewer(Gtk.VBox):
    class DummyBrowser(GObject.GObject): 
    304304        pass
    305305
    306306
    307 class PDFProgressMessageBox(Gtk.EventBox):
    308     def __init__(self, message, button_callback):
    309         Gtk.EventBox.__init__(self)
    310 
    311         self.modify_bg(Gtk.StateType.NORMAL,
    312                        style.COLOR_WHITE.get_gdk_color())
    313 
    314         alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1)
    315         self.add(alignment)
    316         alignment.show()
    317 
    318         box = Gtk.VBox()
    319         alignment.add(box)
    320         box.show()
    321 
    322         icon = ProgressIcon(icon_name='book',
    323                             pixel_size=style.LARGE_ICON_SIZE,
    324                             stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
    325                             fill_color=style.COLOR_SELECTION_GREY.get_svg())
    326         self.progress_icon = icon
    327 
    328         box.pack_start(icon, expand=True, fill=False, padding=0)
    329         icon.show()
    330 
    331         label = Gtk.Label()
    332         color = style.COLOR_BUTTON_GREY.get_html()
    333         label.set_markup('<span weight="bold" color="%s">%s</span>' % (
    334             color, GLib.markup_escape_text(message)))
    335         box.pack_start(label, expand=True, fill=False, padding=0)
    336         label.show()
    337 
    338         button_box = Gtk.HButtonBox()
    339         button_box.set_layout(Gtk.ButtonBoxStyle.CENTER)
    340         box.pack_start(button_box, False, True, 0)
    341         button_box.show()
    342 
    343         button = Gtk.Button(label=_('Cancel'))
    344         button.connect('clicked', button_callback)
    345         button.props.image = Icon(icon_name='dialog-cancel',
    346                                   pixel_size=style.SMALL_ICON_SIZE)
    347         button_box.pack_start(button, expand=True, fill=False, padding=0)
    348         button.show()
    349 
    350 
    351 class PDFErrorMessageBox(Gtk.EventBox):
    352     def __init__(self, title, message, button_callback):
    353         Gtk.EventBox.__init__(self)
    354 
    355         self.modify_bg(Gtk.StateType.NORMAL,
    356                        style.COLOR_WHITE.get_gdk_color())
    357 
    358         alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1)
    359         self.add(alignment)
    360         alignment.show()
    361 
    362         box = Gtk.VBox()
    363         alignment.add(box)
    364         box.show()
    365 
    366         # Get the icon of this activity through the bundle path.
    367         bundle_path = activity.get_bundle_path()
    368         activity_bundle = ActivityBundle(bundle_path)
    369         icon = Icon(pixel_size=style.LARGE_ICON_SIZE,
    370                     file=activity_bundle.get_icon(),
    371                     stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
    372                     fill_color=style.COLOR_TRANSPARENT.get_svg())
    373 
    374         box.pack_start(icon, expand=True, fill=False, padding=0)
    375         icon.show()
    376 
    377         color = style.COLOR_BUTTON_GREY.get_html()
    378 
    379         label = Gtk.Label()
    380         label.set_markup('<span weight="bold" color="%s">%s</span>' % (
    381             color, GLib.markup_escape_text(title)))
    382         box.pack_start(label, expand=True, fill=False, padding=0)
    383         label.show()
    384 
    385         label = Gtk.Label()
    386         label.set_markup('<span color="%s">%s</span>' % (
    387             color, GLib.markup_escape_text(message)))
    388         box.pack_start(label, expand=True, fill=False, padding=0)
    389         label.show()
    390 
    391         button_box = Gtk.HButtonBox()
    392         button_box.set_layout(Gtk.ButtonBoxStyle.CENTER)
    393         box.pack_start(button_box, False, True, 0)
    394         button_box.show()
    395 
    396         button = Gtk.Button(label=_('Try again'))
    397         button.connect('clicked', button_callback)
    398         button.props.image = Icon(icon_name='entry-refresh',
    399                                   pixel_size=style.SMALL_ICON_SIZE,
    400                                   stroke_color=style.COLOR_WHITE.get_svg(),
    401                                   fill_color=style.COLOR_TRANSPARENT.get_svg())
    402         button_box.pack_start(button, expand=True, fill=False, padding=0)
    403         button.show()
    404 
    405 
    406307class PDFTabPage(Gtk.HBox):
    407308    """Shows a basic PDF viewer, download the file first if the PDF is
    408309    in a remote location.
    class PDFTabPage(Gtk.HBox): 
    488389        """Download the PDF from a remote location to a temporal file."""
    489390
    490391        # Display a message
    491         self._message_box = PDFProgressMessageBox(
    492             message=_("Downloading document..."),
    493             button_callback=self.close_tab)
     392        icon = ProgressIcon(icon_name='book',
     393                            pixel_size=style.LARGE_ICON_SIZE,
     394                            stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
     395                            fill_color=style.COLOR_SELECTION_GREY.get_svg())
     396        self.progress_icon = icon
     397
     398        self._message_box = MessageBox(title=_("Downloading document..."),
     399                                       icon=self.progress_icon)
     400
     401        cancel_btn = Gtk.Button(label=_('Cancel'))
     402        cancel_btn.connect('clicked', self.close_tab)
     403        cancel_btn.props.image = Icon(icon_name='dialog-cancel',
     404                                      pixel_size=style.SMALL_ICON_SIZE)
     405
     406        self._message_box.add_button(cancel_btn)
     407        self._message_box.show_all()
    494408        self.pack_start(self._message_box, True, True, 0)
    495         self._message_box.show()
    496409
    497410        # Figure out download URI
    498411        temp_path = os.path.join(activity.get_activity_root(), 'instance')
    class PDFTabPage(Gtk.HBox): 
    522435        total_size = download.get_total_size()
    523436        progress = current_size / float(total_size)
    524437        self._browser.props.progress = progress
    525         self._message_box.progress_icon.update(progress)
     438        self.progress_icon.update(progress)
    526439
    527440    def __download_progress_cb(self, download, data):
    528441        progress = download.get_progress()
    529442        self._browser.props.progress = progress
    530         self._message_box.progress_icon.update(progress)
     443        self.progress_icon.update(progress)
    531444
    532445    def __download_status_cb(self, download, data):
    533446        status = download.get_status()
    class PDFTabPage(Gtk.HBox): 
    552465        if self._message_box is not None:
    553466            self.remove(self._message_box)
    554467
    555         self._message_box = PDFErrorMessageBox(
     468        # Get the icon of this activity through the bundle path.
     469        bundle_path = activity.get_bundle_path()
     470        activity_bundle = ActivityBundle(bundle_path)
     471        icon = Icon(pixel_size=style.LARGE_ICON_SIZE,
     472                    file=activity_bundle.get_icon(),
     473                    stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
     474                    fill_color=style.COLOR_TRANSPARENT.get_svg())
     475
     476        desc = _('Please make sure you are connected to the Internet.')
     477        # no inline because of PEP8
     478        self._message_box = MessageBox(
    556479            title=title,
    557             message=_('Please make sure you are connected to the Internet.'),
    558             button_callback=self.reload)
     480            icon=icon,
     481            description=desc
     482            )
     483
     484        button = Gtk.Button(label=_('Try again'))
     485        button.props.image = Icon(icon_name='entry-refresh',
     486                                  pixel_size=style.SMALL_ICON_SIZE,
     487                                  stroke_color=style.COLOR_WHITE.get_svg(),
     488                                  fill_color=style.COLOR_TRANSPARENT.get_svg())
     489        button.connect('clicked', self.reload)
     490        self._message_box.add_button(button)
     491
    559492        self.pack_start(self._message_box, True, True, 0)
    560         self._message_box.show()
     493        self._message_box.show_all()
    561494
    562495    def reload(self, button=None):
    563496        self.remove(self._message_box)