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

Manuel Kaufmann humitos at gmail.com
Thu Apr 12 12:19:44 EDT 2012


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 no results for that query the Entry
box is highlighted with red color.

This commit solves: #2734

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 logviewer.py |   32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/logviewer.py b/logviewer.py
index 88fe2e6..8871aa0 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')
@@ -443,8 +443,12 @@ class LogActivity(activity.Activity):
         self._update_search_buttons()
 
     def _search_entry_changed_cb(self, entry):
-        self.viewer.set_search_text(entry.props.text)
-        self._update_search_buttons()
+        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 +468,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 IconEntry (gtk.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



More information about the Sugar-devel mailing list