From 89f8ebe0cf024c15faa64d45e2049211a1e67096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Stadler?= Date: Mon, 3 Dec 2007 12:18:23 +0200 Subject: [PATCH] Implement lazy highlighting of search results --- debug-viewer/GstDebugViewer/GUI.py | 37 ++++++++++++------- .../GstDebugViewer/Plugins/FindBar.py | 19 +++++++--- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/debug-viewer/GstDebugViewer/GUI.py b/debug-viewer/GstDebugViewer/GUI.py index 4a5b78a0c1..87a9a0cd0b 100755 --- a/debug-viewer/GstDebugViewer/GUI.py +++ b/debug-viewer/GstDebugViewer/GUI.py @@ -516,6 +516,7 @@ class Column (object): label_header = None get_modify_func = None get_data_func = None + get_row_data_func = None get_sort_func = None def __init__ (self): @@ -563,6 +564,12 @@ class TextColumn (SizedColumn): else: cell_data_func = data_func column.set_cell_data_func (cell, cell_data_func) + elif self.get_row_data_func: + data_func = self.get_row_data_func () + assert data_func + def cell_data_func (column, cell, model, tree_iter): + data_func (cell.props, model[tree_iter]) + column.set_cell_data_func (cell, cell_data_func) elif not self.get_modify_func: column.add_attribute (cell, "text", self.id) else: @@ -765,27 +772,29 @@ class MessageColumn (TextColumn): def __init__ (self, *a, **kw): - self.highlight = {} + self.highlighters = {} TextColumn.__init__ (self, *a, **kw) - def get_data_func (self): + def get_row_data_func (self): from pango import AttrList, AttrBackground, AttrForeground - highlight = self.highlight + highlighters = self.highlighters + id_ = self.id - def message_data_func (props, value, path): + def message_data_func (props, row): - line_index = path[0] - props.text = value - if line_index in highlight: - start, end = highlight[line_index] - attrlist = AttrList () - attrlist.insert (AttrBackground (0, 0, 65535, start, end)) - attrlist.insert (AttrForeground (65535, 65535, 65535, start, end)) - props.attributes = attrlist - else: - props.attributes = None + props.text = row[id_] + for highlighter in highlighters.values (): + ranges = highlighter (row) + if not ranges: + props.attributes = None + else: + attrlist = AttrList () + for start, end in ranges: + attrlist.insert (AttrBackground (0, 0, 65535, start, end)) + attrlist.insert (AttrForeground (65535, 65535, 65535, start, end)) + props.attributes = attrlist return message_data_func diff --git a/debug-viewer/GstDebugViewer/Plugins/FindBar.py b/debug-viewer/GstDebugViewer/Plugins/FindBar.py index b26aafbd05..7f2979b6dd 100644 --- a/debug-viewer/GstDebugViewer/Plugins/FindBar.py +++ b/debug-viewer/GstDebugViewer/Plugins/FindBar.py @@ -220,6 +220,11 @@ class FindBarFeature (FeatureBase): self.bar.show () self.bar.entry.grab_focus () else: + try: + column = self.window.column_manager.find_item (name = "message") + del column.highlighters[self] + except KeyError: + pass self.bar.hide () def handle_goto_previous_search_result_action_activate (self, action): @@ -270,6 +275,9 @@ class FindBarFeature (FeatureBase): self.operation = SearchOperation (model, search_string, start_position = start_path[0]) self.sentinel.run_for (self.operation) + column = self.window.column_manager.find_item (name = "message") + column.highlighters[self] = self.operation.match_func + def handle_match_found (self, model, tree_iter): line_index = model.get_path (tree_iter)[0] @@ -307,19 +315,20 @@ class FindBarFeature (FeatureBase): start_path, end_path = self.log_view.get_visible_range () start_index, end_index = start_path[0], end_path[0] + # Update highlighting. FIXME: Probably not needed/can be done better. for line_index in new_matches: path = (line_index,) tree_iter = model.get_iter (path) - row = model[tree_iter] - ranges = match_func (row) - column.highlight[line_index] = ranges[0] if line_index >= start_index and line_index <= end_index: model.row_changed (path, tree_iter) def clear_results (self): - column = self.window.column_manager.find_item (name = "message") - column.highlight.clear () + try: + column = self.window.column_manager.find_item (name = "message") + del column.highlighters[self] + except KeyError: + pass model = self.log_view.props.model