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


Python QFile.exists方法代码示例

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


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

示例1: read

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
 def read(self, fileName):
     self.state = PluginState.Invalid
     self.hasError = False
     self.dependencies = []
     specFile = QFile(fileName)
     if not specFile.exists():
         msg = QCoreApplication.translate(None, "File does not exist: {name}")
         return self.__reportError(msg.format(name=specFile.fileName()))
     if not specFile.open(QIODevice.ReadOnly):
         msg = QCoreApplication.translate(None, "Could not open file for read: {name}")
         return self.__reportError(msg.format(name=specFile.fileName()))
     fileInfo = QFileInfo(specFile)
     self.location = fileInfo.absolutePath()
     self.filePath = fileInfo.absoluteFilePath()
     reader = QXmlStreamReader(specFile)
     while not reader.atEnd():
         reader.readNext()
         tokenType = reader.tokenType()
         if tokenType is QXmlStreamReader.StartElement:
             self.__readPluginSpec(reader)
         else:
             pass
     if reader.hasError():
         msg = QCoreApplication.translate(None, "Error parsing file {0}: {1}, at line {2}, column {3}")
         return self.__reportError(msg.format(specFile.fileName(), reader.errorString(),
                                              reader.lineNumber(), reader.columnNumber()))
     self.state = PluginState.Read
     return True
开发者ID:nichollyn,项目名称:libspark,代码行数:30,代码来源:pluginspec.py

示例2: updateFileMenu

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
    def updateFileMenu(self):
        """
        Updates the file menu dynamically, so that recent files can be shown.
        """
        self.menuFile.clear()
        #        self.menuFile.addAction(self.actionNew)    # disable for now
        self.menuFile.addAction(self.actionOpen)
        self.menuFile.addAction(self.actionSave)
        self.menuFile.addAction(self.actionSave_as)
        self.menuFile.addAction(self.actionClose_Model)

        recentFiles = []
        for filename in self.recentFiles:
            if QFile.exists(filename):
                recentFiles.append(filename)

        if len(self.recentFiles) > 0:
            self.menuFile.addSeparator()
            for i, filename in enumerate(recentFiles):
                action = QAction("&%d %s" % (i + 1, QFileInfo(filename).fileName()), self)
                action.setData(filename)
                action.setStatusTip("Opens recent file %s" % QFileInfo(filename).fileName())
                action.setShortcut(QKeySequence(Qt.CTRL | (Qt.Key_1 + i)))
                action.triggered.connect(self.load_model)
                self.menuFile.addAction(action)

        self.menuFile.addSeparator()
        self.menuFile.addAction(self.actionQuit)
开发者ID:CSB-at-ZIB,项目名称:BioPARKIN,代码行数:30,代码来源:BioPARKIN.py

示例3: get_file_name

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
 def get_file_name(self, url):
     path = url.path()
     basename = QFileInfo(path).fileName()
     if not basename:
         basename = "download"
     if QFile.exists(basename):
         print "aaaaaaaaaaaaaaaah"
         return
     return basename
开发者ID:bordstein,项目名称:hamster,代码行数:11,代码来源:downloader.py

示例4: downloadFile

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
    def downloadFile(self, path, setting):
        self.progress_text = 'Downloading {}'.format(path.replace(self.base_url.format(self.selected_version()),''))

        url = QUrl(path)
        fileInfo = QFileInfo(url.path())
        fileName = setting.save_file_path(self.selected_version())

        archive_exists = QFile.exists(fileName)

        dest_files_exist = True

        for dest_file in setting.dest_files:
            dest_file_path = os.path.join('files', setting.name, dest_file)
            dest_files_exist &= QFile.exists(dest_file_path)

        forced = self.getSetting('force_download').value

        if (archive_exists or dest_files_exist) and not forced:
            self.continueDownloadingOrExtract()
            return #QFile.remove(fileName)

        self.outFile = QFile(fileName)
        if not self.outFile.open(QIODevice.WriteOnly):
            self.show_error('Unable to save the file {}: {}.'.format(fileName, self.outFile.errorString()))
            self.outFile = None
            self.enableUI()
            return

        mode = QHttp.ConnectionModeHttp
        port = url.port()
        if port == -1:
            port = 0
        self.http.setHost(url.host(), mode, port)
        self.httpRequestAborted = False

        path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
        if path:
            path = str(path)
        else:
            path = '/'

        # Download the file.
        self.httpGetId = self.http.get(path, self.outFile)
