当前位置: 首页>>代码示例>>Python>>正文


Python QFileInfo.suffix方法代码示例

本文整理汇总了Python中PyQt5.QtCore.QFileInfo.suffix方法的典型用法代码示例。如果您正苦于以下问题:Python QFileInfo.suffix方法的具体用法?Python QFileInfo.suffix怎么用?Python QFileInfo.suffix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtCore.QFileInfo的用法示例。


在下文中一共展示了QFileInfo.suffix方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __saveFileName

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
 def __saveFileName(self, directory):
     """
     Private method to calculate a name for the file to download.
     
     @param directory name of the directory to store the file into (string)
     @return proposed filename and original filename (string, string)
     """
     path = parseContentDisposition(self.__reply)
     info = QFileInfo(path)
     baseName = info.completeBaseName()
     endName = info.suffix()
     
     origName = baseName
     if endName:
         origName += '.' + endName
     
     name = directory + baseName
     if endName:
         name += '.' + endName
         if not self.__requestFilename:
             # do not overwrite, if the user is not being asked
             i = 1
             while QFile.exists(name):
                 # file exists already, don't overwrite
                 name = directory + baseName + ('-{0:d}'.format(i))
                 if endName:
                     name += '.' + endName
                 i += 1
     return name, origName
开发者ID:pycom,项目名称:EricShort,代码行数:31,代码来源:DownloadItem.py

示例2: FileBasedTextStream

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
class FileBasedTextStream(QTextStream):
    def __init__(self, qfile):
        super().__init__(qfile)
        self.saved_file = qfile
        self.qfi = None # may never need this
    def rewind(self):
        self.flush()
        self.seek(0)
    def writeLine(self, str):
        self << str
        self << '\n'
    def open_mode(self):
        return self.saved_file.openMode()
    def fullpath(self):
        if self.qfi is None:
            self.qfi = QFileInfo(self.saved_file)
        return self.qfi.canonicalFilePath()
    def folderpath(self):
        if self.qfi is None:
            self.qfi = QFileInfo(self.saved_file)
        return self.qfi.canonicalPath()
    def filename(self):
        if self.qfi is None:
            self.qfi = QFileInfo(self.saved_file)
        return self.qfi.fileName()
    def basename(self):
        if self.qfi is None:
            self.qfi = QFileInfo(self.saved_file)
        return self.qfi.completeBaseName()
    def suffix(self):
        if self.qfi is None:
            self.qfi = QFileInfo(self.saved_file)
        return self.qfi.suffix()
开发者ID:B-Rich,项目名称:PPQT2,代码行数:35,代码来源:utilities.py

示例3: set_mode_by_filename

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
    def set_mode_by_filename(self, filename):
        file = QFile(filename)
        fileinfo = QFileInfo(file)

        suffix = fileinfo.suffix()
        self.page().mainFrame().evaluateJavaScript("editor.getSession().setMode('%s');" % (
            self.SUFIX_2_MODE[suffix] if suffix in self.SUFIX_2_MODE else self.SUFIX_2_MODE[None]
        ))
开发者ID:gitter-badger,项目名称:cetech,代码行数:10,代码来源:scripteditor.py

示例4: add_song

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
 def add_song(self, song_path):
     if song_path.split(".")[-1] not in ["mp3", "flac", "ogg"]:
         raise AssertionError
     song = self.path_to_song(song_path)
     filepath = song.path
     fileInfo = QFileInfo(filepath)
     if fileInfo.exists():
         url = QUrl.fromLocalFile(fileInfo.absoluteFilePath())
         if fileInfo.suffix().lower() == "mp3" or "flac" or "ogg":
             self.playlist.addMedia(QMediaContent(url))
             self.songs.append(song)
开发者ID:eevlogieva,项目名称:letTheMusicPlaY,代码行数:13,代码来源:playlist_wrapper.py

示例5: show

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
 def show(self):
     """
     Public slot to show this dialog.
     
     This overloaded slot loads a UI file to be previewed after
     the main window has been shown. This way, previewing a dialog
     doesn't interfere with showing the main window.
     """
     super(TRPreviewer, self).show()
     if self.filesToLoad:
         filenames, self.filesToLoad = (self.filesToLoad[:], [])
         first = True
         for fn in filenames:
             fi = QFileInfo(fn)
             if fi.suffix().lower() == 'ui':
                 self.preview.loadWidget(fn)
             elif fi.suffix().lower() == 'qm':
                 self.translations.add(fn, first)
                 first = False
         
         self.__updateActions()
