Example #1
0
    def on_selection_changed(self, _):
        """Called when the user clicks a specific row."""
        node = self.treeview.get_selected_node()
        if node is None:
            return

        if not node.children:
            # It is a single file.
            # Show a chart containing all twins of this file.
            # This is helpful to see quickly where those lie.

            cksum = node[Column.CKSUM]
            group = self.model.trie.group(cksum)

            paths = []
            if len(self.last_paths) > 1:
                paths = self.last_paths[0] + self.last_paths[1]

            group_model = PathTreeModel(paths)

            for twin_node in group or []:
                group_model.add_path(twin_node.build_path(),
                                     twin_node.row,
                                     immediately=True)

            self.group_treeview.set_model(group_model)
            self.group_revealer.show()
            self.group_revealer.get_child().show_all()
            self.group_revealer.set_reveal_child(True)
            self.chart_stack.render(group_model.trie.root)
        else:
            self.group_revealer.hide()
            self.group_revealer.set_reveal_child(False)
            self.chart_stack.render(node)
Example #2
0
    def trigger_run(self, untagged_paths, tagged_paths):
        """Trigger a new run on all paths in `paths`"""
        # Remember last paths for rerun()
        self.reset()
        self.last_paths = (untagged_paths, tagged_paths)

        # Make sure it looks busy:
        self.sub_title = 'Running…'

        # Fork off the rmlint process:
        self.runner = Runner(self.app.settings, untagged_paths, tagged_paths)
        self.runner.connect('lint-added', self.on_add_elem)
        self.runner.connect('process-finished', self.on_process_finish)
        self.runner.run()

        # Make sure the previous run is not visible anymore:
        self.model = PathTreeModel(untagged_paths + tagged_paths)
        self.treeview.set_model(self.model)

        # Indicate that we're in a fresh run:
        self.is_running = True
        self.show_progress(0)
Example #3
0
    def main():
        """Stupid test main"""
        from shredder.tree import PathTreeModel
        model = PathTreeModel(['/home/sahib'])

        def push(size, path):
            """Helper for pushing a dummy path"""
            model.add_path(path, Column.make_row({'size': size}), True)

        push(500, '/home/sahib/docs/stuff.pdf')

        for idx, size in enumerate((700, 600, 200)):
            push(size, '/home/sahib/docs/more/' + 'stuff.pdf-' + str(idx))

        for idx in range(50):
            push(10, '/home/sahib/docs/more/' + 'small.pdf-' + str(idx))

        for idx in range(10):
            push(100, '/home/sahib/' + 'dummy-' + str(idx))

        push(1000, '/home/sahib/music/1.mp3')
        push(1200, '/home/sahib/music/sub/2.mp3')
        push(1200, '/home/sahib/music/sub/3.mp3')
        push(600, '/home/sahib/music/sub/4.mp3')
        model.trie.sort(Column.SIZE)
        print(model.trie)

        area = RingChart()
        area.render(model.trie.root)

        win = Gtk.Window()
        win.set_size_request(300, 500)
        win.connect('destroy', Gtk.main_quit)
        win.add(area)
        win.show_all()

        Gtk.main()
Example #4
0
    def __init__(self, app):
        View.__init__(self, app, 'Running…')

        # Public: The runner.
        self.runner = None

        self.last_paths = []

        # Disable scrolling for the main view:
        self.scw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)

        # Public flag for checking if the view is still
        # in running mode (thus en/disabling certain features)
        self.is_running = False

        self._script_generated = False
        self._is_filtered = False

        self.model = PathTreeModel([])

        self.treeview = PathTreeView()
        self.treeview.set_model(self.model)
        self.treeview.get_selection().connect('changed',
                                              self.on_selection_changed)

        self.group_treeview = PathTreeView()
        self.group_treeview.set_vexpand(True)
        self.group_treeview.set_valign(Gtk.Align.FILL)

        # This is needed to make sure operations on the one update
        # the other. Internally the same nodes are updated, but it has
        # to be made sure that the models get updated.
        self.group_treeview.set_twin(self.treeview)
        self.treeview.set_twin(self.group_treeview)

        group_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        group_box.pack_start(scrolled(self.group_treeview), True, True, 0)
        group_box.pack_start(Gtk.HSeparator(), False, False, 0)

        self.group_revealer = Gtk.Revealer()
        self.group_revealer.set_vexpand(True)
        self.group_revealer.set_valign(Gtk.Align.FILL)
        self.group_revealer.add(group_box)
        self.group_revealer.set_no_show_all(True)
        self.group_revealer.set_size_request(-1, 70)

        for column in self.treeview.get_columns():
            column.connect('clicked', lambda _: self.rerender_chart())

        self.chart_stack = ChartStack()
        self.actionbar = ResultActionBar(self)
        self.actionbar.set_valign(Gtk.Align.END)
        self.actionbar.set_halign(Gtk.Align.FILL)

        # Right part of the view
        stats_box = Gtk.Paned(orientation=Gtk.Orientation.VERTICAL)
        stats_box.pack1(self.group_revealer, True, True)
        stats_box.pack2(self.chart_stack, True, True)
        stats_box.props.position = 200

        # Separator container for separator|chart (could have used grid)
        separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
        right_pane = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        right_pane.pack_start(separator, False, False, 0)
        right_pane.pack_start(stats_box, True, True, 0)
        right_pane.set_size_request(100, -1)

        scw = scrolled(self.treeview)
        scw.set_size_request(200, -1)

        paned = Gtk.Paned(orientation=Gtk.Orientation.HORIZONTAL)
        paned.set_vexpand(True)
        paned.set_valign(Gtk.Align.FILL)
        paned.pack1(scw, True, True)
        paned.pack2(right_pane, True, True)
        paned.props.position = 720
        paned.set_hexpand(True)

        grid = Gtk.Grid()
        grid.attach(paned, 0, 0, 1, 1)
        grid.attach(self.actionbar, 0, 1, 1, 1)

        self.add(grid)

        self.search_entry.connect('search-changed', self.on_search_changed)

        self.actionbar.connect('generate-all-script', self.on_generate_script)
        self.actionbar.connect('generate-filtered-script',
                               self.on_generate_filtered_script)
        self.actionbar.connect('generate-selection-script',
                               self.on_generate_selection_script)

        self._menu = None