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


Python QFileInfo.exists方法代码示例

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


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

示例1: on_new_wallet

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
 def on_new_wallet(self):
     # TODO: Было бы круто использовать стандартные методы
     dialog = NewWalletDialog(self.__current_path)
     if dialog.exec() == QDialog.Accepted:
         directory = dialog.directory()
         wallet_name = dialog.wallet_name()
         if not wallet_name:
             return
         file_name = '%s/%s' % (directory, wallet_name)
         if QFileInfo.exists(file_name):
             result = QMessageBox.question(self,
                                           tr('MyWallet', 'Create new wallet'),
                                           tr('MyWallet', 'Wallet \'%s\' already exists. Rewrite?') % wallet_name)
             if result == QMessageBox.No:
                 return
         if not wallet_name.endswith('.db'):
             file_name = '%s.db' % file_name
         try:
             WalletModel.create_new_wallet(file_name)
         except WalletModelException as e:
             QMessageBox.critical(self, tr('MyWallet', 'Create new wallet'), str(e))
         else:
             QMessageBox.information(self,
                                     tr('MyWallet', 'Create new wallet'),
                                     tr('MyWallet', 'Wallet \'%s\' was created') % wallet_name)
开发者ID:dimV36,项目名称:MyWallet,代码行数:27,代码来源:mywallet.py

示例2: open

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
    def open(self, file_name):
        """Open the file at the given path for reading.

        Args:
            file_name (str): File path of the file to open. Only .wav files
                permitted.

        Raises:
            FileNotFoundError: If the filename given cannot be opened.
        """
        if file_name is not None:
            file_info = QFileInfo(file_name)
            if file_info.exists():
                self.file_name = file_name
                # Update the waveform data
                wave_read = wave.open(file_name, 'r')
                self.waveform_info = wave_read.getparams()
                step = int(self.waveform_info.framerate / self.stored_fps)
                self.waveform_data = list(bytesToInts(
                        data=wave_read.readframes(-1),
                        channelWidth=self.waveform_info.sampwidth,
                        numChannels=self.waveform_info.nchannels,
                        signed=True,
                        step=step))
                # Update the media player
                url = QUrl.fromLocalFile(file_info.absoluteFilePath())
                self.media_player.setMedia(QMediaContent(url))
                # Send out appropriate event
                self.signalFileChanged.emit()
                wave_read.close()
            else:
                raise FileNotFoundError('No file exists at given file path')
开发者ID:RNanoware,项目名称:snapshot,代码行数:34,代码来源:signal.py

示例3: restoreDir

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
 def restoreDir(self):
     "用户点击了“默认运行目录”按钮。"
     path = self.txtPath.text().strip()
     fi = QFileInfo(path)
     if path == "" or not fi.exists():
         return
     self.txtDir.setText(fi.dir().absolutePath())
开发者ID:hgoldfish,项目名称:quickpanel,代码行数:9,代码来源:desktop_icon.py

示例4: setFileIcon

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
 def setFileIcon(self, path):
     "每当txtPath的值改变时,就设置快捷方式的图标"
     fi = QFileInfo(path)
     if not fi.exists():
         self.shortcutIcon = QIcon(":/images/unknown.png")
     else:
         ip = QFileIconProvider()
         self.shortcutIcon = ip.icon(fi)
     self.btnFace.setIcon(self.shortcutIcon)
开发者ID:hgoldfish,项目名称:quickpanel,代码行数:11,代码来源:desktop_icon.py

