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


Python QDir.homePath方法代码示例

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


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

示例1: on_btnSave_clicked

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
    def on_btnSave_clicked(self):
        fileName, _ = QFileDialog.getSaveFileName(None,
                                                  self.tr('Export Colors and elevations as XML'),
                                                  QDir.homePath(),
                                                  self.tr('XML files (*.xml *.XML)'))

        if fileName == '':
            return

        if not fileName.lower().endswith('.xml'):
            fileName += '.xml'

        doc = QDomDocument()
        colorsElem = doc.createElement('ReliefColors')
        doc.appendChild(colorsElem)

        colors = self.reliefColors()
        for c in colors:
            elem = doc.createElement('ReliefColor')
            elem.setAttribute('MinElevation', str(c.minElevation))
            elem.setAttribute('MaxElevation', str(c.maxElevation))
            elem.setAttribute('red', str(c.color.red()))
            elem.setAttribute('green', str(c.color.green()))
            elem.setAttribute('blue', str(c.color.blue()))
            colorsElem.appendChild(elem)

        with codecs.open(fileName, 'w', encoding='utf-8') as f:
            f.write(doc.toString(2))
开发者ID:cayetanobv,项目名称:QGIS,代码行数:30,代码来源:ReliefColorsWidget.py

示例2: on_btnSave_clicked

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
    def on_btnSave_clicked(self):
        fileName, _ = QFileDialog.getSaveFileName(
            None, self.tr("Export Colors and elevations as XML"), QDir.homePath(), self.tr("XML files (*.xml *.XML)")
        )

        if fileName == "":
            return

        if not fileName.lower().endswith(".xml"):
            fileName += ".xml"

        doc = QDomDocument()
        colorsElem = doc.createElement("ReliefColors")
        doc.appendChild(colorsElem)

        colors = self.reliefColors()
        for c in colors:
            elem = doc.createElement("ReliefColor")
            elem.setAttribute("MinElevation", str(c.minElevation))
            elem.setAttribute("MaxElevation", str(c.maxElevation))
            elem.setAttribute("red", str(c.color.red()))
            elem.setAttribute("green", str(c.color.green()))
            elem.setAttribute("blue", str(c.color.blue()))
            colorsElem.appendChild(elem)

        with codecs.open(fileName, "w", encoding="utf-8") as f:
            f.write(doc.toString(2))
开发者ID:kalxas,项目名称:QGIS,代码行数:29,代码来源:ReliefColorsWidget.py

示例3: on_btnLoad_clicked

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
    def on_btnLoad_clicked(self):
        fileName, _ = QFileDialog.getOpenFileName(None,
                                                  self.tr('Import Colors and elevations from XML'),
                                                  QDir.homePath(),
                                                  self.tr('XML files (*.xml *.XML)'))
        if fileName == '':
            return

        doc = QDomDocument()
        with codecs.open(fileName, 'r', encoding='utf-8') as f:
            content = f.read()

        if not doc.setContent(content):
            QMessageBox.critical(None,
                                 self.tr('Error parsing XML'),
                                 self.tr('The XML file could not be loaded'))
            return

        self.reliefClassTree.clear()
        reliefColorList = doc.elementsByTagName('ReliefColor')
        for i in range(reliefColorList.length()):
            elem = reliefColorList.at(i).toElement()
            item = QTreeWidgetItem()
            item.setText(0, elem.attribute('MinElevation'))
            item.setText(1, elem.attribute('MaxElevation'))
            item.setBackground(2, QBrush(QColor(int(elem.attribute('red')),
                                                int(elem.attribute('green')),
                                                int(elem.attribute('blue')))))
            self.reliefClassTree.addTopLevelItem(item)
开发者ID:cayetanobv,项目名称:QGIS,代码行数:31,代码来源:ReliefColorsWidget.py

示例4: saveAsScriptFile

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
    def saveAsScriptFile(self, index=None):
        tabWidget = self.tabEditorWidget.currentWidget()
        if not index:
            index = self.tabEditorWidget.currentIndex()
        if not tabWidget.path:
            fileName = self.tabEditorWidget.tabText(index) + '.py'
            folder = self.settings.value("pythonConsole/lastDirPath", QDir.homePath())
            pathFileName = os.path.join(folder, fileName)
            fileNone = True
        else:
            pathFileName = tabWidget.path
            fileNone = False
        saveAsFileTr = QCoreApplication.translate("PythonConsole", "Save File As")
        filename, filter = QFileDialog.getSaveFileName(self,
                                                       saveAsFileTr,
                                                       pathFileName, "Script file (*.py)")
        if filename:
            try:
                tabWidget.save(filename)
            except (IOError, OSError) as error:
                msgText = QCoreApplication.translate('PythonConsole',
                                                     'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path,
                                                                                                                  error.strerror)
                self.callWidgetMessageBarEditor(msgText, 2, False)
                if fileNone:
                    tabWidget.path = None
                else:
                    tabWidget.path = pathFileName
                return

            if not fileNone:
                self.updateTabListScript(pathFileName, action='remove')
