Ticket #4398: 0001-PDF-view-Use-MessageBox-SL-4398.patch

File 0001-PDF-view-Use-MessageBox-SL-4398.patch, 5.0 KB (added by manuq, 11 years ago)

Patch - adapt Browse

  • pdfviewer.py

    From e456fa822c80558ed2b3f3bcfd8d73147c311cce Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Fri, 25 Jan 2013 17:33:42 -0300
    Subject: [PATCH Browse] PDF view: Use MessageBox - SL #4398
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    Replace the custom one and use the new toolkit widget.
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     pdfviewer.py | 70 ++++++++++++++++++------------------------------------------
     1 file changed, 21 insertions(+), 49 deletions(-)
    
    diff --git a/pdfviewer.py b/pdfviewer.py
    index e0030ef..9493293 100644
    a b from gettext import gettext as _ 
    2222
    2323from gi.repository import GObject
    2424from gi.repository import Gtk
    25 from gi.repository import GLib
    2625from gi.repository import EvinceDocument
    2726from gi.repository import EvinceView
    2827from gi.repository import WebKit
    from sugar3.graphics.toolbutton import ToolButton 
    3231from sugar3.graphics.icon import Icon
    3332from sugar3.graphics.progressicon import ProgressIcon
    3433from sugar3.graphics import style
     34from sugar3.graphics.messagebox import MessageBox
    3535from sugar3.datastore import datastore
    3636from sugar3.activity import activity
    3737
    class DummyBrowser(GObject.GObject): 
    301301        pass
    302302
    303303
    304 class PDFMessageBox(Gtk.EventBox):
    305     def __init__(self, message, button_callback):
    306         Gtk.EventBox.__init__(self)
    307 
    308         self.modify_bg(Gtk.StateType.NORMAL,
    309                        style.COLOR_WHITE.get_gdk_color())
    310 
    311         alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1)
    312         self.add(alignment)
    313         alignment.show()
    314 
    315         box = Gtk.VBox()
    316         alignment.add(box)
    317         box.show()
    318 
    319         icon = ProgressIcon(icon_name='book',
    320                             pixel_size=style.LARGE_ICON_SIZE,
    321                             stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
    322                             fill_color=style.COLOR_SELECTION_GREY.get_svg())
    323         self.progress_icon = icon
    324 
    325         box.pack_start(icon, expand=True, fill=False, padding=0)
    326         icon.show()
    327 
    328         label = Gtk.Label()
    329         color = style.COLOR_BUTTON_GREY.get_html()
    330         label.set_markup('<span weight="bold" color="%s">%s</span>' % ( \
    331                 color, GLib.markup_escape_text(message)))
    332         box.pack_start(label, expand=True, fill=False, padding=0)
    333         label.show()
    334 
    335         button_box = Gtk.HButtonBox()
    336         button_box.set_layout(Gtk.ButtonBoxStyle.CENTER)
    337         box.pack_start(button_box, False, True, 0)
    338         button_box.show()
    339 
    340         button = Gtk.Button(label=_('Cancel'))
    341         button.connect('clicked', button_callback)
    342         button.props.image = Icon(icon_name='dialog-cancel',
    343                                   icon_size=Gtk.IconSize.BUTTON)
    344         button_box.pack_start(button, expand=True, fill=False, padding=0)
    345         button.show()
    346 
    347 
    348304class PDFTabPage(Gtk.HBox):
    349305    """Shows a basic PDF viewer, download the file first if the PDF is
    350306    in a remote location.
    class PDFTabPage(Gtk.HBox): 
    355311    def __init__(self):
    356312        GObject.GObject.__init__(self)
    357313        self._browser = DummyBrowser(self)
     314        self._progress_icon = None
    358315        self._message_box = None
    359316        self._evince_viewer = None
    360317        self._pdf_uri = None
    class PDFTabPage(Gtk.HBox): 
    428385        """Download the PDF from a remote location to a temporal file."""
    429386
    430387        # Display a message
    431         self._message_box = PDFMessageBox(
    432             message=_("Downloading document..."),
    433             button_callback=self.cancel_download)
     388
     389        self._progress_icon = ProgressIcon(
     390            icon_name='book',
     391            pixel_size=style.LARGE_ICON_SIZE,
     392            stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
     393            fill_color=style.COLOR_SELECTION_GREY.get_svg())
     394
     395        self._message_box = MessageBox(
     396            title = _("Downloading document..."),
     397            icon = self._progress_icon)
     398
    434399        self.pack_start(self._message_box, True, True, 0)
    435400        self._message_box.show()
    436401
     402        cancel_button = Gtk.Button(label=_('Cancel'))
     403        cancel_button.connect('clicked', self.cancel_download)
     404        cancel_button.props.image = Icon(icon_name='dialog-cancel',
     405                                  icon_size=Gtk.IconSize.BUTTON)
     406        self._message_box.add_button(cancel_button)
     407        cancel_button.show()
     408
    437409        # Figure out download URI
    438410        temp_path = os.path.join(activity.get_activity_root(), 'instance')
    439411        if not os.path.exists(temp_path):
    class PDFTabPage(Gtk.HBox): 
    456428    def __download_progress_cb(self, download, data):
    457429        progress = download.get_progress()
    458430        self._browser.props.progress = progress
    459         self._message_box.progress_icon.update(progress)
     431        self._progress_icon.update(progress)
    460432
    461433    def __download_status_cb(self, download, data):
    462434        status = download.get_status()