Ejemplo n.º 1
0
    def load(self, images, positionedImages={}):
        self._scene.clear()
        self._pixmaps = {}

        from PyQt5.QtSvg import QSvgRenderer
        standardPixmapsvg = QSvgRenderer(self)
        standardPixmapsvg.setViewBox(QRect(0, 0, self._width, self._height))
        standardPixmapsvg.load(
            "/usr/share/icons/gnome-human/scalable/status/image-loading.svg")
        self.standardPixmap = QPixmap(self._width, self._height)

        painter = QPainter(self.standardPixmap)
        painter.fillRect(QRect(0, 0, self._width, self._height),
                         QBrush(self.palette().color(self.backgroundRole())))
        standardPixmapsvg.render(painter)

        imagesToLoad = images
        if positionedImages:
            imagesToLoad = positionedImages.keys()

        maxX = maxY = minX = minY = 0

        total = len(imagesToLoad)
        current = 0
        row = 0
        for path in images:
            #QtGui.QMessageBox.warning(None, "Bild", u"{0}".format(path))
            dirname = os.path.dirname(path)
            basename = os.path.basename(path)
            if os.path.isdir(path) or os.path.basename(path).startswith('.'):
                continue

            cachePath = os.path.join(dirname, ".thumbnails/" + basename)
            if os.path.exists(
                    cachePath) and os.stat(cachePath).st_mtime > os.stat(path):
                print('cache hit')
                imagePath = cachePath

            item = QdGraphicsPixmapItem(path, QSize(self._width, self._height))
            if positionedImages and path in positionedImages:
                x, y = positionedImages[path]
            else:
                modresult = current % self._imagesPerRow
                padding = 10
                if modresult == 0:
                    if current > 0:
                        row += 1
                    x = padding
                else:
                    x = padding + modresult * (self._width + padding)
                y = self._height * row
            current += 1
            minX = min(minX, x)
            minY = min(minY, y)
            maxX = max(maxX, x)
            maxY = max(maxY, y)

            #QtGui.QMessageBox.warning(None, "Bild", u"{0}, {1}, {2}".format(path, x, y))

            item.setPos(x, y)
            item.setPixmap(self.standardPixmap)

            self._pixmaps[path] = item
            self._scene.addItem(item)

        self._progressTotal = current
        self._progressCurrent = 0

        paths = list(self._pixmaps.keys())
        paths.sort()

        # load in background thread(s)
        self._loader.load(paths)
        self.setScene(self._scene)