Add new base time feature

The log view context menu gains a new action "Set base time", which changes the
time column to show the delta to the selected row.
This commit is contained in:
René Stadler 2009-10-16 21:45:29 +03:00 committed by Stefan Sauer
parent d71d09759b
commit 097cacebbd
4 changed files with 60 additions and 14 deletions

View file

@ -35,6 +35,20 @@ def time_args (ts):
secs % 60, secs % 60,
ts % SECOND,) ts % SECOND,)
def time_diff_args (time_diff):
if time_diff >= 0:
sign = "+"
else:
sign = "-"
secs = abs (time_diff) // SECOND
return "%s%02i:%02i.%09i" % (sign,
secs // 60,
secs % 60,
abs (time_diff) % SECOND,)
def time_args_no_hours (ts): def time_args_no_hours (ts):
secs = ts // SECOND secs = ts // SECOND

View file

@ -96,14 +96,18 @@ class TextColumn (SizedColumn):
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:
modify_func = self.get_modify_func () self.update_modify_func (column, cell)
id_ = self.id
def cell_data_func (column, cell, model, tree_iter):
cell.props.text = modify_func (model.get (tree_iter, id_)[0])
column.set_cell_data_func (cell, cell_data_func)
column.props.resizable = True column.props.resizable = True
def update_modify_func (self, column, cell):
modify_func = self.get_modify_func ()
id_ = self.id
def cell_data_func (column, cell, model, tree_iter):
cell.props.text = modify_func (model.get (tree_iter, id_)[0])
column.set_cell_data_func (cell, cell_data_func)
def compute_default_size (self, view, model): def compute_default_size (self, view, model):
values = self.get_values_for_size () values = self.get_values_for_size ()
@ -137,15 +141,27 @@ class TimeColumn (TextColumn):
id = LazyLogModel.COL_TIME id = LazyLogModel.COL_TIME
font_family = "monospace" font_family = "monospace"
@staticmethod def __init__ (self, *a, **kw):
def get_modify_func ():
time_args = Data.time_args self.base_time = 0
def format_time (value):
# TODO: This is hard coded to omit hours as well as the last 3 TextColumn.__init__ (self, *a, **kw)
# digits at the end, since current gst uses g_get_current_time,
# which has microsecond precision only. def get_modify_func (self):
return time_args (value)[2:-3]
if self.base_time:
time_diff_args = Data.time_diff_args
base_time = self.base_time
def format_time (value):
# TODO: Hard coded to omit trailing zeroes, see below.
return time_diff_args (value - base_time)[:-3]
else:
time_args = Data.time_args
def format_time (value):
# TODO: This is hard coded to omit hours as well as the last 3
# digits at the end, since current gst uses g_get_current_time,
# which has microsecond precision only.
return time_args (value)[2:-3]
return format_time return format_time
@ -155,6 +171,14 @@ class TimeColumn (TextColumn):
return values return values
def set_base_time (self, base_time):
self.base_time = base_time
column = self.view_column
cell = column.get_cell_renderers ()[0]
self.update_modify_func (column, cell)
class LevelColumn (TextColumn): class LevelColumn (TextColumn):
name = "level" name = "level"

View file

@ -225,6 +225,7 @@ class Window (object):
("show-hidden-lines", None, _("Show hidden lines")), ("show-hidden-lines", None, _("Show hidden lines")),
("edit-copy-line", gtk.STOCK_COPY, _("Copy line"), "<Ctrl>C"), ("edit-copy-line", gtk.STOCK_COPY, _("Copy line"), "<Ctrl>C"),
("edit-copy-message", gtk.STOCK_COPY, _("Copy message"), ""), ("edit-copy-message", gtk.STOCK_COPY, _("Copy message"), ""),
("set-base-time", None, _("Set base time")),
("hide-log-level", None, _("Hide log level")), ("hide-log-level", None, _("Hide log level")),
("hide-log-category", None, _("Hide log category")), ("hide-log-category", None, _("Hide log category")),
("hide-log-object", None, _("Hide object")), ("hide-log-object", None, _("Hide object")),
@ -292,7 +293,7 @@ class Window (object):
for action_name in ("new-window", "open-file", "reload-file", for action_name in ("new-window", "open-file", "reload-file",
"close-window", "cancel-load", "close-window", "cancel-load",
"hide-before-line", "hide-after-line", "show-hidden-lines", "hide-before-line", "hide-after-line", "show-hidden-lines",
"edit-copy-line", "edit-copy-message", "edit-copy-line", "edit-copy-message", "set-base-time",
"hide-log-level", "hide-log-category", "hide-log-object", "hide-log-level", "hide-log-category", "hide-log-object",
"hide-filename", "show-about",): "hide-filename", "show-about",):
name = action_name.replace ("-", "_") name = action_name.replace ("-", "_")
@ -627,6 +628,12 @@ class Window (object):
self.actions.show_hidden_lines.props.sensitive = True self.actions.show_hidden_lines.props.sensitive = True
def handle_set_base_time_action_activate (self, action):
row = self.get_active_line ()
time_column = self.column_manager.find_item (name = "time")
time_column.set_base_time (row[LogModelBase.COL_TIME])
def handle_hide_log_level_action_activate (self, action): def handle_hide_log_level_action_activate (self, action):
row = self.get_active_line () row = self.get_active_line ()

View file

@ -55,6 +55,7 @@
</menu> </menu>
<placeholder name="LogViewContextMenuAdditions"/> <placeholder name="LogViewContextMenuAdditions"/>
<separator/> <separator/>
<menuitem name="ViewContextMenuSetBaseTime" action="set-base-time"/>
<menuitem name="ViewContextMenuHideLevel" action="hide-log-level"/> <menuitem name="ViewContextMenuHideLevel" action="hide-log-level"/>
<menuitem name="ViewContextMenuHideCategory" action="hide-log-category"/> <menuitem name="ViewContextMenuHideCategory" action="hide-log-category"/>
<menuitem name="ViewContextMenuHideObject" action="hide-log-object"/> <menuitem name="ViewContextMenuHideObject" action="hide-log-object"/>