开发者ID:pycom,项目名称:EricShort,代码行数:23,代码来源:TRPreviewer.py

示例6: checkFiles

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
    def checkFiles(self, lst):
        f = QFileInfo()
        newLst = []
        for url in lst:
            _file = url.toLocalFile()
            print("FILE::", url, _file)
            f.setFile(_file)
            if f.suffix() not in ("tar", "exe", "mp3", "mp4", "flv", "zip", "rar", "iso"):
                newLst.append(_file)

        if newLst:
            self.openFiles.emit(newLst)
开发者ID:Salmista-94,项目名称:Ninja_3.0_PyQt5,代码行数:14,代码来源:start_page.py

示例7: addToPlaylist

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
 def addToPlaylist(self, fileNames):
     for name in fileNames:
         fileInfo = QFileInfo(name)
         if fileInfo.exists():
             url = QUrl.fromLocalFile(fileInfo.absoluteFilePath())
             if fileInfo.suffix().lower() == 'm3u':
                 self.playlist.load(url)
             else:
                 self.playlist.addMedia(QMediaContent(url))
         else:
             url = QUrl(name)
             if url.isValid():
                 self.playlist.addMedia(QMediaContent(url))
开发者ID:heylenz,项目名称:python27,代码行数:15,代码来源:player.py

示例8: _load_audio

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
    def _load_audio(self):
        filename = os.path.join(self.audio_path, "{:03}.mp3".format(self._song_number))
        self.playlist.clear()
        fileInfo = QFileInfo(filename)
        if fileInfo.exists():
            url = QUrl.fromLocalFile(fileInfo.absoluteFilePath())
            if fileInfo.suffix().lower() == 'm3u':
                self.playlist.load(url)
            else:
                self.playlist.addMedia(QMediaContent(url))
                self._loading_audio = True

            self.player.play()
开发者ID:maccesch,项目名称:songscreen,代码行数:15,代码来源:player.py

示例9: on_load

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
            def on_load():
                file = QFile(filename)
                fileinfo = QFileInfo(file)

                file.open(QFile.ReadOnly)
                data = file.readAll()
                codec = QTextCodec.codecForUtfText(data)
                unistr = codec.toUnicode(data)

                self.page().mainFrame().findFirstElement("#editor").setInnerXml(unistr)
                self.page().mainFrame().evaluateJavaScript("init()")

                suffix = fileinfo.suffix()
                self.page().mainFrame().evaluateJavaScript("editor.getSession().setMode('%s');" % (
                    self.SUFIX_2_MODE[suffix] if suffix in self.SUFIX_2_MODE else self.SUFIX_2_MODE[None]
                ))
开发者ID:gitter-badger,项目名称:cetech,代码行数:18,代码来源:scripteditor.py

示例10: __saveFileName

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
 def __saveFileName(self, directory):
     """
     Private method to calculate a name for the file to download.
     
     @param directory name of the directory to store the file into (string)
     @return proposed filename and original filename (string, string)
     """
     path = ""
     if self.__reply.hasRawHeader("Content-Disposition"):
         header = bytes(self.__reply.rawHeader("Content-Disposition"))\
             .decode()
         if header:
             pos = header.find("filename=")
             if pos != -1:
                 path = header[pos + 9:]
                 if path.startswith('"') and path.endswith('"'):
                     path = path[1:-1]
     if not path:
         path = self.__url.path()
     
     info = QFileInfo(path)
     baseName = info.completeBaseName()
     endName = info.suffix()
     
     if not baseName:
         baseName = "unnamed_download"
     
     origName = baseName
     if endName:
         origName += '.' + endName
     
     name = directory + baseName
     if endName:
         name += '.' + endName
         if not self.__requestFilename:
             # do not overwrite, if the user is not being asked
             i = 1
             while QFile.exists(name):
                 # file exists already, don't overwrite
                 name = directory + baseName + ('-{0:d}'.format(i))
                 if endName:
                     name += '.' + endName
                 i += 1
     return name, origName