示例5: add_song

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [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

示例6: addShapeToCanvas

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
def addShapeToCanvas( shapefile_path ):
    file_info = QFileInfo( shapefile_path )
    if file_info.exists():
        layer_name = file_info.completeBaseName()
    else:
        return False
    vlayer_new = QgsVectorLayer( shapefile_path, layer_name, "ogr" )
    if vlayer_new.isValid():
        QgsProject.instance().addMapLayers( [vlayer_new] )
        return True
    else:
        return False
开发者ID:rozos,项目名称:Hydrogeios-Qgis,代码行数:14,代码来源:h_utils.py

示例7: create_wallet

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
 def create_wallet(database):
     target_dir = QFileInfo(database).absoluteDir()
     if not target_dir.exists():
         QDir().mkdir(target_dir.absolutePath())
     db = sqlite3.connect(database)
     cursor = db.cursor()
     try:
         for cq in WalletDatabase.__WALLET_INIT_WALLET_QUERY:
             cursor.execute(cq)
     except sqlite3.Error as e:
         raise WalletDatabaseException(tr('WalletDatabase', 'Failed to create wallet: %s') % e)
     db.commit()
     db.close()
开发者ID:dimV36,项目名称:MyWallet,代码行数:15,代码来源:walletdatabase.py

示例8: _load_audio

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [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: addToPlaylist

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [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

示例10: handle_file_changed

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
    def handle_file_changed(self, path):
        """Handle when a watched file gets changed

        Crazy stuff ahead.

        If a file is modified, some editors (systems?) will first remove
        the file and then write it back to the disk. And for that split
        second, the watcher will drop the file from being watched.

        But then again, maybe that file really got deleted? Who knows?!

        Anyway, when a file gets modified, we sleep a short while to
        see if that file will "get back" and if so, add it back to the
        watcher. If not, we'll assume the file got deleted.
        """
        if not self.__is_path_watched(path):
            fileinfo = QFileInfo(path)

            total_slept = 0
            file_exists = fileinfo.exists()

            while not file_exists:
                sleep_for = 0.1
                total_slept += sleep_for

                if total_slept > 1:
                    break

                time.sleep(sleep_for)
                file_exists = fileinfo.exists()

            if file_exists:
                self.watcher.addPath(path)

                self.refresh_document(path)
            else:
                # file got deleted?
                pass
开发者ID:mbarbon,项目名称:pugdebug,代码行数:40,代码来源:documents.py

示例11: loadRasterfileToCanvas

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
def loadRasterfileToCanvas(prjpath, layerName):
    """Loads a raste to canvas."""
    if isLayerLoaded(layerName):
        return True
    pathFilename=os.path.join(prjpath, layerName+".tif")
    file_info = QFileInfo(pathFilename)
    if file_info.exists():
        layer_name = file_info.completeBaseName()
    else:
        message="Error loading raster"+pathFilename
        QMessageBox.critical(None, 'Error', message, QMessageBox.Ok)
        return False
    layeropts=QgsRasterLayer.LayerOptions(True)    
    rlayer_new = QgsRasterLayer( pathFilename, layer_name, 'gdal', layeropts )
    if rlayer_new.isValid():
        QgsProject.instance().addMapLayer(rlayer_new)
        return True
    else:
        return False
开发者ID:rozos,项目名称:Hydrogeios-Qgis,代码行数:21,代码来源:h_utils.py

示例12: on_main_window_start

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
def on_main_window_start(main_window):
    main_window.theme_menu = main_window.menuBar().addMenu(
        main_window.tr('Themes'))
    themes_directory = QFileInfo('themes')
    if themes_directory.exists():
        active_theme = ThemeManager.get_active_theme()
        path = themes_directory.absoluteFilePath()
        group_action = QActionGroup(main_window)
        group_action.setExclusive(True)
        for theme in os.listdir(path):
            action = QAction(theme, main_window)
            action.setData(theme)
            action.setCheckable(True)
            if theme == active_theme:
                action.setChecked(True)
            action.changed.connect(ThemeManager.wrapper(main_window))
            group_action.addAction(action)
            group_action.addAction(action)
            main_window.theme_menu.addAction(action)
开发者ID:FlorianPerrot,项目名称:Mojuru,代码行数:21,代码来源:theme_manager.py

示例13: prepareAPIs

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
 def prepareAPIs(self, ondemand=False, rawList=None):
     """
     Public method to prepare the APIs if necessary.
     
     @keyparam ondemand flag indicating a requested preparation (boolean)
     @keyparam rawList list of raw API files (list of strings)
     """
     if self.__apis is None or self.__inPreparation:
         return
     
     needsPreparation = False
     if ondemand:
         needsPreparation = True
     else:
         # check, if a new preparation is necessary
         preparedAPIs = self.__defaultPreparedName()
         if preparedAPIs:
             preparedAPIsInfo = QFileInfo(preparedAPIs)
             if not preparedAPIsInfo.exists():
                 needsPreparation = True
             else:
                 preparedAPIsTime = preparedAPIsInfo.lastModified()
                 apifiles = sorted(
                     Preferences.getEditorAPI(self.__language))
                 if self.__apifiles != apifiles:
                     needsPreparation = True
                 for apifile in apifiles:
                     if QFileInfo(apifile).lastModified() > \
                             preparedAPIsTime:
                         needsPreparation = True
                         break
     
     if needsPreparation:
         # do the preparation
         self.__apis.clear()
         if rawList:
             apifiles = rawList
         else:
             apifiles = Preferences.getEditorAPI(self.__language)
         for apifile in apifiles:
             self.__apis.load(apifile)
         self.__apis.prepare()
         self.__apifiles = apifiles
开发者ID:pycom,项目名称:EricShort,代码行数:45,代码来源:APIsManager.py

示例14: fromPath

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
    def fromPath(cls, path):
        # type: (str) -> ImportItem
        """
        Create a `ImportItem` from a local file system path.
        """
        iconprovider = QFileIconProvider()
        basename = os.path.basename(path)
        item = cls()
        item.setText(basename)
        item.setToolTip(path)
        finfo = QFileInfo(path)
        if finfo.exists():
            item.setIcon(iconprovider.icon(finfo))
        else:
            item.setIcon(iconprovider.icon(QFileIconProvider.File))

        item.setData(path, ImportItem.PathRole)
        if not os.path.isfile(path):
            item.setEnabled(False)
            item.setToolTip(item.toolTip() + " (missing from filesystem)")
        return item
开发者ID:pavlin-policar,项目名称:orange3-prototypes,代码行数:23,代码来源:owcsvimport.py

示例15: createRequest

# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import exists [as 别名]
 def createRequest(self, op, request, outgoingData=None):
     """
     Public method to create a request.
     
     @param op the operation to be performed
         (QNetworkAccessManager.Operation)
     @param request reference to the request object (QNetworkRequest)
     @param outgoingData reference to an IODevice containing data to be sent
         (QIODevice)
     @return reference to the created reply object (QNetworkReply)
     """
     if op == QNetworkAccessManager.GetOperation:
         fileInfo = QFileInfo(request.url().toLocalFile())
         if not fileInfo.isDir() or \
            not fileInfo.isReadable() or \
            not fileInfo.exists():
             return None
         from .FileReply import FileReply
         return FileReply(request.url(), self.parent())
     else:
         return None
开发者ID:Darriall,项目名称:eric,代码行数:23,代码来源:FileAccessHandler.py


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