columns: optimize cell data functions a little
This commit is contained in:
parent
a83c471d00
commit
1a4374809b
@ -41,7 +41,6 @@ class Column (object):
|
|||||||
label_header = None
|
label_header = None
|
||||||
get_modify_func = None
|
get_modify_func = None
|
||||||
get_data_func = None
|
get_data_func = None
|
||||||
get_row_data_func = None
|
|
||||||
get_sort_func = None
|
get_sort_func = None
|
||||||
|
|
||||||
def __init__ (self):
|
def __init__ (self):
|
||||||
@ -85,16 +84,10 @@ class TextColumn (SizedColumn):
|
|||||||
id_ = self.id
|
id_ = self.id
|
||||||
if id_ is not None:
|
if id_ is not None:
|
||||||
def cell_data_func (column, cell, model, tree_iter):
|
def cell_data_func (column, cell, model, tree_iter):
|
||||||
data_func (cell.props, model.get_value (tree_iter, id_), model.get_path (tree_iter))
|
data_func (cell.props, model.get_value (tree_iter, id_))
|
||||||
else:
|
else:
|
||||||
cell_data_func = data_func
|
cell_data_func = data_func
|
||||||
column.set_cell_data_func (cell, cell_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:
|
elif not self.get_modify_func:
|
||||||
column.add_attribute (cell, "text", self.id)
|
column.add_attribute (cell, "text", self.id)
|
||||||
else:
|
else:
|
||||||
@ -107,7 +100,7 @@ class TextColumn (SizedColumn):
|
|||||||
modify_func = self.get_modify_func ()
|
modify_func = self.get_modify_func ()
|
||||||
id_ = self.id
|
id_ = self.id
|
||||||
def cell_data_func (column, cell, model, tree_iter):
|
def cell_data_func (column, cell, model, tree_iter):
|
||||||
cell.props.text = modify_func (model.get (tree_iter, id_)[0])
|
cell.props.text = modify_func (model.get_value (tree_iter, id_))
|
||||||
column.set_cell_data_func (cell, cell_data_func)
|
column.set_cell_data_func (cell, cell_data_func)
|
||||||
|
|
||||||
def compute_default_size (self):
|
def compute_default_size (self):
|
||||||
@ -210,7 +203,7 @@ class LevelColumn (TextColumn):
|
|||||||
for c in theme.colors[level])),)
|
for c in theme.colors[level])),)
|
||||||
for level in Data.debug_levels
|
for level in Data.debug_levels
|
||||||
if level != Data.debug_level_none)
|
if level != Data.debug_level_none)
|
||||||
def level_data_func (cell_props, level, path):
|
def level_data_func (cell_props, level):
|
||||||
cell_props.text = level.name[0]
|
cell_props.text = level.name[0]
|
||||||
if level in colors:
|
if level in colors:
|
||||||
cell_colors = colors[level]
|
cell_colors = colors[level]
|
||||||
@ -319,7 +312,7 @@ class MessageColumn (TextColumn):
|
|||||||
|
|
||||||
name = "message"
|
name = "message"
|
||||||
label_header = _("Message")
|
label_header = _("Message")
|
||||||
id = LazyLogModel.COL_MESSAGE
|
id = None
|
||||||
|
|
||||||
def __init__ (self, *a, **kw):
|
def __init__ (self, *a, **kw):
|
||||||
|
|
||||||
@ -327,26 +320,27 @@ class MessageColumn (TextColumn):
|
|||||||
|
|
||||||
TextColumn.__init__ (self, *a, **kw)
|
TextColumn.__init__ (self, *a, **kw)
|
||||||
|
|
||||||
def get_row_data_func (self):
|
def get_data_func (self):
|
||||||
|
|
||||||
highlighters = self.highlighters
|
highlighters = self.highlighters
|
||||||
id_ = self.id
|
id_ = LazyLogModel.COL_MESSAGE
|
||||||
|
|
||||||
def message_data_func (props, row):
|
def message_data_func (column, cell, model, tree_iter):
|
||||||
|
|
||||||
msg = row[id_]
|
msg = model.get_value (tree_iter, id_)
|
||||||
|
|
||||||
if not highlighters:
|
if not highlighters:
|
||||||
props.text = msg
|
cell.props.text = msg
|
||||||
return
|
return
|
||||||
|
|
||||||
if len (highlighters) > 1:
|
if len (highlighters) > 1:
|
||||||
raise NotImplementedError ("FIXME: Support more than one...")
|
raise NotImplementedError ("FIXME: Support more than one...")
|
||||||
|
|
||||||
highlighter = highlighters.values ()[0]
|
highlighter = highlighters.values ()[0]
|
||||||
|
row = model[tree_iter]
|
||||||
ranges = highlighter (row)
|
ranges = highlighter (row)
|
||||||
if not ranges:
|
if not ranges:
|
||||||
props.text = msg
|
cell.props.text = msg
|
||||||
else:
|
else:
|
||||||
tags = []
|
tags = []
|
||||||
prev_end = 0
|
prev_end = 0
|
||||||
@ -360,7 +354,7 @@ class MessageColumn (TextColumn):
|
|||||||
prev_end = end
|
prev_end = end
|
||||||
if end is not None:
|
if end is not None:
|
||||||
tags.append (glib.markup_escape_text (msg[end:]))
|
tags.append (glib.markup_escape_text (msg[end:]))
|
||||||
props.markup = "".join (tags)
|
cell.props.markup = "".join (tags)
|
||||||
|
|
||||||
return message_data_func
|
return message_data_func
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user