From 8108907e5f1fd558423fbbc6fa685c90a5b5689d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Stadler?= Date: Tue, 27 Nov 2007 16:50:41 +0200 Subject: [PATCH] Add ranged line omission feature --- debug-viewer/GstDebugViewer/GUI.py | 104 +++++++++++++++++- .../GstDebugViewer/Plugins/Timeline.py | 28 ++++- debug-viewer/data/gst-debug-viewer.ui | 3 + 3 files changed, 128 insertions(+), 7 deletions(-) diff --git a/debug-viewer/GstDebugViewer/GUI.py b/debug-viewer/GstDebugViewer/GUI.py index bca28725c4..27f713f6f4 100755 --- a/debug-viewer/GstDebugViewer/GUI.py +++ b/debug-viewer/GstDebugViewer/GUI.py @@ -387,10 +387,62 @@ class FilteredLogModel (LogModelBase): self.line_offsets[:] = (offset for row, offset in enum if func (row)) + def parent_line_index (self, line_index): + + return line_index # FIXME + class Filter (object): pass +class SubRange (object): + + def __init__ (self, l, start, end): + + if start > end: + raise ValueError ("need start <= end") + + self.l = l + self.start = start + self.end = end + + def __getitem__ (self, i): + + return self.l[i + self.start] + + def __len__ (self): + + return self.end - self.start + + def __iter__ (self): + + l = self.l + i = self.start + while i <= self.end: + yield l[i] + +class RangeFilteredLogModel (FilteredLogModel): + + def __init__ (self, lazy_log_model): + + FilteredLogModel.__init__ (self, lazy_log_model) + + self.line_index_range = None + + def set_range (self, start_index, last_index): + + self.line_index_range = (start_index, last_index,) + self.line_offsets = SubRange (self.parent_model.line_offsets, + start_index, last_index) + self.line_levels = SubRange (self.parent_model.line_levels, + start_index, last_index) + + def parent_line_index (self, line_index): + + start_index = self.line_index_range[0] + + return line_index + start_index + class DebugLevelFilter (Filter): def __init__ (self, debug_level): @@ -979,10 +1031,14 @@ class Window (object): self.actions.reload_file.props.sensitive = False group = gtk.ActionGroup ("RowActions") - group.add_actions ([("edit-copy-line", gtk.STOCK_COPY, _("Copy line"), "C"), + group.add_actions ([("omit-before-line", None, _("Omit lines before this one")), + ("omit-after-line", None, _("Omit lines after this one")), + ("show-hidden-lines", None, _("Show omitted lines")), + ("edit-copy-line", gtk.STOCK_COPY, _("Copy line"), "C"), ("edit-copy-message", gtk.STOCK_COPY, _("Copy message")), ("filter-out-higher-levels", None, _("Filter out higher debug levels"))]) self.actions.add_group (group) + self.actions.show_hidden_lines.props.sensitive = False self.actions.add_group (self.column_manager.action_group) @@ -1034,6 +1090,7 @@ class Window (object): for action_name in ("new-window", "open-file", "reload-file", "close-window", "cancel-load", + "omit-before-line", "omit-after-line", "show-hidden-lines", "edit-copy-line", "edit-copy-message", "filter-out-higher-levels", "show-about",): @@ -1137,6 +1194,51 @@ class Window (object): self.close () + def handle_omit_after_line_action_activate (self, action): + + first_index = self.log_filter.parent_line_index (0) + try: + filtered_line_index = self.get_active_line_index () + except ValueError: + return + last_index = self.log_filter.parent_line_index (filtered_line_index) + + self.logger.info ("omitting lines after %i (abs %i), first line is abs %i", + filtered_line_index, + last_index, + first_index) + + self.log_filter = RangeFilteredLogModel (self.log_model) + self.log_filter.set_range (first_index, last_index + 1) + self.log_view.props.model = self.log_filter + self.actions.show_hidden_lines.props.sensitive = True + + def handle_omit_before_line_action_activate (self, action): + + try: + filtered_line_index = self.get_active_line_index () + except ValueError: + return + first_index = self.log_filter.parent_line_index (filtered_line_index) + last_index = self.log_filter.parent_line_index (len (self.log_filter) - 1) + + self.logger.info ("omitting lines before %i (abs %i), last line is abs %i", + filtered_line_index, + first_index, + last_index) + + self.log_filter = RangeFilteredLogModel (self.log_model) + self.log_filter.set_range (first_index, last_index) + self.log_view.props.model = self.log_filter + self.actions.show_hidden_lines.props.sensitive = True + + def handle_show_hidden_lines_action_activate (self, action): + + self.logger.info ("restoring model filter to show all lines") + self.log_filter = FilteredLogModel (self.log_model) + self.log_view.props.model = self.log_filter + self.actions.show_hidden_lines.props.sensitive = False + def handle_edit_copy_line_action_activate (self, action): line_index = self.get_active_line_index () diff --git a/debug-viewer/GstDebugViewer/Plugins/Timeline.py b/debug-viewer/GstDebugViewer/Plugins/Timeline.py index 18ef9bd71e..d45a883488 100644 --- a/debug-viewer/GstDebugViewer/Plugins/Timeline.py +++ b/debug-viewer/GstDebugViewer/Plugins/Timeline.py @@ -647,8 +647,14 @@ class TimelineFeature (FeatureBase): action.connect ("toggled", handler) action.props.active = self.state.shown + handler = self.handle_log_view_notify_model + self.notify_model_id = self.log_view.connect ("notify::model", handler) + def handle_detach_window (self, window): + self.log_view.disconnect (self.notify_model_id) + self.log_view = None + window.ui_manager.remove_ui (self.merge_id) self.merge_id = None @@ -659,7 +665,22 @@ class TimelineFeature (FeatureBase): def handle_attach_log_file (self, window, log_file): - model = window.log_filter + pass + + def handle_detach_log_file (self, window, log_file): + + self.timeline.clear () + self.vtimeline.clear () + + def handle_log_view_notify_model (self, view, gparam): + + model = view.props.model + + if model is None: + self.timeline.clear () + self.vtimeline.clear () + return + self.timeline.update (model) # Need to dispatch these idly with a low priority to avoid triggering a @@ -670,11 +691,6 @@ class TimelineFeature (FeatureBase): return False gobject.idle_add (idle_update, priority = gobject.PRIORITY_LOW) - def handle_detach_log_file (self, window, log_file): - - self.timeline.clear () - self.vtimeline.clear () - def update_timeline_position (self): model = self.log_view.props.model diff --git a/debug-viewer/data/gst-debug-viewer.ui b/debug-viewer/data/gst-debug-viewer.ui index 263cebf12c..afcda9e3c1 100644 --- a/debug-viewer/data/gst-debug-viewer.ui +++ b/debug-viewer/data/gst-debug-viewer.ui @@ -24,6 +24,9 @@ + + +