Ticket #4049: 0002-Improve-styling-of-the-autocomplete-list-SL-4049-V2.patch

File 0002-Improve-styling-of-the-autocomplete-list-SL-4049-V2.patch, 4.4 KB (added by manuq, 12 years ago)

Patch similar than the previous, counter proposal.

  • webtoolbar.py

    From 63d16a9a93c7fe91aefb89c4afd2b87fa0a64300 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Thu, 25 Oct 2012 00:19:12 -0300
    Subject: [PATCH browse 2/2] Improve styling of the autocomplete list - SL
     #4049
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    - add background to the entry to match the drop down list
    - make the list styleable
    - set the list minimun height to match four entries
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     webtoolbar.py | 45 ++++++++++++++++++++++++++++++++++++++++-----
     1 file changed, 40 insertions(+), 5 deletions(-)
    
    diff --git a/webtoolbar.py b/webtoolbar.py
    index 4db684e..b241389 100644
    a b from gi.repository import WebKit 
    2727from sugar3.graphics.toolbutton import ToolButton
    2828from sugar3.graphics import iconentry
    2929from sugar3.graphics.toolbarbox import ToolbarBox as ToolbarBase
    30 from sugar3.graphics.style import STANDARD_ICON_SIZE
     30from sugar3.graphics import style
    3131from sugar3.activity.widgets import ActivityToolbarButton
    3232from sugar3.activity.widgets import StopButton
    3333
    from browser import Browser 
    4040_MAX_HISTORY_ENTRIES = 15
    4141
    4242
     43class _SearchWindow(Gtk.Window):
     44    """A search window that can be styled in the theme."""
     45
     46    __gtype_name__ = "BrowseSearchWindow"
     47
     48    def __init__(self):
     49        Gtk.Window.__init__(self, type=Gtk.WindowType.POPUP)
     50
     51
    4352class WebEntry(iconentry.IconEntry):
    4453    _COL_ADDRESS = 0
    4554    _COL_TITLE = 1
    class WebEntry(iconentry.IconEntry): 
    5059        self._address = None
    5160        self._search_view = self._search_create_view()
    5261
    53         self._search_window = Gtk.Window(type=Gtk.WindowType.POPUP)
     62        self._search_window = _SearchWindow()
    5463        self._search_window.add(self._search_view)
    5564        self._search_view.show()
    5665
    class WebEntry(iconentry.IconEntry): 
    6170                    'focus-out-event', self.__focus_out_event_cb)
    6271        self._change_hid = self.connect('changed', self.__changed_cb)
    6372
     73    def do_draw(self, cr):
     74        """Draw a background to better fit the search window."""
     75        if self._search_window.props.visible:
     76            original_path = cr.copy_path()
     77
     78            allocation = self.get_allocation()
     79            cr.set_source_rgb(0, 0, 0)
     80            cr.rectangle(0, allocation.height / 2,
     81                         allocation.width, allocation.height / 2)
     82            cr.fill()
     83
     84            cr.set_source_rgba(*style.COLOR_BUTTON_GREY.get_rgba())
     85            # Set the line width two times the theme border to make
     86            # the calculation easier.
     87            cr.set_line_width(style.LINE_WIDTH * 4)
     88            cr.move_to(0, allocation.height)
     89            cr.line_to(0, allocation.height / 2)
     90            cr.move_to(allocation.width, allocation.height)
     91            cr.line_to(allocation.width, allocation.height / 2)
     92            cr.stroke()
     93
     94            cr.new_path()
     95            cr.append_path(original_path)
     96
     97        iconentry.IconEntry.do_draw(self, cr)
     98
    6499    def _set_text(self, text):
    65100        """Set the text but block changes notification, so that we can
    66101           recognize changes caused directly by user actions"""
    class WebEntry(iconentry.IconEntry): 
    85120    def _search_create_view(self):
    86121        view = Gtk.TreeView()
    87122        view.props.headers_visible = False
    88         view.props.rules_hint = True
    89123
    90124        view.connect('button-press-event', self.__view_button_press_event_cb)
    91125
    class WebEntry(iconentry.IconEntry): 
    95129        cell = Gtk.CellRendererText()
    96130        cell.props.ellipsize = Pango.EllipsizeMode.END
    97131        cell.props.ellipsize_set = True
    98         cell.props.height = STANDARD_ICON_SIZE
     132        cell.props.height = style.STANDARD_ICON_SIZE
    99133        cell.props.font = 'Bold'
    100134        column.pack_start(cell, True)
    101135
    class WebEntry(iconentry.IconEntry): 
    131165        search_x = window_x + entry_allocation.x
    132166        search_y = window_y + gap + preferred_height
    133167        search_width = entry_allocation.width
    134         search_height = Gdk.Screen.height() / 3
     168        # Set minimun height to four entries.
     169        search_height = (style.STANDARD_ICON_SIZE + style.LINE_WIDTH * 2) * 4
    135170
    136171        self._search_window.move(search_x, search_y)
    137172        self._search_window.resize(search_width, search_height)