开发者ID:riderx,项目名称:Web2Executable,代码行数:45,代码来源:main.py

示例5: download_file

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
    def download_file(self, path, setting):
        version_file = self.settings['base_url'].format(self.selected_version())

        location = self.get_setting('download_dir').value

        versions = re.findall('v(\d+)\.(\d+)\.(\d+)', path)[0]

        minor = int(versions[1])
        if minor >= 12:
            path = path.replace('node-webkit', 'nwjs')

        self.progress_text = 'Downloading {}'.format(path.replace(version_file, ''))

        url = QUrl(path)
        file_name = setting.save_file_path(self.selected_version(), location)

        archive_exists = QFile.exists(file_name)

        #dest_files_exist = False

        # for dest_file in setting.dest_files:
        #    dest_file_path = os.path.join('files', setting.name, dest_file)
        #    dest_files_exist &= QFile.exists(dest_file_path)

        forced = self.get_setting('force_download').value

        if archive_exists and not forced:
            self.continue_downloading_or_extract()
            return

        self.out_file = QFile(file_name)
        if not self.out_file.open(QIODevice.WriteOnly):
            error = self.out_file.error().name
            self.show_error('Unable to save the file {}: {}.'.format(file_name,
                                                                     error))
            self.out_file = None
            self.enable_ui()
            return

        mode = QHttp.ConnectionModeHttp
        port = url.port()
        if port == -1:
            port = 0
        self.http.setHost(url.host(), mode, port)
        self.http_request_aborted = False

        path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
        if path:
            path = str(path)
        else:
            path = '/'

        # Download the file.
        self.http_get_id = self.http.get(path, self.out_file)
开发者ID:ebenshap,项目名称:Web2Executable,代码行数:56,代码来源:main.py

示例6: load_initial_data

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
 def load_initial_data(self):
     settings = QSettings()
     dbfile = unicode(settings.value("Database/LastDb"))
     modelname = unicode(settings.value("Database/DefaultModel"))
     if dbfile and QFile.exists(dbfile):
         self.load_db(dbfile, modelname=modelname)
         self.logger.debug("Loaded database %s with model %s" % (dbfile,
                                                                  modelname))
     
     if settings.value("Database/visibleFields"):
         visible_fields = [item for item in settings.value("Database/visibleFields")]
     
         # FIXME: in absence of QVariant, deal with values
         visible_fields = [False if item == 'false' else True for item in visible_fields]
         if not all(visible_fields):
             self.logger.debug("Hiding fields %s" % visible_fields)
         self.show_fields(visible_fields)
开发者ID:jlehtoma,项目名称:MaeBird,代码行数:19,代码来源:main.py

