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


Python QUrl.fromLocalFile方法代码示例

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


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

示例1: setUpClass

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
    def setUpClass(cls):
        """Run before all tests"""
        # Create test layer
        srcpath = os.path.join(TEST_DATA_DIR, 'provider')
        cls.basetestfile = os.path.join(srcpath, 'delimited_wkt.csv')

        url = QUrl.fromLocalFile(cls.basetestfile)
        url.addQueryItem("crs", "epsg:4326")
        url.addQueryItem("type", "csv")
        url.addQueryItem("wktField", "wkt")
        url.addQueryItem("spatialIndex", "no")
        url.addQueryItem("subsetIndex", "no")
        url.addQueryItem("watchFile", "no")

        cls.vl = QgsVectorLayer(url.toString(), u'test', u'delimitedtext')
        assert cls.vl.isValid(), "{} is invalid".format(cls.basetestfile)
        cls.provider = cls.vl.dataProvider()

        cls.basetestpolyfile = os.path.join(srcpath, 'delimited_wkt_poly.csv')

        url = QUrl.fromLocalFile(cls.basetestpolyfile)
        url.addQueryItem("crs", "epsg:4326")
        url.addQueryItem("type", "csv")
        url.addQueryItem("wktField", "wkt")
        url.addQueryItem("spatialIndex", "no")
        url.addQueryItem("subsetIndex", "no")
        url.addQueryItem("watchFile", "no")

        cls.vl_poly = QgsVectorLayer(url.toString(), u'test_polygon', u'delimitedtext')
        assert cls.vl_poly.isValid(), "{} is invalid".format(cls.basetestpolyfile)
        cls.poly_provider = cls.vl_poly.dataProvider()
开发者ID:Naisha634,项目名称:QGIS,代码行数:33,代码来源:test_qgsdelimitedtextprovider.py

