label_header = None
get_modify_func = None
get_data_func = None
+ get_row_data_func = None
get_sort_func = None
def __init__ (self):
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:
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
-
- def message_data_func (props, value, path):
-
- 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
+ highlighters = self.highlighters
+ id_ = self.id
+
+ def message_data_func (props, row):
+
+ 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
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):
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]
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