示例7: load_stylesheet

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
def load_stylesheet(pyside=True):


    f = QFile(":petfactoryStyle/style.qss")
    if not f.exists():
        pass

    else:
        f.open(QFile.ReadOnly | QFile.Text)
        ts = QTextStream(f)
        stylesheet = ts.readAll()
        if platform.system().lower() == 'darwin':  # see issue #12 on github
            mac_fix = '''
            QDockWidget::title
            {
                background-color: #353434;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
开发者ID:petfactory,项目名称:PySide,代码行数:24,代码来源:__init__.py

示例8: dbConnect

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
def dbConnect():
    db = QSqlDatabase.addDatabase("QSQLITE")
    filename = "pythonthusiast.db"
    database =  QFile(filename)
    if not database.exists():
        qDebug("Database not found. Creating and opening")
        db.setDatabaseName(filename)
        db.open()
        query = QSqlQuery()
        query.exec_("create table qtapp_users "
                    "(id integer primary key autoincrement, "
                    "username varchar(30), "
                    "password varchar(255))")
        query.prepare("insert into qtapp_users(username, password) values(:username, :password)")
        query.bindValue(":username", "eko")
        query.bindValue(":password", computeHash("password"))
        query.exec_()
    else:
        qDebug("Database found. Opening")
        db.setDatabaseName(filename)
        db.open()
    return db.isOpen()
开发者ID:bmweller,项目名称:CrossPlatformQt,代码行数:24,代码来源:helper.py

示例9: main

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
def main(argv):
    """
    TOWRITE

    :param `argc`: TOWRITE
    :type `argc`: int
    :param `argv`: TOWRITE
    :type `argv`: char
    :rtype: int
    """

    filesToOpen = []  # QStringList filesToOpen;
    filesToCheck = []

    bindings = defaultBindings
    bindings_flag = False
    for arg in argv[1:]:
        if bindings_flag:
            bindings_flag = False
            if not arg in ("pyside", "pyqt4"):
                usage()
            else:
                bindings = arg
        elif arg == "-d" or arg == "--debug":
            pass
        elif arg == "-h" or arg == "--help":
            usage()
        elif arg == "-v" or arg == "--version":
            version()
        elif arg == "-b" or arg == "--bindings":
            bindings_flag = True
        else:
            filesToCheck.append(arg)

    if exitApp:
        return 1

    # make global to all modules
    if bindings == "pyside":
        builtins.PYSIDE = True
        builtins.PYQT4 = False
    elif bindings == "pyqt4":
        builtins.PYSIDE = False
        builtins.PYQT4 = True

    if PYSIDE:
        from PySide.QtScript import QScriptEngine

        if not hasattr(QScriptEngine, "newFunction"):
            raise ImportError("You need a patched version of PySide.\n" "see: https://codereview.qt-project.org/112333")

    # --PySide Imports.
    if PYSIDE:
        from PySide.QtCore import QObject, SIGNAL, SLOT, QFile
        from PySide.QtGui import QApplication
    elif PYQT4:
        import sip

        sip.setapi("QString", 2)
        sip.setapi("QVariant", 2)
        from PyQt4.QtCore import QObject, SIGNAL, SLOT, QFile
        from PyQt4.QtGui import QApplication

    from mainwindow import MainWindow

    for file_ in filesToCheck:
        if QFile.exists(file_) and MainWindow.validFileFormat(file_):
            filesToOpen.append(file_)
        else:
            usage()
            break

    if exitApp:
        return 1

    app = QApplication(argv)
    app.setApplicationName(_appName_)
    app.setApplicationVersion(_appVer_)

    mainWin = MainWindow()  # MainWindow*

    QObject.connect(app, SIGNAL("lastWindowClosed()"), mainWin, SLOT("quit()"))

    mainWin.setWindowTitle(app.applicationName() + " " + app.applicationVersion())
    mainWin.show()

    # NOTE: If openFilesSelected() is called from within the mainWin constructor, slot commands wont work and the window menu will be screwed
    if filesToOpen:  # if(!filesToOpen.isEmpty())
        mainWin.openFilesSelected(filesToOpen)

    # return app.exec_()
    return app.exec_()
开发者ID:stevegt,项目名称:Embroidermodder,代码行数:94,代码来源:main.py

示例10: testCallingInstanceMethod

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
 def testCallingInstanceMethod(self):
     '''Call instance method.'''
     f1 = QFile(self.non_existing_filename)
     self.assertFalse(f1.exists())
     f2 = QFile(self.existing_filename)
     self.assert_(f2.exists())
开发者ID:Hasimir,项目名称:PySide,代码行数:8,代码来源:static_method_test.py

示例11: testCallingStaticMethodWithInstance

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
 def testCallingStaticMethodWithInstance(self):
     '''Call static method using instance of class.'''
     f = QFile(self.non_existing_filename)
     self.assert_(f.exists(self.existing_filename))
     self.assertFalse(f.exists(self.non_existing_filename))
开发者ID:Hasimir,项目名称:PySide,代码行数:7,代码来源:static_method_test.py

示例12: testCallingStaticMethodWithClass

# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import exists [as 别名]
 def testCallingStaticMethodWithClass(self):
     '''Call static method using class.'''
     self.assert_(QFile.exists(self.existing_filename))
     self.assertFalse(QFile.exists(self.non_existing_filename))
开发者ID:Hasimir,项目名称:PySide,代码行数:6,代码来源:static_method_test.py


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