Exemplo n.º 1
0
 def _set_icon_label(self, icon_info, icon_label):
     image, mime, file_info = icon_info
     pixmap = None
     if image:
         pixmap = QPixmap(self.FILE_LIST_ICON_SIZE,
                          self.FILE_LIST_ICON_SIZE)
         pixmap.convertFromImage(image)
     elif mime:
         icon = self._get_icon(mime)
         if icon:
             pixmap = icon.pixmap(
                 self.FILE_LIST_ICON_SIZE, self.FILE_LIST_ICON_SIZE)
     if not pixmap or pixmap.isNull():
         icon = QFileIconProvider().icon(file_info)
         pixmap = icon.pixmap(
             self.FILE_LIST_ICON_SIZE, self.FILE_LIST_ICON_SIZE)
     if pixmap and not pixmap.isNull():
         icon_label.setPixmap(pixmap)
     icon_label.setScaledContents(True)
     icon_label.setFixedSize(
         self.FILE_LIST_ICON_SIZE, self.FILE_LIST_ICON_SIZE)
     icon_label.setAlignment(Qt.AlignCenter)
Exemplo n.º 2
0
    def set_texture(self, filename):
        # load image
        p = Path(filename)
        suffix = p.suffix[1:].upper()
        try:
            if p.is_file() and suffix in self._supported_images:
                pim = Image.open(filename)
                img = ImageQt(pim)
                self.info = f"{pim.format} - {pim.size} - {pim.mode} "
            else:
                ico = QFileIconProvider().icon(QFileInfo(filename))
                pix = ico.pixmap(256, 256)
                img = pix.toImage()
                self.info = "not an image "
        except UnidentifiedImageError as e:
            print("UnidentifiedImageError:\n", e, flush=True)
            return

        self._texture_size = img.width(), img.height()
        self.__update_scale(self.width(), self.height())

        # create texture
        self.makeCurrent()
        self._texture = QOpenGLTexture(QOpenGLTexture.Target2D)
        self._texture.create()
        self._texture.bind()
        self._texture.setMinMagFilters(QOpenGLTexture.LinearMipMapLinear,
                                       QOpenGLTexture.Linear)
        self._texture.setWrapMode(QOpenGLTexture.DirectionS,
                                  QOpenGLTexture.Repeat)
        self._texture.setWrapMode(QOpenGLTexture.DirectionT,
                                  QOpenGLTexture.Repeat)
        self._texture.setData(img)
        self._texture.release()

        # redraw
        self.update()