Example #1
0
    def main():
        """Show a window with the dupe-contents of a user specified path."""
        import sys

        model = PathTreeModel(sys.argv[1:])
        for arg_path in sys.argv[1:]:
            model.add_path(arg_path,
                           Column.make_row({
                               'mtime': time.time(),
                               'size': 0
                           }))

        from shredder.runner import Runner
        settings = Gio.Settings.new('org.gnome.Shredder')

        runner = Runner(settings, sys.argv[1:], [])
        runner.connect(
            'lint-added', lambda *_: model.add_path(
                runner.element['path'], Column.make_row(runner.element)))

        runner.connect('process-finished',
                       lambda _, msg: print('Status:', msg))
        runner.run()

        view = PathTreeView()
        view.set_model(model)

        runner.connect('process-finished',
                       lambda _, msg: GLib.timeout_add(500, view.expand_all))

        runner.connect(
            'process-finished',
            lambda *_: GLib.timeout_add(500, lambda: model.sort(Column.SIZE)))
        runner.connect(
            'process-finished',
            lambda *_: GLib.timeout_add(600, lambda: print(model.trie)))

        def _search_changed(entry):
            view.set_model(model.filter_model(entry.get_text()))
            view.expand_all()

        entry = Gtk.SearchEntry()
        entry.connect('search-changed', _search_changed)

        scw = Gtk.ScrolledWindow()
        scw.add(view)

        win = Gtk.Window()
        win.set_default_size(640, 480)
        win.connect('destroy', Gtk.main_quit)

        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        box.pack_start(scw, True, True, 0)
        box.pack_start(entry, False, False, 0)

        win.add(box)
        win.show_all()

        Gtk.main()
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)