Exemple #1
0
    def ensureUniqueFilename(self, name, appendFormat="(%s)"):
        assert('%s' in appendFormat)

        info = QFileInfo(name)
        if not info.exists():
            return name

        # QDir
        dir_ = info.absoluteDir()
        # QString
        fileName = info.fileName()

        idx = 1
        while info.exists():
            file_ = fileName
            index = file_.rfind('.')
            appendString = appendFormat % idx
            if index == -1:
                file_ += appendString
            else:
                file_ = file_[:index] + appendString + file_[index:]
            info.setFile(dir_, file_)
            idx += 1

        return info.absoluteFilePath()
Exemple #2
0
    def iconFromFileName(self, fileName):
        '''
        @param: fileName QString
        @return: QIcon
        '''
        tempInfo = QFileInfo(fileName)
        suffix = tempInfo.suffix()
        if suffix in self._s_iconCache:
            return self._s_iconCache[suffix]

        iconProvider = QFileIconProvider()
        tempFile = DataPaths.path(DataPaths.Temp) + '/XXXXXX.' + suffix
        tempFile.open()
        tempInfo.setFile(tempFile.fileName())

        icon = QIcon(iconProvider.icon(tempInfo))
        self._s_iconCache[suffix] = icon