示例2: setup

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
 def setup(self, parent=None, caption=str("Sélectionnez")) :
     self.setFileMode(self.ExistingFiles)
     icon = QtGui.QIcon()
     icon.addPixmap(QtGui.QPixmap(_fromUtf8("resources/PL128.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
     self.setWindowIcon(icon)
     mydir = str(os.environ['USERPROFILE'])
     thedir = QDir("C:/")
     self.setDirectory(thedir)
     url = []
     url.append(QUrl.fromLocalFile(QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation)))
     url.append(QUrl.fromLocalFile(QDesktopServices.storageLocation(QDesktopServices.DesktopLocation)))
     url.append(QUrl.fromLocalFile(QDesktopServices.storageLocation(QDesktopServices.HomeLocation)))
     url.append(QUrl('file:'))
     self.setSidebarUrls(url)
     # self.setDirectory(mydir)
     self.setWindowModality(QtCore.Qt.ApplicationModal)
     MyFileDialog.setNameFilter(self, "Epub (*.epub)")
     self.setLabelText(self.LookIn, "Regarder dans :")
     self.setLabelText(self.FileName, "Fichier")
     self.setLabelText(self.FileType, "Type de fichier")
     self.setLabelText(self.Accept, "Ouvrir")
     self.setLabelText(self.Reject, "Annuler")
     self.setWindowTitle("Sélectionnez un ou plusieurs fichiers")
     self.setOption(self.DontUseNativeDialog, False)
     # self.setOption(self.DontResolveSymlinks, True)
     self.setOption(self.ShowDirsOnly, False)
     self.tree = self.findChild(QtGui.QTreeView)
     self.init_ui()
     self.filesSelected.connect(self.cur_change)
     self.filesSelected.connect(self.choose_file)
开发者ID:vdfebook,项目名称:PersonnaLiseur,代码行数:32,代码来源:dialogue.py

示例3: search

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
    def search(self, description):
        if description.help_ref:
            ref = description.help_ref
        else:
            raise KeyError()

        url = QUrl(self.baseurl).resolved(QUrl(ref))
        if url.isLocalFile():
            path = url.toLocalFile()
            fragment = url.fragment()
            if os.path.isfile(path):
                return url
            elif os.path.isfile("{}.html".format(path)):
                url = QUrl.fromLocalFile("{}.html".format(path))
                url.setFragment(fragment)
                return url
            elif os.path.isdir(path) and \
                    os.path.isfile(os.path.join(path, "index.html")):
                url = QUrl.fromLocalFile(os.path.join(path, "index.html"))
                url.setFragment(fragment)
                return url
            else:
                raise KeyError()
        else:
            if url.scheme() in ["http", "https"]:
                path = url.path()
                if not (path.endswith(".html") or path.endswith("/")):
                    url.setPath(path + ".html")
        return url
开发者ID:Coding4Sec,项目名称:orange3,代码行数:31,代码来源:provider.py

示例4: startmain

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
def startmain():
    import optparse
    optparse._ = _ # let optparse use our translations
    parser = optparse.OptionParser(
        usage = _("{appname} [options] file ...").format(appname=info.name),
        version = "{0} {1}".format(info.appname, info.version),
        description = _("A LilyPond Music Editor"))
    parser.add_option('-e', '--encoding', metavar=_("ENC"),
        help=_("Encoding to use"))
    parser.add_option('-l', '--line', type="int", metavar=_("NUM"),
        help=_("Line number to go to, starting at 1"))
    parser.add_option('-c', '--column', type="int", metavar=_("NUM"),
        help=_("Column to go to, starting at 0"), default=0)
    parser.add_option('--start', metavar=_("NAME"),
        help=_("Session to start ('{none}' for empty session)").format(none="none"),
        dest="session")

    args = QApplication.arguments()
    if os.name == 'nt' and args and 'python' in os.path.basename(args[0]).lower():
        args = args[2:]
    else:
        args = args[1:]
    options, files = parser.parse_args(args)

    # load specified session
    doc = None
    if options.session and options.session != "none":
        doc = sessions.loadSession(options.session)
        
    # Just create one MainWindow
    win = mainwindow.MainWindow()
    win.show()
    
    if files:
        # make urls
        for arg in files:
            if re.match(r'^(https?|s?ftp)://', arg):
                url = QUrl(arg)
            elif arg.startswith('file://'):
                url = QUrl.fromLocalFile(arg[7:])
            elif arg.startswith('file:'):
                url = QUrl.fromLocalFile(os.path.abspath(arg[5:]))
            else:
                url = QUrl.fromLocalFile(os.path.abspath(arg))
            doc = win.openUrl(url, options.encoding)
    elif not options.session:
        # no docs, load default session
        doc = sessions.loadDefaultSession()
    win.setCurrentDocument(doc or document.Document())
    if files and options.line is not None:
        # set the last loaded document active and apply navigation if requested
        pos = doc.findBlockByNumber(options.line - 1).position() + options.column
        cursor = QTextCursor(doc)
        cursor.setPosition(pos)
        win.currentView().setTextCursor(cursor)
        win.currentView().centerCursor()
开发者ID:mbsrz1972,项目名称:frescobaldi,代码行数:58,代码来源:main.py

示例5: url

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
def url(arg):
    """Converts a filename-like argument to a QUrl."""
    if re.match(r'^(https?|s?ftp)://', arg):
        return QUrl(arg)
    elif arg.startswith('file://'):
        return QUrl.fromLocalFile(os.path.abspath(arg[7:]))
    elif arg.startswith('file:'):
        return QUrl.fromLocalFile(os.path.abspath(arg[5:]))
    else:
        return QUrl.fromLocalFile(os.path.abspath(arg))
开发者ID:WedgeLeft,项目名称:frescobaldi,代码行数:12,代码来源:main.py

示例6: test_refLayers2

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
    def test_refLayers2(self):
        l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
        self.assertEqual(l1.isValid(), True)
        QgsMapLayerRegistry.instance().addMapLayer(l1)

        # referenced layers cannot be stored !
        tmp = QUrl.fromLocalFile(os.path.join(tempfile.gettempdir(), "t.sqlite")).toString()
        l2 = QgsVectorLayer("%s?layer_ref=%s" % (tmp, l1.id()), "tt", "virtual", False)
        self.assertEqual(l2.isValid(), False)
        self.assertEqual("Cannot store referenced layers" in l2.dataProvider().error().message(), True)
开发者ID:dudds6699,项目名称:QGIS,代码行数:12,代码来源:test_provider_virtual.py

示例7: _addAlgorithm

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
    def _addAlgorithm(self,name,operationNumber,xpos,ypos):
        print "python local method adding: ",name, " at location (",xpos,",",ypos,")"
        engine = self._savedViewObject.engine()
        print "engine: ", engine
        newalgo_comp = QtDeclarative.QDeclarativeComponent(engine)
          
        for case in switch(name):
           if case("Lagrange"):
            newalgo_comp = QtDeclarative.QDeclarativeComponent(engine,QUrl.fromLocalFile("/Users/clisle/Projects/Arbor/code/exploration/ArborUsingPyQt/Declarations/operations/Lagrange.qml"));
            break;
           if case("OpenModeller"):
            newalgo_comp = QtDeclarative.QDeclarativeComponent(engine,QUrl.fromLocalFile("/Users/clisle/Projects/Arbor/code/exploration/ArborUsingPyQt/Declarations/operations/OpenModeller.qml"));
            break;
           if case("DataIntegrator"):
            newalgo_comp = QtDeclarative.QDeclarativeComponent(engine,QUrl.fromLocalFile("/Users/clisle/Projects/Arbor/code/exploration/ArborUsingPyQt/Declarations/operations/DataIntegrator.qml"));
            break;
           if case("FitContinuous"):
            newalgo_comp = QtDeclarative.QDeclarativeComponent(engine,QUrl.fromLocalFile("/Users/clisle/Projects/Arbor/code/exploration/ArborUsingPyQt/Declarations/operations/FitContinuous.qml"));
            break;
           if case("FitDiscrete"):
            newalgo_comp = QtDeclarative.QDeclarativeComponent(engine,QUrl.fromLocalFile("/Users/clisle/Projects/Arbor/code/exploration/ArborUsingPyQt/Declarations/operations/FitDiscrete.qml"));
            break;
           if case("TreeFromFile"):
            newalgo_comp = QtDeclarative.QDeclarativeComponent(engine,QUrl.fromLocalFile("/Users/clisle/Projects/Arbor/code/exploration/ArborUsingPyQt/Declarations/operations/TreeFromFile.qml"));
            break;
           if case("OpenTreeOfLife"):
            newalgo_comp = QtDeclarative.QDeclarativeComponent(engine,QUrl.fromLocalFile("/Users/clisle/Projects/Arbor/code/exploration/ArborUsingPyQt/Declarations/operations/OpenTreeOfLife.qml"));
            break;
           if case("CharacterMatrix"):
            newalgo_comp = QtDeclarative.QDeclarativeComponent(engine,QUrl.fromLocalFile("/Users/clisle/Projects/Arbor/code/exploration/ArborUsingPyQt/Declarations/operations/CharacterMatrix.qml"));
            break;
           if case("TreeTransform"):
            newalgo_comp = QtDeclarative.QDeclarativeComponent(engine,QUrl.fromLocalFile("/Users/clisle/Projects/Arbor/code/exploration/ArborUsingPyQt/Declarations/operations/TreeTransform.qml"));
            break;

           if case():
              document.write("Sorry, we are out of " + name + ".<br>");
                  
        # instantiate the component to create a new instance
        newalgo_item = newalgo_comp.create()
        # assign a unique object name to the workstep instance
        newalgo_item.setObjectName("operation_"+str(operationNumber))
        # store the algorithm in the list of operations saved by the workflow manager.  The type of the operation
        # is stored in a parallel list so we can reference this to find pixel offsets later depending on the
        # type of the operation
        self._operations.append(newalgo_item)
        # build a dictionary indexed by object name that returns the object type.  Keeping local and global one just 
        # because the Segment class needs access to this cross reference, as well. 
        self._operationsType[newalgo_item.objectName()] = name
        operationsType[newalgo_item.objectName()] = name
        #print "newalgo_item=", newalgo_item
        print "new objname is: ",newalgo_item.objectName()
        # set the visual position of the icon and add it to the visual scene so it displays. The 
        # position it is added to the scene needs to be fixed, but this doesn't affect operation, just
        # aesthetics.  We need to translate from screen to workspace rectangle coordinates to get it right. 
        newalgo_item.setPos(float(xpos),float(ypos))
        self._savedViewObject.scene().addItem(newalgo_item)
        newalgo_item.setParentItem(self._workspaceObject)
开发者ID:curtislisle,项目名称:ArborWorkflowGUIPrototype,代码行数:60,代码来源:workflowManager.py

示例8: select_git_directory

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
def select_git_directory():
    settings = QSettings("majerti", "gitbuster")
    settings.beginGroup("Last run")

    filepath = '/'
    last_directory = settings.value("directory", QVariant(QDir.homePath()))
    dirs_list = settings.value("recent directories",
                               QStringList()).toStringList()
    custom_entries = settings.value("custom entries",
                                    QStringList()).toStringList()

    recent_dirs_urls = [QUrl.fromLocalFile(dir) for dir in dirs_list]
    home_url = QUrl.fromLocalFile(QDir.homePath())
    custom_entries_urls = [QUrl.fromLocalFile(dir) for dir in custom_entries]

    while not is_top_git_directory(unicode(filepath)):
        file_dialog = QFileDialog(None, "Open git repository",
                                  last_directory.toString())
        file_dialog.setFileMode(QFileDialog.Directory)
        file_dialog.setOptions(QFileDialog.ShowDirsOnly)
        if recent_dirs_urls:
            file_dialog.setSidebarUrls(
                [home_url,] +
                custom_entries_urls +
                recent_dirs_urls[-6:]
            )
        ret = file_dialog.exec_()

        custom_entries = QStringList()
        custom_entries_urls = []
        for url in file_dialog.sidebarUrls():
            if url not in recent_dirs_urls and url != home_url:
                custom_entries.append(QString(url.path()))
                custom_entries_urls.append(url)
        settings.setValue("custom entries", custom_entries)

        if ret:
            filepath = file_dialog.selectedFiles()[0]
        else:
            return ret

        if not filepath:
            return filepath

    if not dirs_list.contains(filepath):
        dirs_list.append(filepath)
        settings.setValue("recent directories", dirs_list)

    settings.setValue("directory", filepath)
    settings.endGroup()
    settings.sync()

    return unicode(filepath)
开发者ID:mike-perdide,项目名称:gitbuster,代码行数:55,代码来源:util.py

示例9: compute

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
    def compute(self):
        """ compute() -> None
        Render the XML tree and display it on the spreadsheet
        """
        xml = self.getInputFromPort('XML').name
        xsl = self.getInputFromPort('XSL').name

        query = QXmlQuery(QXmlQuery.XSLT20)
        query.setFocus(QUrl.fromLocalFile(os.path.join(os.getcwd(), xml)))
        query.setQuery(QUrl.fromLocalFile(os.path.join(os.getcwd(), xsl)))
        html = query.evaluateToString()

        self.cellWidget = self.displayAndWait(RichTextCellWidget, (html,))
开发者ID:cjh1,项目名称:VisTrails,代码行数:15,代码来源:richtext.py

示例10: createDocument

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
    def createDocument(self, filename, contents):
        """Create a new document using the specified filename and contents.

        Make it the current document in our mainwindow.

        """
        while os.path.exists(filename) or app.findDocument(QUrl.fromLocalFile(filename)):
            filename = util.next_file(filename)
        doc = app.openUrl(QUrl())
        doc.setPlainText(contents)
        doc.setUrl(QUrl.fromLocalFile(filename))
        doc.setModified(True)
        self.mainwindow().setCurrentDocument(doc)
        return doc
开发者ID:ryanakca,项目名称:frescobaldi,代码行数:16,代码来源:__init__.py

示例11: compute

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
    def compute(self):
        """ compute() -> None
        Render the XML tree and display it on the spreadsheet
        """
        xml = self.get_input('XML').name
        xsl = self.get_input('XSL').name

        query = QXmlQuery(QXmlQuery.XSLT20)
        query.setFocus(QUrl.fromLocalFile(os.path.join(os.getcwd(), xml)))
        query.setQuery(QUrl.fromLocalFile(os.path.join(os.getcwd(), xsl)))
        html = query.evaluateToString() # gets a unicode object
        if html is None:
            raise ModuleError(self, "Error applying XSL")

        self.displayAndWait(RichTextCellWidget, (html,))
开发者ID:hjanime,项目名称:VisTrails,代码行数:17,代码来源:richtext.py

示例12: help

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
 def help(self):
    self.help = QWidget()
    self.help.setWindowTitle('Lifemapper Help')
    self.help.resize(600, 400)
    self.help.setMinimumSize(600,400)
    self.help.setMaximumSize(1000,1000)
    layout = QVBoxLayout()
    helpDialog = QTextBrowser()
    helpDialog.setOpenExternalLinks(True)
    #helpDialog.setSearchPaths(['documents'])
    helppath = os.path.dirname(os.path.realpath(__file__))+'/documents/help.html'
    helpDialog.setSource(QUrl.fromLocalFile(helppath))
    helpDialog.scrollToAnchor('randomizePAM')
    layout.addWidget(helpDialog)
    self.help.setLayout(layout)
    if self.isModal():
       self.setModal(False)
    self.help.show()       
    
    
    
    
    
    
    
    
    
    
    
    
开发者ID:idigbio-api-hackathon,项目名称:LifemapperQgis,代码行数:20,代码来源:randomizePAM.py

示例13: test_source_escaping

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
 def test_source_escaping(self):
     # the source contains ':'
     source = QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no"
     d = QgsVirtualLayerDefinition()
     d.addSource("t", source, "delimitedtext")
     l = QgsVectorLayer(d.toString(), "vtab", "virtual", False)
     self.assertEqual(l.isValid(), True)
开发者ID:dudds6699,项目名称:QGIS,代码行数:9,代码来源:test_provider_virtual.py

示例14: help

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
    def help(self):
        localDoc = None
        html = self.grass7Name + '.html'
        if system.isWindows():
            # For MS-Windows, use the configured GRASS7 path
            localPath = os.path.join(Grass7Utils.grassPath(), 'docs/html', html)
            if os.path.exists(localPath):
                localDoc = os.path.abspath(localPath)
        elif system.isMac():
            # For MacOSX official package
            localPath = os.path.join('/Applications/GRASS-7.0.app/Contents/MacOS/docs/html', html)
            if os.path.exists(localPath):
                localDoc = os.path.abspath(localPath)
        else:
            # For GNU/Linux distributions
            searchPaths = ['/usr/share/doc/grass-doc/html', '/opt/grass/docs/html',
                           '/usr/share/doc/grass/docs/html']
            for path in searchPaths:
                localPath = os.path.join(path, html)
                if os.path.exists(localPath):
                    localDoc = os.path.abspath(localPath)

        # Found the local documentation
        if localDoc:
            localDoc = QUrl.fromLocalFile(localDoc).toString()
            return False, localDoc

        # Return the URL if local doc is not found
        return False, 'http://grass.osgeo.org/grass70/manuals/' + self.grass7Name + '.html'
开发者ID:Jesonchang12,项目名称:QGIS,代码行数:31,代码来源:Grass7Algorithm.py

示例15: openformfolder

# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import fromLocalFile [as 别名]
 def openformfolder(self, url):
     """
     Open the form folder using the OS file manager.
     :param url:
     :return:
     """
     QDesktopServices.openUrl(QUrl.fromLocalFile(self.form.folder))
开发者ID:skeenp,项目名称:Roam,代码行数:9,代码来源:layerwidgets.py


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