def layoutRow(self, rect, scale, row):
        # [TODO]
        if len(row) == 0:
            return rect

        if rect.width() > rect.height():
            dir = 'Horizontal'
        else:
            dir = 'Vertical'

        primary = max(rect.width(), rect.height())

        sum = row.sumTotalSizes()
        secondary = int(sum * (1.0 * scale) / primary)

        if sum == 0:  # Prevent division by zero.
            return rect

        if secondary < self._parentView.minTileSize(
        ):  # We don't want tiles that small.
            return rect

        offset = 0
        remaining = primary

        for fileInfo in row:
            childSize = int((1.0 * fileInfo.totalSize()) /
                            (1.0 * sum) * primary + 0.5)
            if childSize > remaining:  # Prevent overflow because of accumulated rounding errors
                childSize = remaining

            remaining -= childSize

            if childSize >= self._parentView.minTileSize():
                if dir == 'Horizontal':
                    childRect = Rect(Point(rect.x() + offset, rect.y()),
                                     Size(childSize, secondary))
                else:
                    childRect = Rect(Point(rect.x(),
                                           rect.y() + offset),
                                     Size(secondary, childSize))

                tile = TreemapTile(self._parentView,
                                   self,
                                   fileInfo,
                                   childRect,
                                   orientation='Auto')
                # What should I do with the tile ?
                offset += childSize

        if (dir == 'Horizontal'):
            newRect = Rect(Point(rect.x(),
                                 rect.y() + secondary),
                           Size(rect.width(),
                                rect.height() - secondary))
        else:
            newRect = Rect(Point(rect.x() + secondary, rect.y()),
                           Size(rect.width() - secondary, rect.height()))

        return newRect
Beispiel #2
0
    def rebuildTreemap( self, newRoot=None, newSize=None ):
        needtoclean_savedRootUrl = False
        if not newRoot :
            (newRoot,newSize) = self._getparam_rebuildTreemap()
            needtoclean_savedRootUrl = True

        if not newSize :
            newSize = self.visibleSize()

        self._selectedTile  = None;
        self._selectionRect = None;
        self._rootTile      = None;

        self.canvas().resize( newSize.width(), newSize.height() )

        if newSize.width() >= UpdateMinSize and newSize.height() >= UpdateMinSize  :
            if newRoot :
                self._rootTile = TreemapTile(
                    self,       # parentView
                    None,       # parentTile
                    newRoot,    # orig
                    Rect( point=Point(0, 0), size=newSize ),
                    'Auto' )

        # if self._tree.selection() :
        #     self.selectTile( self._tree.selection() )

        if needtoclean_savedRootUrl :
            self._savedRootUrl = ""
Beispiel #3
0
 def __init__( self, parentView, parentTile, orig, rect, orientation = 'Auto' ) :
     self._rect       = Rect(rect=rect)
     self._parentView = parentView
     self._parentTile = parentTile
     self._orig       = orig
     self._init()
     self._parentView.addTileToDraw(self)
     self.createChildren( rect, orientation )
    def createChildrenSimple(self, rect, orientation):
        dir = orientation
        childDir = orientation

        if dir == 'Auto':
            if rect.width() > rect.height():
                dir = 'Horizontal'
            else:
                dir = 'Vertical'

        if orientation == 'Horizontal': childDir = 'Vertical'
        if orientation == 'Vertical': childDir = 'Horizontal'

        offset = 0
        size = {'Horizontal': rect.width(), 'Vertical': rect.height()}[dir]
        # count    = 0
        scale = (1.0 * size) / (1.0 * self._orig.totalSize())

        fileInfoList = FileInfoList(self._orig,
                                    minSize=self._parentView.minTileSize() /
                                    scale,
                                    bySize=True,
                                    param='AsSubDir')

        # KFileInfoSortedBySizeIterator it( _orig,
        #                               (KFileSize) ( _parentView->minTileSize() / scale ),
        #                               KDotEntryAsSubDir );

        for fileInfo in fileInfoList:
            childSize = fileInfo.totalSize()
            if childSize >= self._parentView.minTileSize():
                if dir == 'Horizontal':
                    childRect = Rect(point=Point(rect.x() + offset, rect.y()),
                                     size=Size(childSize, rect.height()))
                else:
                    childRect = Rect(point=Point(rect.x(),
                                                 rect.y() + offset),
                                     size=Size(rect.width(), childSize))

                tile = TreemapTile(self._parentView, self, fileInfo, childRect,
                                   childDir)

                offset += childSize
 def __init__(self,
              parentView,
              parentTile,
              fileinfo,
              rect,
              orientation='Auto'):
     """Constructor"""
     self._rect = Rect(rect=rect)
     # parentView is a TreemapView
     self._parentView = parentView
     self._parentTile = parentTile
     self._fileinfo = fileinfo
     self._init()
     self._parentView.addTileToDraw(self)
     self.createChildren(rect, orientation)
Beispiel #6
0
    def createSquarifiedChildren( self, rect ) :
        if self._orig.totalSize() == 0 :
            return
        scale   = (1.0*rect.width()) * (1.0*rect.height()) / (1.0*self._orig.totalSize())
        minSize = int( self._parentView.minTileSize() / scale )

        fileInfoList = FileInfoList( self._orig, minSize=minSize, bySize=True, param='AsSubDir' )

        fileInfoListIterator = iter(fileInfoList)
        childrenRect = Rect(rect=rect)

        fileInfoListIterator.next_nofail()

        while fileInfoListIterator.isValid() :
            #fileInfoListIterator.next_nofail()
            row = self.squarify( childrenRect, scale, fileInfoListIterator )
            # print "  %s" % map(lambda x:x.name(),row._list)
            childrenRect = self.layoutRow( childrenRect, scale, row )
    def rebuildTreemap(self, newRoot, newSize=None):
        """Build/Rebuild the tree."""
        if not newSize:
            newSize = self.visibleSize()

        self._selectedTile = None
        self._selectionRect = None
        self._rootTile = None

        self.canvas().resize(newSize.width(), newSize.height())

        if newSize.width() >= UpdateMinSize and newSize.height(
        ) >= UpdateMinSize:
            if newRoot:
                self._rootTile = TreemapTile(
                    self,  # parentView
                    None,  # parentTile
                    newRoot,  # fileinfo
                    Rect(point=Point(0, 0), size=newSize),
                    'Auto')
    def createSquarifiedChildren(self, rect):
        """This method create the tile, and if needed the sub tiles using the squarification algo from KDirStat."""
        if self._fileinfo.totalArea() == 0:
            return
        scale = (1.0 * rect.width()) * (1.0 * rect.height()) / (
            1.0 * self._fileinfo.totalArea())
        minSize = int(self._parentView.minTileSize() / scale)

        fileInfoList = FileInfoList(self._fileinfo,
                                    minSize=minSize,
                                    bySize=True,
                                    param='AsSubDir')

        fileInfoListIterator = iter(fileInfoList)
        childrenRect = Rect(rect=rect)

        fileInfoListIterator.next_nofail()

        while fileInfoListIterator.isValid():
            #fileInfoListIterator.next_nofail()
            row = self.squarify(childrenRect, scale, fileInfoListIterator)
            # print "  %s" % map(lambda x:x.name(),row._list)
            childrenRect = self.layoutRow(childrenRect, scale, row)