[Sugar-devel] [PATCH Log v2] Don't update search results every keystroke

Manuel Quiñones manuq at laptop.org
Thu Apr 12 13:19:49 EDT 2012


El día 12 de abril de 2012 14:14, Manuel Kaufmann <humitos at gmail.com> escribió:
> If the log file is long and we search for new results every time that a key is
> pressed this action could consume a lot of CPU. Even more if we search for a
> single char.
>
> So, I changed the way that it works to update the search results every time the
> user presses the Enter key and if there are results for that query the Entry
> box is highlighted with yellow color and if there are no results with red
> color..

This is a great improvement.

> This commit solves: #2734
>
> Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
Reviewed-by: Manuel Quiñones <manuq at laptop.org>


> ---
>  logviewer.py |   43 ++++++++++++++++++++++++++++++++++---------
>  1 file changed, 34 insertions(+), 9 deletions(-)
>
> diff --git a/logviewer.py b/logviewer.py
> index 88fe2e6..5fbc6ab 100644
> --- a/logviewer.py
> +++ b/logviewer.py
> @@ -383,15 +383,15 @@ class LogActivity(activity.Activity):
>         wrap_btn.connect('clicked', self._wrap_cb)
>         toolbar_box.toolbar.insert(wrap_btn, -1)
>
> -        search_entry = iconentry.IconEntry()
> -        search_entry.set_size_request(gtk.gdk.screen_width() / 3, -1)
> -        search_entry.set_icon_from_name(
> +        self._search_entry = iconentry.IconEntry()
> +        self._search_entry.set_size_request(gtk.gdk.screen_width() / 3, -1)
> +        self._search_entry.set_icon_from_name(
>                 iconentry.ICON_ENTRY_PRIMARY, 'system-search')
> -        search_entry.add_clear_button()
> -        search_entry.connect('activate', self._search_entry_activate_cb)
> -        search_entry.connect('changed', self._search_entry_changed_cb)
> +        self._search_entry.add_clear_button()
> +        self._search_entry.connect('activate', self._search_entry_activate_cb)
> +        self._search_entry.connect('changed', self._search_entry_changed_cb)
>         search_item = gtk.ToolItem()
> -        search_item.add(search_entry)
> +        search_item.add(self._search_entry)
>         toolbar_box.toolbar.insert(search_item, -1)
>
>         self._search_prev = ToolButton('go-previous-paired')
> @@ -440,11 +440,26 @@ class LogActivity(activity.Activity):
>
>     def _search_entry_activate_cb(self, entry):
>         self.viewer.set_search_text(entry.props.text)
> +        # Set an activated color to the search entry
> +        fg_color = gtk.gdk.color_parse('#FFFFB0')
> +        self._search_entry.modify_base(gtk.STATE_ACTIVE, fg_color)
> +        self._search_entry.modify_base(gtk.STATE_NORMAL, fg_color)
>         self._update_search_buttons()
>
>     def _search_entry_changed_cb(self, entry):
> -        self.viewer.set_search_text(entry.props.text)
> -        self._update_search_buttons()
> +        # Remove all highlighted words from the TextView
> +        _buffer = self.viewer._textview.get_buffer()
> +        start, end = _buffer.get_bounds()
> +        _buffer.remove_tag_by_name('search-hilite', start, end)
> +        _buffer.remove_tag_by_name('search-select', start, end)
> +
> +        # Go back to the search entry original colors
> +        bg_color = gtk.gdk.color_parse('#FFFFFF')
> +        fg_color = gtk.gdk.color_parse('#000000')
> +        self._search_entry.modify_base(gtk.STATE_NORMAL, bg_color)
> +        self._search_entry.modify_text(gtk.STATE_NORMAL, fg_color)
> +        self._search_entry.modify_base(gtk.STATE_ACTIVE, bg_color)
> +        self._search_entry.modify_text(gtk.STATE_ACTIVE, fg_color)
>
>     def _search_prev_cb(self, button):
>         self.viewer.search_next('backward')
> @@ -464,6 +479,16 @@ class LogActivity(activity.Activity):
>             self._search_prev.props.sensitive = prev_result != None
>             self._search_next.props.sensitive = next_result != None
>
> +            if prev_result == next_result == None:
> +                # Change the background and foreground color of the
> +                # search entry
> +                bg_color = gtk.gdk.color_parse('#FF6666')
> +                fg_color = gtk.gdk.color_parse('#FFFFFF')
> +                self._search_entry.modify_base(gtk.STATE_ACTIVE, bg_color)
> +                self._search_entry.modify_base(gtk.STATE_NORMAL, bg_color)
> +                self._search_entry.modify_text(gtk.STATE_ACTIVE, fg_color)
> +                self._search_entry.modify_text(gtk.STATE_NORMAL, fg_color)
> +
>     def _delete_log_cb(self, widget):
>         if self.viewer.active_log:
>             logfile = self.viewer.active_log.logfile
> --
> 1.7.9.5
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel



-- 
.. manuq ..


More information about the Sugar-devel mailing list