Example #1
0
    def __init__(self):

        self.column_manager = LineViewColumnManager()
Example #2
0
    def __init__ (self):

        self.column_manager = LineViewColumnManager ()
Example #3
0
class LineView(object):
    def __init__(self):

        self.column_manager = LineViewColumnManager()

    def attach(self, window):

        for action_name, handler in iter_actions(self):
            action = getattr(window.actions, action_name)
            action.connect("activate", handler)

        self.clear_action = window.actions.clear_line_view

        self.line_view = window.widgets.line_view
        self.line_view.connect("row-activated",
                               self.handle_line_view_row_activated)

        ui = window.ui_manager
        self.popup = ui.get_widget(
            "/ui/context/LineViewContextMenu").get_submenu()
        Common.GUI.widget_add_popup_menu(self.line_view, self.popup)

        self.log_view = log_view = window.log_view
        log_view.connect("row-activated", self.handle_log_view_row_activated)
        sel = log_view.get_selection()
        sel.connect("changed", self.handle_log_view_selection_changed)

        self.clear_action.props.sensitive = False
        self.column_manager.attach(window)

    def clear(self):

        model = self.line_view.get_model()

        if len(model) == 0:
            return

        for i in range(1, len(model)):
            model.remove_line(1)

        self.clear_action.props.sensitive = False

    def handle_attach_log_file(self, window):

        self.line_view.set_model(LineViewLogModel(window.log_model))

    def handle_line_view_row_activated(self, view, path, column):

        line_index = path[0]
        line_model = view.get_model()
        log_model = self.log_view.get_model()
        super_index = line_model.line_index_to_super(line_index)
        log_index = log_model.line_index_from_super(super_index)
        path = (log_index, )
        self.log_view.scroll_to_cell(path, use_align=True, row_align=.5)
        sel = self.log_view.get_selection()
        sel.select_path(path)

    def handle_log_view_row_activated(self, view, path, column):

        log_model = view.get_model()
        line_index = path[0]

        super_index = log_model.line_index_to_super(line_index)
        line_model = self.line_view.get_model()
        if line_model is None:
            return

        if len(line_model):
            timestamps = [row[line_model.COL_TIME] for row in line_model]
            row = log_model[(line_index, )]
            position = bisect_right(timestamps, row[line_model.COL_TIME])
        else:
            position = 0
        if len(line_model) > 1:
            other_index = line_model.line_index_to_super(position - 1)
        else:
            other_index = -1
        if other_index == super_index and position != 1:
            # Already have the line.
            pass
        else:
            line_model.insert_line(position, super_index)
            self.clear_action.props.sensitive = True

    def handle_log_view_selection_changed(self, selection):

        line_model = self.line_view.get_model()
        if line_model is None:
            return

        model, tree_iter = selection.get_selected()

        if tree_iter is None:
            return

        path = model.get_path(tree_iter)
        line_index = model.line_index_to_super(path[0])

        if len(line_model) == 0:
            line_model.insert_line(0, line_index)
        else:
            line_model.replace_line(0, line_index)

    @action
    def handle_clear_line_view_action_activate(self, action):

        self.clear()
Example #4
0
class LineView (object):

    def __init__ (self):

        self.column_manager = LineViewColumnManager ()

    def attach (self, window):

        for action_name, handler in iter_actions (self):
            action = getattr (window.actions, action_name)
            action.connect ("activate", handler)

        self.clear_action = window.actions.clear_line_view

        self.line_view = window.widgets.line_view
        self.line_view.connect ("row-activated", self.handle_line_view_row_activated)

        ui = window.ui_manager
        self.popup = ui.get_widget ("/ui/context/LineViewContextMenu").get_submenu ()
        Common.GUI.widget_add_popup_menu (self.line_view, self.popup)

        self.log_view = log_view = window.log_view
        log_view.connect ("row-activated", self.handle_log_view_row_activated)
        sel = log_view.get_selection ()
        sel.connect ("changed", self.handle_log_view_selection_changed)

        self.clear_action.props.sensitive = False
        self.column_manager.attach (window)

    def clear (self):

        model = self.line_view.get_model ()

        if len (model) == 0:
            return

        for i in range (1, len (model)):
            model.remove_line (1)

        self.clear_action.props.sensitive = False

    def handle_attach_log_file (self, window):

        self.line_view.set_model (LineViewLogModel (window.log_model))

    def handle_line_view_row_activated (self, view, path, column):

        line_index = path[0]
        line_model = view.get_model ()
        log_model = self.log_view.get_model ()
        super_index = line_model.line_index_to_super (line_index)
        log_index = log_model.line_index_from_super (super_index)
        path = (log_index,)
        self.log_view.scroll_to_cell (path, use_align = True, row_align = .5)
        sel = self.log_view.get_selection ()
        sel.select_path (path)

    def handle_log_view_row_activated (self, view, path, column):

        log_model = view.get_model ()
        line_index = path[0]

        super_index = log_model.line_index_to_super (line_index)
        line_model = self.line_view.get_model ()
        if line_model is None:
            return

        if len (line_model):
            timestamps = [row[line_model.COL_TIME] for row in line_model]
            row = log_model[(line_index,)]
            position = bisect_right (timestamps, row[line_model.COL_TIME])
        else:
            position = 0
        if len (line_model) > 1:
            other_index = line_model.line_index_to_super (position - 1)
        else:
            other_index = -1
        if other_index == super_index and position != 1:
            # Already have the line.
            pass
        else:
            line_model.insert_line (position, super_index)
            self.clear_action.props.sensitive = True

    def handle_log_view_selection_changed (self, selection):

        line_model = self.line_view.get_model ()
        if line_model is None:
            return

        model, tree_iter = selection.get_selected ()

        if tree_iter is None:
            return

        path = model.get_path (tree_iter)
        line_index = model.line_index_to_super (path[0])

        if len (line_model) == 0:
            line_model.insert_line (0, line_index)
        else:
            line_model.replace_line (0, line_index)

    @action
    def handle_clear_line_view_action_activate (self, action):

        self.clear ()