Ticket #4398: 0006-Use-MessageBox-widget-and-remove-duplicated-code-SL-.patch

File 0006-Use-MessageBox-widget-and-remove-duplicated-code-SL-.patch, 7.6 KB (added by manuq, 10 years ago)

Patch - adapt shell

  • src/jarabe/desktop/activitieslist.py

    From dc18602b338d2e001639d68a2831f8f3b534345c Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Fri, 25 Jan 2013 17:37:10 -0300
    Subject: [PATCH shell 6/6] Use MessageBox widget and remove duplicated code -
     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 messages in Journal and Home list view for the new
    toolkit widget.
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/jarabe/desktop/activitieslist.py | 64 ++++++++++--------------------------
     src/jarabe/journal/listview.py       | 51 ++++++++++------------------
     2 files changed, 35 insertions(+), 80 deletions(-)
    
    diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py
    index 1cf67ab..12af6dd 100644
    a b import os 
    1919import logging
    2020from gettext import gettext as _
    2121
    22 from gi.repository import GLib
    2322from gi.repository import GObject
    2423from gi.repository import Pango
    2524from gi.repository import GConf
    from gi.repository import Gdk 
    2827
    2928from sugar3 import util
    3029from sugar3.graphics import style
     30from sugar3.graphics.messagebox import MessageBox
    3131from sugar3.graphics.icon import Icon, CellRendererIcon
    3232from sugar3.graphics.xocolor import XoColor
    3333from sugar3.graphics.alert import Alert
    class CellRendererActivityIcon(CellRendererIcon): 
    316316        self.emit('erase-activated', bundle_id)
    317317
    318318
    319 class ClearMessageBox(Gtk.EventBox):
    320     def __init__(self, message, button_callback):
    321         Gtk.EventBox.__init__(self)
    322 
    323         self.modify_bg(Gtk.StateType.NORMAL,
    324                        style.COLOR_WHITE.get_gdk_color())
    325 
    326         alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1)
    327         self.add(alignment)
    328         alignment.show()
    329 
    330         box = Gtk.VBox()
    331         alignment.add(box)
    332         box.show()
    333 
    334         icon = Icon(pixel_size=style.LARGE_ICON_SIZE,
    335                     icon_name='system-search',
    336                     stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
    337                     fill_color=style.COLOR_TRANSPARENT.get_svg())
    338         box.pack_start(icon, expand=True, fill=False, padding=0)
    339         icon.show()
    340 
    341         label = Gtk.Label()
    342         color = style.COLOR_BUTTON_GREY.get_html()
    343         label.set_markup('<span weight="bold" color="%s">%s</span>' % ( \
    344                 color, GLib.markup_escape_text(message)))
    345         box.pack_start(label, expand=True, fill=False, padding=0)
    346         label.show()
    347 
    348         button_box = Gtk.HButtonBox()
    349         button_box.set_layout(Gtk.ButtonBoxStyle.CENTER)
    350         box.pack_start(button_box, False, True, 0)
    351         button_box.show()
    352 
    353         button = Gtk.Button(label=_('Clear search'))
    354         button.connect('clicked', button_callback)
    355         button.props.image = Icon(icon_name='dialog-cancel',
    356                                   icon_size=Gtk.IconSize.BUTTON)
    357         button_box.pack_start(button, expand=True, fill=False, padding=0)
    358         button.show()
    359 
    360 
    361319class ActivitiesList(Gtk.VBox):
    362320    __gtype_name__ = 'SugarActivitiesList'
    363321
    class ActivitiesList(Gtk.VBox): 
    422380        if self._scrolled_window in self.get_children():
    423381            self.remove(self._scrolled_window)
    424382
    425         self._clear_message_box = ClearMessageBox(
    426             message=_('No matching activities'),
    427             button_callback=self.__clear_button_clicked_cb)
     383        # Create MessageBox.
     384
     385        self._clear_message_box = MessageBox(
     386            title=_('No matching activities'),
     387            icon = Icon(
     388                pixel_size=style.LARGE_ICON_SIZE,
     389                icon_name='system-search',
     390                stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
     391                fill_color=style.COLOR_TRANSPARENT.get_svg())
     392            )
    428393
    429394        self.pack_end(self._clear_message_box, True, True, 0)
    430395        self._clear_message_box.show()
    431396
     397        clear_button = Gtk.Button(label=_('Clear search'))
     398        clear_button.connect('clicked', self.__clear_button_clicked_cb)
     399        clear_button.props.image = Icon(icon_name='dialog-cancel',
     400                                        icon_size=Gtk.IconSize.BUTTON)
     401        self._clear_message_box.add_button(clear_button)
     402        clear_button.show()
     403
    432404    def __clear_button_clicked_cb(self, button):
    433405        self.emit('clear-clicked')
    434406
  • src/jarabe/journal/listview.py

    diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
    index 3005d2f..9544c26 100644
    a b import logging 
    1818from gettext import gettext as _
    1919import time
    2020
    21 from gi.repository import GLib
    2221from gi.repository import GObject
    2322from gi.repository import Gtk
    2423from gi.repository import Gdk
    from gi.repository import GConf 
    2625from gi.repository import Pango
    2726
    2827from sugar3.graphics import style
     28from sugar3.graphics.messagebox import MessageBox
    2929from sugar3.graphics.icon import Icon, CellRendererIcon
    3030from sugar3.graphics.xocolor import XoColor
    3131from sugar3 import util
    class BaseListView(Gtk.Bin): 
    393393    def _show_message(self, message, show_clear_query=False):
    394394        self.remove(self.get_child())
    395395
    396         background_box = Gtk.EventBox()
    397         background_box.modify_bg(Gtk.StateType.NORMAL,
    398                                  style.COLOR_WHITE.get_gdk_color())
    399         self.add(background_box)
     396        message_box = MessageBox(
     397            title = message,
     398            icon = Icon(
     399                pixel_size=style.LARGE_ICON_SIZE,
     400                icon_name='activity-journal',
     401                stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
     402                fill_color=style.COLOR_TRANSPARENT.get_svg())
     403            )
    400404
    401         alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1)
    402         background_box.add(alignment)
    403 
    404         box = Gtk.VBox()
    405         alignment.add(box)
    406 
    407         icon = Icon(pixel_size=style.LARGE_ICON_SIZE,
    408                     icon_name='activity-journal',
    409                     stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
    410                     fill_color=style.COLOR_TRANSPARENT.get_svg())
    411         box.pack_start(icon, expand=True, fill=False, padding=0)
    412 
    413         label = Gtk.Label()
    414         color = style.COLOR_BUTTON_GREY.get_html()
    415         label.set_markup('<span weight="bold" color="%s">%s</span>' % ( \
    416                 color, GLib.markup_escape_text(message)))
    417         box.pack_start(label, expand=True, fill=False, padding=0)
     405        self.add(message_box)
     406        message_box.show()
    418407
    419408        if show_clear_query:
    420             button_box = Gtk.HButtonBox()
    421             button_box.set_layout(Gtk.ButtonBoxStyle.CENTER)
    422             box.pack_start(button_box, False, True, 0)
    423             button_box.show()
    424 
    425             button = Gtk.Button(label=_('Clear search'))
    426             button.connect('clicked', self.__clear_button_clicked_cb)
    427             button.props.image = Icon(icon_name='dialog-cancel',
    428                                       icon_size=Gtk.IconSize.BUTTON)
    429             button_box.pack_start(button, expand=True, fill=False, padding=0)
    430 
    431         background_box.show_all()
     409            clear_button = Gtk.Button(label=_('Clear search'))
     410            clear_button.connect('clicked', self.__clear_button_clicked_cb)
     411            clear_button.props.image = Icon(icon_name='dialog-cancel',
     412                                            icon_size=Gtk.IconSize.BUTTON)
     413            message_box.add_button(clear_button)
     414            clear_button.show()
    432415
    433416    def __clear_button_clicked_cb(self, button):
    434417        self.emit('clear-clicked')