开发者ID:Darriall,项目名称:eric,代码行数:46,代码来源:DownloadItem.py

示例11: FileBasedTextStream

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
class FileBasedTextStream(QTextStream):
    def __init__(self, qfile):
        super().__init__(qfile)
        self.saved_file = qfile
        self.qfi = None # may never need this
    def rewind(self):
        self.flush()
        self.seek(0)
    def writeLine(self, str):
        self << str
        self << '\n'
    def open_mode(self):
        return self.saved_file.openMode()
    def fullpath(self):
        if self.qfi is None:
            self.qfi = QFileInfo(self.saved_file)
        return self.qfi.canonicalFilePath()
    def folderpath(self):
        if self.qfi is None:
            self.qfi = QFileInfo(self.saved_file)
        return self.qfi.canonicalPath()
    def filename(self):
        if self.qfi is None:
            self.qfi = QFileInfo(self.saved_file)
        return self.qfi.fileName()
    def basename(self):
        if self.qfi is None:
            self.qfi = QFileInfo(self.saved_file)
        return self.qfi.completeBaseName()
    def suffix(self):
        if self.qfi is None:
            self.qfi = QFileInfo(self.saved_file)
        return self.qfi.suffix()
    def flush(self):
        super().flush() # make sure text buffer goes to device
        return self.device().flush() # do a real flush
    def show_error( self, action, parent ):
        error_number = self.device().error()
        if error_number : # is not 0, no error
            error_string = self.device().errorString()
            msg_string = 'Error {} ({}) on {}'.format(
                error_number, error_string, action )
            warning_msg( msg_string, self.fullpath(), parent )
开发者ID:tallforasmurf,项目名称:PPQT2,代码行数:45,代码来源:utilities.py

示例12: replaceImage

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
    def replaceImage(self, filepath, title):
        self.title = title
        self.filepath = filepath

         # set custom properties
        self.setCustomProperty("title", title)
        self.setCustomProperty("filepath", self.filepath)
        self.setName(title)

        fileInfo = QFileInfo(filepath)
        ext = fileInfo.suffix()
        if ext == "pdf":
            s = QSettings()
            oldValidation = s.value("/Projections/defaultBehavior")
            s.setValue("/Projections/defaultBehavior", "useGlobal")  # for not asking about crs
            path = fileInfo.filePath()
            baseName = fileInfo.baseName()
            layer = QgsRasterLayer(path, baseName)
            self.image = layer.previewAsImage(QSize(layer.width(), layer.height()))
            s.setValue("/Projections/defaultBehavior", oldValidation)
        else:
            reader = QImageReader(filepath)
            self.image = reader.read()
        self.repaint()
开发者ID:gvellut,项目名称:FreehandRasterGeoreferencer,代码行数:26,代码来源:freehandrastergeoreferencer_layer.py

示例13: initializeLayer

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]
    def initializeLayer(self, screenExtent=None):
        if self.error or self.initialized or self.initializing:
            return

        if self.filepath is not None:
            # not safe...
            self.initializing = True
            filepath = self.getAbsoluteFilepath()

            if not os.path.exists(filepath):
                # TODO integrate with BadLayerHandler ?
                loadErrorDialog = LoadErrorDialog(filepath)
                result = loadErrorDialog.exec_()
                if result == 1:
                    # absolute
                    filepath = loadErrorDialog.lineEditImagePath.text()
                    # to relative if needed
                    self.filepath = utils.toRelativeToQGS(filepath)
                    self.setCustomProperty("filepath", self.filepath)
                    QgsProject.instance().setDirty(True)
                else:
                    self.error = True

                del loadErrorDialog

            fileInfo = QFileInfo(filepath)
            ext = fileInfo.suffix()
            if ext == "pdf":
                s = QSettings()
                oldValidation = s.value("/Projections/defaultBehavior")
                s.setValue("/Projections/defaultBehavior", "useGlobal") # for not asking about crs
                path = fileInfo.filePath()
                baseName = fileInfo.baseName()
                layer = QgsRasterLayer(path, baseName)
                self.image = layer.previewAsImage(QSize(layer.width(),layer.height()))
                s.setValue("/Projections/defaultBehavior", oldValidation)
            else:
                reader = QImageReader(filepath)
                self.image = reader.read()

            self.initialized = True
            self.initializing = False

            self.setupCrs()

            if screenExtent:
                # constructor called from AddLayer action
                # if not, layer loaded from QGS project file

                # check if image already has georef info
                # use GDAL
                dataset = gdal.Open(filepath, gdal.GA_ReadOnly)
                georef = None
                if dataset:
                    georef = dataset.GetGeoTransform()

                if georef and not self.is_default_geotransform(georef):
                    self.initializeExistingGeoreferencing(dataset, georef)
                else:
                    # init to default params
                    self.setCenter(screenExtent.center())
                    self.setRotation(0.0)

                    sw = screenExtent.width()
                    sh = screenExtent.height()

                    self.resetScale(sw, sh)

                    self.commitTransformParameters()