开发者ID:CS-SI,项目名称:QGIS,代码行数:34,代码来源:console.py

示例5: selFile

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
 def selFile(self):
     sf = QFileInfo(QFileDialog.getOpenFileName(self, 'Open logo file', QDir.homePath(), 'Image files (*.png)'))
     f = sf.fileName()
     if f!='':
         self.logopath = sf.absoluteFilePath()
         self.label.setPixmap(QPixmap(self.logopath))
     return f
开发者ID:IZSVenezie,项目名称:VetEpiGIS-Tool,代码行数:9,代码来源:xprint.py

示例6: filer

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
    def filer(self):
        if self.comboBox.currentText()=='ESRI shape file':
            a = 'Save as ESRI shape file'
            sf = QFileDialog.getExistingDirectory(self, a, QDir.homePath())
            # b = 'ESRI shape files (*.shp)'
        elif self.comboBox.currentText()=='Comma separated value (CSV)':
            a = 'Save as comma separated value (CSV)'
            sf = QFileDialog.getExistingDirectory(self, a, QDir.homePath())
            # b = 'CSV files (*.csv)'
        elif self.comboBox.currentText()=='SQLite database':
            a = 'SQLite database'
            sf = QFileDialog.getOpenFileName(self, a, QDir.homePath())
        elif self.comboBox.currentText()=='Copy complete database':
            a = 'Copy complete database'
            sf = QFileDialog.getSaveFileName(self, a, QDir.homePath())

        self.lineEdit.setText(sf)
开发者ID:IZSVenezie,项目名称:VetEpiGIS-Tool,代码行数:19,代码来源:export.py

示例7: selectDirectory

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
    def selectDirectory(self):
        lastDir = self.leText.text()
        settings = QgsSettings()
        if not lastDir:
            lastDir = settings.value("/Processing/LastOutputPath", QDir.homePath())

        dirName = QFileDialog.getExistingDirectory(self, self.tr('Select directory'),
                                                   lastDir, QFileDialog.ShowDirsOnly)
        if dirName:
            self.leText.setText(QDir.toNativeSeparators(dirName))
            settings.setValue('/Processing/LastOutputPath', dirName)
开发者ID:timlinux,项目名称:QGIS,代码行数:13,代码来源:DestinationSelectionPanel.py

示例8: selectDirectory

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
    def selectDirectory(self):
        lastDir = self.leText.text()
        settings = QgsSettings()
        if not lastDir:
            lastDir = settings.value("/Processing/LastOutputPath", QDir.homePath())

        dirName = QFileDialog.getExistingDirectory(self, self.tr('Select Directory'),
                                                   lastDir, QFileDialog.ShowDirsOnly)
        if dirName:
            self.leText.setText(QDir.toNativeSeparators(dirName))
            settings.setValue('/Processing/LastOutputPath', dirName)
            self.use_temporary = False
            self.skipOutputChanged.emit(False)
            self.destinationChanged.emit()
开发者ID:lbartoletti,项目名称:QGIS,代码行数:16,代码来源:DestinationSelectionPanel.py

示例9: local_collection_path

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
def local_collection_path(id=None):
    """Get the path to the local collection dir.

    If id is not passed, it will just return the root dir of the collections.
    """
    path = os.path.join(
        QDir.homePath(),
        'QGIS',
        'Resource Sharing')
    if id:
        collection_name = config.COLLECTIONS[id]['name']
        dir_name = '%s (%s)' % (collection_name, id)
        path = os.path.join(path, dir_name)
    return path
开发者ID:akbargumbira,项目名称:qgis_resources_sharing,代码行数:16,代码来源:utilities.py

