예제 #1
0
 def rebuild_rects(self, file):
     delete_widget(self.tree_map_widget)
     file.build(
         Rectangle(0, 0, self.width - self.width * 0.005,
                   self.height - self.height * 0.205, self.file), 1,
         self.max_level, 100)
     self.tree_map_widget = TreeMapWidget(self, file, self.max_level,
                                          self.width, self.height)
예제 #2
0
파일: file.py 프로젝트: Scopee/DiskUsage
 def __init__(self, path, level, exclude, mask):
     path = path if path[-1] != '/' else path[:-1]
     self.level = level
     self.path = path
     self.percent = 100
     try:
         self.dirs, self.files = _build_graph(path, level, exclude, mask)
         self.size = self._get_size()
         self.ext = os.path.splitext(self.path)[1]
     except (OSError, PermissionError):
         self.dirs = []
         self.files = []
         self.size = 0.0
         self.ext = ""
     self.rect = Rectangle(0, 0, 0, 0, self)
     self.rects = []
예제 #3
0
파일: file.py 프로젝트: Scopee/DiskUsage
 def build(self, rect, level, max_level, percent):
     self.rect = rect
     self.percent = round(percent, 2)
     childs = sorted(list(itertools.chain(self.dirs, self.files)),
                     key=lambda x: x.size, reverse=True)
     values = sorted(map(lambda x: x.size or 0.1, childs), reverse=True)
     values = squarify.normalize_sizes(values, self.rect.width,
                                       self.rect.height)
     rects = squarify.squarify(values, rect.x, rect.y, rect.width,
                               rect.height)
     for (rect, child) in zip(rects, childs):
         child.build(
             Rectangle(rect['x'], rect['y'], rect['dx'],
                       rect['dy'], child, self.rect),
             level + 1, max_level,
             child.size / (self.size or 0.1) * 100)
     self.rects = self.rectangles(level, max_level)
예제 #4
0
 def resizeEvent(self, e):
     self.width = e.size().width()
     self.height = e.size().height()
     if self.tree_map_widget is not None:
         delete_widget(self.tree_map_widget)
     self.file.build(
         Rectangle(0, 0, self.width - self.width * 0.005,
                   self.height - self.height * 0.205, self.file), 1,
         self.max_level, 100)
     self.tree_map_widget = TreeMapWidget(self, self.file, self.max_level,
                                          self.width, self.height)
     if self.list_widget is not None:
         delete_widget(self.list_widget)
     self.list_widget = ColorListWidget(self, self.width, self.height)
     if self.tree_widget is not None:
         delete_widget(self.tree_widget)
     self.tree_widget = DirsWidget(self, self.width, self.height, self.file)
     self.tree_widget.set_tree(self.create_tree_item(self.tree_widget))
     super(MainWidget, self).resizeEvent(e)
예제 #5
0
 def test_many_files(self):
     for i in range(15):
         for j in range(15):
             os.makedirs(f'/test/dir{i}/dir{j}')
             for k in range(15):
                 with open(f'/test/dir{i}/dir{j}/file{k}.mp{k % 3}',
                           'w') as f:
                     f.write('0' * k)
     f = File('/test', float('inf'), [], '*')
     self.assertEqual(15, len(f.dirs))
     for i in range(15):
         self.assertEqual(15, len(f.dirs[i].dirs))
         for j in range(15):
             self.assertEqual(15, len(f.dirs[i].dirs[j].files))
             self.assertEqual(0, len(f.dirs[i].dirs[j].dirs))
             for k in range(15):
                 self.assertEqual(
                     os.path.getsize(
                         f'/test/dir{i}/dir{j}/file{k}.mp{k % 3}'),
                     f.dirs[i].dirs[j].files[k].size)
     f.build(Rectangle(0, 0, 1, 1, f), 1, float('inf'), 100)
예제 #6
0
    def __init__(self, file, width, height, max_level):
        super().__init__()
        self.width = width
        self.height = height
        self.file = file
        self.file.build(
            Rectangle(0, 0, self.width - self.width * 0.005,
                      self.height - self.height * 0.205, self.file), 1,
            max_level, 100)
        self.file.rectangles(1, max_level)
        self.widget = MainWidget(self, self.file, max_level, self.width,
                                 self.height)
        self.widget.show()

        act = QAction('Up', self)
        act.setShortcut('Ctrl+Z')
        act.triggered.connect(self.widget.key_pressed)
        self.toolbar = self.addToolBar('Exit')
        self.toolbar.addAction(act)
        self.height = self.toolbar.actionGeometry(act).height()
        self.setGeometry(0, 0, width, height)
        self.show()
예제 #7
0
 def test_rects(self):
     f = File("/home/x", 1, [], '*')
     f.build(Rectangle(0, 0, 1, 1, f), 1, float('inf'), 100)
     self.assertEqual(5, len(f.rectangles(1, 100)))