From 9ca338dc04f7285c97acd5f543803ecf2060e336 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 | 44 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)
diff --git a/webtoolbar.py b/webtoolbar.py
index 4db684e..79b1bf6 100644
a
|
b
|
from gi.repository import WebKit |
27 | 27 | from sugar3.graphics.toolbutton import ToolButton |
28 | 28 | from sugar3.graphics import iconentry |
29 | 29 | from sugar3.graphics.toolbarbox import ToolbarBox as ToolbarBase |
30 | | from sugar3.graphics.style import STANDARD_ICON_SIZE |
| 30 | from sugar3.graphics import style |
31 | 31 | from sugar3.activity.widgets import ActivityToolbarButton |
32 | 32 | from sugar3.activity.widgets import StopButton |
33 | 33 | |
… |
… |
from browser import Browser |
40 | 40 | _MAX_HISTORY_ENTRIES = 15 |
41 | 41 | |
42 | 42 | |
| 43 | class _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 | |
43 | 52 | class WebEntry(iconentry.IconEntry): |
44 | 53 | _COL_ADDRESS = 0 |
45 | 54 | _COL_TITLE = 1 |
… |
… |
class WebEntry(iconentry.IconEntry): |
50 | 59 | self._address = None |
51 | 60 | self._search_view = self._search_create_view() |
52 | 61 | |
53 | | self._search_window = Gtk.Window(type=Gtk.WindowType.POPUP) |
| 62 | self._search_window = _SearchWindow() |
54 | 63 | self._search_window.add(self._search_view) |
55 | 64 | self._search_view.show() |
56 | 65 | |
… |
… |
class WebEntry(iconentry.IconEntry): |
61 | 70 | 'focus-out-event', self.__focus_out_event_cb) |
62 | 71 | self._change_hid = self.connect('changed', self.__changed_cb) |
63 | 72 | |
| 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, 0, allocation.width, allocation.height) |
| 81 | cr.paint() |
| 82 | |
| 83 | cr.set_source_rgba(*style.COLOR_BUTTON_GREY.get_rgba()) |
| 84 | # Set the line width two times the theme border to make |
| 85 | # the calculation easier. |
| 86 | cr.set_line_width(style.LINE_WIDTH * 4) |
| 87 | cr.move_to(0, allocation.height) |
| 88 | cr.line_to(0, 0) |
| 89 | cr.line_to(allocation.width, 0) |
| 90 | cr.line_to(allocation.width, allocation.height) |
| 91 | cr.stroke() |
| 92 | |
| 93 | cr.new_path() |
| 94 | cr.append_path(original_path) |
| 95 | |
| 96 | iconentry.IconEntry.do_draw(self, cr) |
| 97 | |
64 | 98 | def _set_text(self, text): |
65 | 99 | """Set the text but block changes notification, so that we can |
66 | 100 | recognize changes caused directly by user actions""" |
… |
… |
class WebEntry(iconentry.IconEntry): |
85 | 119 | def _search_create_view(self): |
86 | 120 | view = Gtk.TreeView() |
87 | 121 | view.props.headers_visible = False |
88 | | view.props.rules_hint = True |
89 | 122 | |
90 | 123 | view.connect('button-press-event', self.__view_button_press_event_cb) |
91 | 124 | |
… |
… |
class WebEntry(iconentry.IconEntry): |
95 | 128 | cell = Gtk.CellRendererText() |
96 | 129 | cell.props.ellipsize = Pango.EllipsizeMode.END |
97 | 130 | cell.props.ellipsize_set = True |
98 | | cell.props.height = STANDARD_ICON_SIZE |
| 131 | cell.props.height = style.STANDARD_ICON_SIZE |
99 | 132 | cell.props.font = 'Bold' |
100 | 133 | column.pack_start(cell, True) |
101 | 134 | |
… |
… |
class WebEntry(iconentry.IconEntry): |
131 | 164 | search_x = window_x + entry_allocation.x |
132 | 165 | search_y = window_y + gap + preferred_height |
133 | 166 | search_width = entry_allocation.width |
134 | | search_height = Gdk.Screen.height() / 3 |
| 167 | # Set minimun height to four entries. |
| 168 | search_height = (style.STANDARD_ICON_SIZE + style.LINE_WIDTH * 2) * 4 |
135 | 169 | |
136 | 170 | self._search_window.move(search_x, search_y) |
137 | 171 | self._search_window.resize(search_width, search_height) |