示例10: save

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
    def save(self):
        toSave = []
        context = dataobjects.createContext()
        for row in range(self.tblParameters.rowCount()):
            algParams = {}
            algOutputs = {}
            col = 0
            alg = self.alg
            for param in alg.parameterDefinitions():
                if param.flags() & QgsProcessingParameterDefinition.FlagHidden:
                    continue
                if param.isDestination():
                    continue
                wrapper = self.wrappers[row][col]
                if not param.checkValueIsAcceptable(wrapper.value(), context):
                    self.parent.messageBar().pushMessage("", self.tr('Wrong or missing parameter value: {0} (row {1})').format(
                        param.description(), row + 1),
                        level=Qgis.Warning, duration=5)
                    return
                algParams[param.name()] = param.valueAsPythonString(wrapper.value(), context)
                col += 1
            for out in alg.destinationParameterDefinitions():
                if out.flags() & QgsProcessingParameterDefinition.FlagHidden:
                    continue
                widget = self.tblParameters.cellWidget(row, col)
                text = widget.getValue()
                if text.strip() != '':
                    algOutputs[out.name()] = text.strip()
                    col += 1
                else:
                    self.parent.messageBar().pushMessage("", self.tr('Wrong or missing output value: {0} (row {1})').format(
                        out.description(), row + 1),
                        level=Qgis.Warning, duration=5)
                    return
            toSave.append({self.PARAMETERS: algParams, self.OUTPUTS: algOutputs})

        settings = QgsSettings()
        last_path = settings.value("/Processing/LastBatchPath", QDir.homePath())
        filename, __ = QFileDialog.getSaveFileName(self,
                                                   self.tr('Save Batch'),
                                                   last_path,
                                                   self.tr('JSON files (*.json)'))
        if filename:
            if not filename.endswith('.json'):
                filename += '.json'
            last_path = QFileInfo(filename).path()
            settings.setValue('/Processing/LastBatchPath', last_path)
            with open(filename, 'w') as f:
                json.dump(toSave, f)
开发者ID:tomchadwin,项目名称:QGIS,代码行数:51,代码来源:BatchPanel.py

示例11: load

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
    def load(self):
        context = dataobjects.createContext()
        settings = QgsSettings()
        last_path = settings.value("/Processing/LastBatchPath", QDir.homePath())
        filename, selected_filter = QFileDialog.getOpenFileName(self,
                                                                self.tr('Open Batch'), last_path,
                                                                self.tr('JSON files (*.json)'))
        if filename:
            last_path = QFileInfo(filename).path()
            settings.setValue('/Processing/LastBatchPath', last_path)
            with open(filename) as f:
                values = json.load(f)
        else:
            # If the user clicked on the cancel button.
            return

        self.tblParameters.setRowCount(0)
        try:
            for row, alg in enumerate(values):
                self.addRow()
                params = alg[self.PARAMETERS]
                outputs = alg[self.OUTPUTS]
                column = 0
                for param in self.alg.parameterDefinitions():
                    if param.flags() & QgsProcessingParameterDefinition.FlagHidden:
                        continue
                    if param.isDestination():
                        continue
                    if param.name() in params:
                        value = eval(params[param.name()])
                        wrapper = self.wrappers[row][column]
                        wrapper.setParameterValue(value, context)
                    column += 1

                for out in self.alg.destinationParameterDefinitions():
                    if out.flags() & QgsProcessingParameterDefinition.FlagHidden:
                        continue
                    if out.name() in outputs:
                        value = outputs[out.name()].strip("'")
                        widget = self.tblParameters.cellWidget(row, column)
                        widget.setValue(value)
                    column += 1
        except TypeError:
            QMessageBox.critical(
                self,
                self.tr('Error'),
                self.tr('An error occurred while reading your file.'))
开发者ID:uclaros,项目名称:QGIS,代码行数:49,代码来源:BatchPanel.py

示例12: openScriptFile

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
    def openScriptFile(self):
        lastDirPath = self.settings.value("pythonConsole/lastDirPath", QDir.homePath())
        openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
        fileList, selected_filter = QFileDialog.getOpenFileNames(
            self, openFileTr, lastDirPath, "Script file (*.py)")
        if fileList:
            for pyFile in fileList:
                for i in range(self.tabEditorWidget.count()):
                    tabWidget = self.tabEditorWidget.widget(i)
                    if tabWidget.path == pyFile:
                        self.tabEditorWidget.setCurrentWidget(tabWidget)
                        break
                else:
                    tabName = QFileInfo(pyFile).fileName()
                    self.tabEditorWidget.newTabEditor(tabName, pyFile)

                    lastDirPath = QFileInfo(pyFile).path()
                    self.settings.setValue("pythonConsole/lastDirPath", pyFile)
                    self.updateTabListScript(pyFile, action='append')
开发者ID:CS-SI,项目名称:QGIS,代码行数:21,代码来源:console.py

示例13: last_icon_path

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
 def last_icon_path(cls):
     return cls.get_settings().value('last_icon_path', QDir.homePath(), str)
开发者ID:nextgis,项目名称:quickmapservices,代码行数:4,代码来源:plugin_settings.py

示例14: outFile

# 需要导入模块: from qgis.PyQt.QtCore import QDir [as 别名]
# 或者: from qgis.PyQt.QtCore.QDir import homePath [as 别名]
 def outFile(self):
     of = QFileInfo(QFileDialog.getSaveFileName(self, 'Output map file', QDir.homePath(), 'PDF files (*.pdf)'))
     f = of.fileName()
     if f!='':
         self.lineEdit_3.setText(of.absoluteFilePath())
     return f
开发者ID:IZSVenezie,项目名称:VetEpiGIS-Tool,代码行数:8,代码来源:xprint.py


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