开发者ID:gvellut,项目名称:FreehandRasterGeoreferencer,代码行数:71,代码来源:freehandrastergeoreferencer_layer.py

示例14: main

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import suffix [as 别名]

#.........这里部分代码省略.........
                        "pylupdate5 error: missing -translate-function name\n")
                sys.exit(2)

            translate_func = sys.argv[i]
            i += 1
            continue

        numFiles += 1

        fullText = ""

        if not metTsFlag:
            f = QFile(arg)

            if not f.open(QIODevice.ReadOnly):
                sys.stderr.write(
                        "pylupdate5 error: Cannot open file '%s'\n" % arg)
                sys.exit(1)

            t = QTextStream(f)
            fullText = t.readAll()
            f.close()

        if standardSyntax:
            oldDir = QDir.currentPath()
            QDir.setCurrent(QFileInfo(arg).path())

            fetchedTor = MetaTranslator()
            codecForTr = ''
            codecForSource = ''
            tsFileNames = []
            uiFileNames = []

            for key, value in proFileTagMap(fullText).items():
                for t in value.split(' '):
                    if key == "SOURCES":
                        fetchtr_py(QDir.current().absoluteFilePath(t),
                                fetchedTor, defaultContext, True,
                                codecForSource, tr_func, translate_func)
                        metSomething = True

                    elif key == "TRANSLATIONS":
                        tsFileNames.append(QDir.current().absoluteFilePath(t))
                        metSomething = True

                    elif key in ("CODEC", "DEFAULTCODEC", "CODECFORTR"):
                        codecForTr = t
                        fetchedTor.setCodec(codecForTr)

                    elif key == "CODECFORSRC":
                        codecForSource = t

                    elif key == "FORMS":
                        fetchtr_ui(QDir.current().absoluteFilePath(t),
                                fetchedTor, defaultContext, True)

            updateTsFiles(fetchedTor, tsFileNames, codecForTr, noObsolete,
                    verbose)

            if not metSomething:
                sys.stderr.write(
                        "pylupdate5 warning: File '%s' does not look like a "
                        "project file\n" % arg)
            elif len(tsFileNames) == 0:
                sys.stderr.write(
                        "pylupdate5 warning: Met no 'TRANSLATIONS' entry in "
                        "project file '%s'\n" % arg)

            QDir.setCurrent(oldDir)
        else:
            if metTsFlag:
                if arg.lower().endswith(".ts"):
                    fi = QFileInfo(arg)

                    if not fi.exists() or fi.isWritable():
                        tsFileNames.append(arg)
                    else:
                        sys.stderr.write(
                                "pylupdate5 warning: For some reason, I "
                                "cannot save '%s'\n" % arg)
                else:
                    sys.stderr.write(
                            "pylupdate5 error: File '%s' lacks .ts extension\n" % arg)
            else:
                fi = QFileInfo(arg)

                if fi.suffix() in ("py", "pyw"):
                    fetchtr_py(fi.absoluteFilePath(), fetchedTor,
                            defaultContext, True, codecForSource, tr_func,
                            translate_func)
                else:
                    fetchtr_ui(fi.absoluteFilePath(), fetchedTor,
                            defaultContext, True)

    if not standardSyntax:
        updateTsFiles(fetchedTor, tsFileNames, codecForTr, noObsolete, verbose)

    if numFiles == 0:
        printUsage()
        sys.exit(1)
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:104,代码来源:pylupdate_main.py


注:本文中的PyQt5.QtCore.QFileInfo.suffix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。