本文整理汇总了Python中qgis.PyQt.QtCore.QDir类的典型用法代码示例。如果您正苦于以下问题:Python QDir类的具体用法?Python QDir怎么用?Python QDir使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QDir类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: getAllInstalled
def getAllInstalled(self):
""" Build the localCache """
self.localCache = {}
# reversed list of the plugin paths: first system plugins -> then user plugins -> finally custom path(s)
pluginPaths = list(plugin_paths)
pluginPaths.reverse()
for pluginsPath in pluginPaths:
isTheSystemDir = (pluginPaths.index(pluginsPath) == 0) # The current dir is the system plugins dir
if isTheSystemDir:
# temporarily add the system path as the first element to force loading the readonly plugins, even if masked by user ones.
sys.path = [pluginsPath] + sys.path
try:
pluginDir = QDir(pluginsPath)
pluginDir.setFilter(QDir.AllDirs)
for key in pluginDir.entryList():
if key not in [".", ".."]:
path = QDir.toNativeSeparators(pluginsPath + "/" + key)
# readOnly = not QFileInfo(pluginsPath).isWritable() # On windows testing the writable status isn't reliable.
readOnly = isTheSystemDir # Assume only the system plugins are not writable.
# failedToLoad = settings.value("/PythonPlugins/watchDog/" + key) is not None
plugin = self.getInstalledPlugin(key, path=path, readOnly=readOnly)
if key in list(self.localCache.keys()) and compareVersions(self.localCache[key]["version_installed"], plugin["version_installed"]) == 1:
# An obsolete plugin in the "user" location is masking a newer one in the "system" location!
self.obsoletePlugins += [key]
self.localCache[key] = plugin
except:
# it's not necessary to stop if one of the dirs is inaccessible
pass
if isTheSystemDir:
# remove the temporarily added path
sys.path.remove(pluginsPath)
开发者ID:AlisterH,项目名称:Quantum-GIS,代码行数:34,代码来源:installer_data.py
示例2: __init__
def __init__(self, parent, plugin):
QDialog.__init__(self, parent)
self.setupUi(self)
self.plugin = plugin
self.mResult = ""
self.progressBar.setRange(0, 0)
self.progressBar.setFormat("%p%")
self.labelName.setText(plugin["name"])
self.buttonBox.clicked.connect(self.abort)
url = QUrl(plugin["download_url"])
fileName = plugin["filename"]
tmpDir = QDir.tempPath()
tmpPath = QDir.cleanPath(tmpDir + "/" + fileName)
self.file = QFile(tmpPath)
self.request = QNetworkRequest(url)
authcfg = repositories.all()[plugin["zip_repository"]]["authcfg"]
if authcfg and isinstance(authcfg, str):
if not QgsAuthManager.instance().updateNetworkRequest(
self.request, authcfg.strip()):
self.mResult = self.tr(
"Update of network request with authentication "
"credentials FAILED for configuration '{0}'").format(authcfg)
self.request = None
if self.request is not None:
self.reply = QgsNetworkAccessManager.instance().get(self.request)
self.reply.downloadProgress.connect(self.readProgress)
self.reply.finished.connect(self.requestFinished)
self.stateChanged(4)
开发者ID:GeoCat,项目名称:QGIS,代码行数:33,代码来源:qgsplugininstallerinstallingdialog.py
示例3: testLayout
def testLayout(self, page=0, pixelDiff=0):
if self.layout is None:
myMessage = "Layout not valid"
return False, myMessage
# load expected image
self.setControlName("expected_" + self.test_name)
# get width/height, create image and render the composition to it
outputImage = QImage(self.size, QImage.Format_RGB32)
outputImage.setDotsPerMeterX(self.dots_per_meter)
outputImage.setDotsPerMeterY(self.dots_per_meter)
QgsMultiRenderChecker.drawBackground(outputImage)
p = QPainter(outputImage)
self.layout.exporter().renderPage(p, page)
p.end()
renderedFilePath = QDir.tempPath() + QDir.separator() + QFileInfo(self.test_name).baseName() + "_rendered.png"
outputImage.save(renderedFilePath, "PNG")
self.setRenderedImage(renderedFilePath)
testResult = self.runTest(self.test_name, pixelDiff)
return testResult, self.report()
开发者ID:cz172638,项目名称:QGIS,代码行数:26,代码来源:qgslayoutchecker.py
示例4: copyFile
def copyFile(alg, fromFile, toFile):
""" Generates a copy command for GRASS7 script """
createDestDir(alg, toFile)
command = "{} \"{}\" \"{}\"".format(
"COPY /Y" if isWindows() else "cp -f",
QDir.toNativeSeparators(fromFile),
QDir.toNativeSeparators(toFile))
alg.commands.append(command)
开发者ID:borysiasty,项目名称:QGIS,代码行数:8,代码来源:i.py
示例5: moveFile
def moveFile(alg, fromFile, toFile):
""" Generates a move command for GRASS7 script """
createDestDir(alg, toFile)
command = "{} \"{}\" \"{}\"".format(
"MOVE /Y" if isWindows() else "mv -f",
QDir.toNativeSeparators(fromFile),
QDir.toNativeSeparators(toFile)
)
alg.commands.append(command)
开发者ID:borysiasty,项目名称:QGIS,代码行数:9,代码来源:i.py
示例6: selectDirectory
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,代码行数:11,代码来源:DestinationSelectionPanel.py
示例7: requestFinished
def requestFinished(self):
reply = self.sender()
self.buttonBox.setEnabled(False)
if reply.error() != QNetworkReply.NoError:
self.mResult = reply.errorString()
if reply.error() == QNetworkReply.OperationCanceledError:
self.mResult += "<br/><br/>" + QCoreApplication.translate("QgsPluginInstaller", "If you haven't canceled the download manually, it might be caused by a timeout. In this case consider increasing the connection timeout value in QGIS options.")
self.reject()
reply.deleteLater()
return
elif reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) in (301, 302):
redirectionUrl = reply.attribute(QNetworkRequest.RedirectionTargetAttribute)
self.redirectionCounter += 1
if self.redirectionCounter > 4:
self.mResult = QCoreApplication.translate("QgsPluginInstaller", "Too many redirections")
self.reject()
reply.deleteLater()
return
else:
if redirectionUrl.isRelative():
redirectionUrl = reply.url().resolved(redirectionUrl)
# Fire a new request and exit immediately in order to quietly destroy the old one
self.url = redirectionUrl
self.requestDownloading()
reply.deleteLater()
return
self.file.open(QFile.WriteOnly)
self.file.write(reply.readAll())
self.file.close()
self.stateChanged(0)
reply.deleteLater()
pluginDir = qgis.utils.home_plugin_path
tmpPath = self.file.fileName()
# make sure that the parent directory exists
if not QDir(pluginDir).exists():
QDir().mkpath(pluginDir)
# if the target directory already exists as a link, remove the link without resolving:
QFile(pluginDir + str(QDir.separator()) + self.plugin["id"]).remove()
try:
unzip(str(tmpPath), str(pluginDir)) # test extract. If fails, then exception will be raised and no removing occurs
# removing old plugin files if exist
removeDir(QDir.cleanPath(pluginDir + "/" + self.plugin["id"])) # remove old plugin if exists
unzip(str(tmpPath), str(pluginDir)) # final extract.
except:
self.mResult = self.tr("Failed to unzip the plugin package. Probably it's broken or missing from the repository. You may also want to make sure that you have write permission to the plugin directory:") + "\n" + pluginDir
self.reject()
return
try:
# cleaning: removing the temporary zip file
QFile(tmpPath).remove()
except:
pass
self.close()
开发者ID:FERRATON,项目名称:QGIS,代码行数:54,代码来源:qgsplugininstallerinstallingdialog.py
示例8: selectDirectory
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,代码行数:14,代码来源:DestinationSelectionPanel.py
示例9: saveAsScriptFile
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,代码行数:32,代码来源:console.py
示例10: testInteger64WriteTabfile
def testInteger64WriteTabfile(self):
"""Check writing Integer64 fields to an MapInfo tabfile (which does not support that type)."""
ml = QgsVectorLayer(("Point?crs=epsg:4326&field=int8:int8"), "test", "memory")
self.assertIsNotNone(ml, "Provider not initialized")
self.assertTrue(ml.isValid(), "Source layer not valid")
provider = ml.dataProvider()
self.assertIsNotNone(provider)
ft = QgsFeature()
ft.setAttributes([2123456789])
res, features = provider.addFeatures([ft])
self.assertTrue(res)
self.assertTrue(features)
dest_file_name = os.path.join(str(QDir.tempPath()), "integer64.tab")
crs = QgsCoordinateReferenceSystem()
crs.createFromId(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
write_result = QgsVectorFileWriter.writeAsVectorFormat(ml, dest_file_name, "utf-8", crs, "MapInfo File")
self.assertEqual(write_result, QgsVectorFileWriter.NoError)
# Open result and check
created_layer = QgsVectorLayer("{}|layerid=0".format(dest_file_name), "test", "ogr")
fields = created_layer.dataProvider().fields()
self.assertEqual(fields.at(fields.indexFromName("int8")).type(), QVariant.Double)
f = next(created_layer.getFeatures(QgsFeatureRequest()))
int8_idx = created_layer.fields().lookupField("int8")
self.assertEqual(f.attributes()[int8_idx], 2123456789)
开发者ID:liminlu0314,项目名称:QGIS,代码行数:31,代码来源:test_qgsvectorfilewriter.py
示例11: testValueConverter
def testValueConverter(self):
"""Tests writing a layer with a field value converter."""
ml = QgsVectorLayer(("Point?field=nonconv:int&field=ignored:string&field=converted:int"), "test", "memory")
self.assertIsNotNone(ml, "Provider not initialized")
self.assertTrue(ml.isValid(), "Source layer not valid")
provider = ml.dataProvider()
self.assertIsNotNone(provider)
self.assertEqual(ml.fields().count(), 3)
ft = QgsFeature()
ft.setAttributes([1, "ignored", 3])
res, features = provider.addFeatures([ft])
self.assertTrue(res)
self.assertTrue(features)
dest_file_name = os.path.join(str(QDir.tempPath()), "value_converter.shp")
converter = TestFieldValueConverter(ml)
write_result = QgsVectorFileWriter.writeAsVectorFormat(
ml,
dest_file_name,
"utf-8",
QgsCoordinateReferenceSystem(),
"ESRI Shapefile",
attributes=[0, 2],
fieldValueConverter=converter,
)
self.assertEqual(write_result, QgsVectorFileWriter.NoError)
# Open result and check
created_layer = QgsVectorLayer("{}|layerid=0".format(dest_file_name), "test", "ogr")
self.assertEqual(created_layer.fields().count(), 2)
f = next(created_layer.getFeatures(QgsFeatureRequest()))
self.assertEqual(f["nonconv"], 1)
self.assertEqual(f["conv_attr"], "converted_val")
开发者ID:liminlu0314,项目名称:QGIS,代码行数:35,代码来源:test_qgsvectorfilewriter.py
示例12: testWriteShapefileWithMultiConversion
def testWriteShapefileWithMultiConversion(self):
"""Check writing geometries to an ESRI shapefile with conversion to multi."""
ml = QgsVectorLayer(("Point?crs=epsg:4326&field=id:int"), "test", "memory")
self.assertIsNotNone(ml, "Provider not initialized")
self.assertTrue(ml.isValid(), "Source layer not valid")
provider = ml.dataProvider()
self.assertIsNotNone(provider)
ft = QgsFeature()
ft.setGeometry(QgsGeometry.fromWkt("Point (1 2)"))
ft.setAttributes([1])
res, features = provider.addFeatures([ft])
self.assertTrue(res)
self.assertTrue(features)
dest_file_name = os.path.join(str(QDir.tempPath()), "to_multi.shp")
crs = QgsCoordinateReferenceSystem()
crs.createFromId(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
write_result = QgsVectorFileWriter.writeAsVectorFormat(
ml, dest_file_name, "utf-8", crs, "ESRI Shapefile", forceMulti=True
)
self.assertEqual(write_result, QgsVectorFileWriter.NoError)
# Open result and check
created_layer = QgsVectorLayer("{}|layerid=0".format(dest_file_name), "test", "ogr")
f = next(created_layer.getFeatures(QgsFeatureRequest()))
g = f.geometry()
wkt = g.exportToWkt()
expWkt = "MultiPoint ((1 2))"
self.assertTrue(
compareWkt(expWkt, wkt),
"saving geometry with multi conversion failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt),
)
开发者ID:liminlu0314,项目名称:QGIS,代码行数:34,代码来源:test_qgsvectorfilewriter.py
示例13: selFile
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,代码行数:7,代码来源:xprint.py
示例14: testQgsCentroidFillSymbolLayerV2
def testQgsCentroidFillSymbolLayerV2(self):
"""
Create a new style from a .sld file and match test
"""
mTestName = 'QgsCentroidFillSymbolLayerV2'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
mDoc = QDomDocument(mTestName)
mFile = QFile(mFilePath)
mFile.open(QIODevice.ReadOnly)
mDoc.setContent(mFile, True)
mFile.close()
mSymbolLayer = QgsCentroidFillSymbolLayerV2.createFromSld(
mDoc.elementsByTagName('PointSymbolizer').item(0).toElement())
mExpectedValue = type(QgsCentroidFillSymbolLayerV2())
mValue = type(mSymbolLayer)
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = u'regular_star'
mValue = mSymbolLayer.subSymbol().symbolLayer(0).name()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = u'#55aaff'
mValue = mSymbolLayer.subSymbol().symbolLayer(0).color().name()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = u'#00ff00'
mValue = mSymbolLayer.subSymbol().symbolLayer(0).borderColor().name()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
开发者ID:PeterTFS,项目名称:QGIS,代码行数:34,代码来源:test_qgssymbollayerv2.py
示例15: __init__
def __init__(self, obsids=[''], settingsdict = {}):
reportfolder = os.path.join(QDir.tempPath(), 'midvatten_reports')
if not os.path.exists(reportfolder):
os.makedirs(reportfolder)
reportpath = os.path.join(reportfolder, "drill_report.html")
logopath = os.path.join(os.sep,os.path.dirname(__file__),"..","templates","midvatten_logga.png")
imgpath = os.path.join(os.sep,os.path.dirname(__file__),"..","templates")
if len(obsids) == 0:
utils.pop_up_info(ru(QCoreApplication.translate('Drillreport', "Must select one or more obsids!")))
return None
elif len(obsids) == 1:
merged_question = False
else:
#Due to problems regarding speed when opening many tabs, only the merge mode is used.
#merged_question = utils.Askuser(question='YesNo', msg="Do you want to open all drill reports merged on the same tab?\n"
# "Else they will be opened separately.\n\n(If answering no, creating drill reports for many obsids take 0.2 seconds per obsid.\nIt might fail if the computer is to slow.\nIf it fails, try to select only one obsid at the time)").result
merged_question = True
if merged_question:
f, rpt = self.open_file(', '.join(obsids), reportpath)
for obsid in obsids:
self.write_obsid(obsid, rpt, imgpath, logopath, f)
self.close_file(f, reportpath)
else:
#opened = False
for obsid in obsids:
f, rpt = self.open_file(obsid, reportpath)
self.write_obsid(obsid, rpt, imgpath, logopath, f)
url_status = self.close_file(f, reportpath)
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:31,代码来源:drillreport.py
示例16: on_btnSave_clicked
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,代码行数:27,代码来源:ReliefColorsWidget.py
示例17: main
def main():
datestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
if QT5:
ini_out_dir = QStandardPaths.writableLocation(QStandardPaths.DesktopLocation)
else:
ini_out_dir = QDesktopServices.storageLocation(QDesktopServices.DesktopLocation)
ini_name = 'org.qgis.{0}-settings_{1}.ini'.format(QGIS_APP_NAME, datestamp)
ini_out = QDir(ini_out_dir).absoluteFilePath(ini_name)
if not os.path.exists(ini_out_dir):
print('INI output directory does not exist: {0}'.format(ini_out_dir))
return
if not os.access(ini_out_dir, os.W_OK | os.X_OK):
print('INI output directory is not writeable: {0}'.format(ini_out_dir))
return
# QGIS settings
if HAS_QGSSETTINGS:
qgis_settings = QgsSettings()
else:
qgis_settings = QSettings()
# Output INI settings
ini_settings = QSettings(ini_out, QSettings.IniFormat)
qgis_keys = qgis_settings.allKeys()
for k in qgis_keys:
ini_settings.setValue(k, qgis_settings.value(k))
ini_settings.sync()
print("Settings output to: {0}".format(QDir.toNativeSeparators(ini_out)))
开发者ID:boundlessgeo,项目名称:desktop-documentation,代码行数:33,代码来源:qgis-settings-to-ini.py
示例18: on_btnSave_clicked
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,代码行数:28,代码来源:ReliefColorsWidget.py
示例19: testWriteWithBinaryField
def testWriteWithBinaryField(self):
"""
Test writing with a binary field
:return:
"""
basetestpath = tempfile.mkdtemp()
tmpfile = os.path.join(basetestpath, 'binaryfield.sqlite')
ds = ogr.GetDriverByName('SQLite').CreateDataSource(tmpfile)
lyr = ds.CreateLayer('test', geom_type=ogr.wkbPoint, options=['FID=fid'])
lyr.CreateField(ogr.FieldDefn('strfield', ogr.OFTString))
lyr.CreateField(ogr.FieldDefn('intfield', ogr.OFTInteger))
lyr.CreateField(ogr.FieldDefn('binfield', ogr.OFTBinary))
lyr.CreateField(ogr.FieldDefn('binfield2', ogr.OFTBinary))
f = None
ds = None
vl = QgsVectorLayer(tmpfile)
self.assertTrue(vl.isValid())
# check that 1 of its fields is a bool
fields = vl.fields()
self.assertEqual(fields.at(fields.indexFromName('binfield')).type(), QVariant.ByteArray)
dp = vl.dataProvider()
f = QgsFeature(fields)
bin_1 = b'xxx'
bin_2 = b'yyy'
bin_val1 = QByteArray(bin_1)
bin_val2 = QByteArray(bin_2)
f.setAttributes([1, 'str', 100, bin_val1, bin_val2])
self.assertTrue(dp.addFeature(f))
# write a gpkg package with a binary field
filename = os.path.join(str(QDir.tempPath()), 'with_bin_field')
rc, errmsg = QgsVectorFileWriter.writeAsVectorFormat(vl,
filename,
'utf-8',
vl.crs(),
'GPKG')
self.assertEqual(rc, QgsVectorFileWriter.NoError)
# open the resulting geopackage
vl = QgsVectorLayer(filename + '.gpkg', '', 'ogr')
self.assertTrue(vl.isValid())
fields = vl.fields()
# test type of converted field
idx = fields.indexFromName('binfield')
self.assertEqual(fields.at(idx).type(), QVariant.ByteArray)
idx2 = fields.indexFromName('binfield2')
self.assertEqual(fields.at(idx2).type(), QVariant.ByteArray)
# test values
self.assertEqual(vl.getFeature(1).attributes()[idx], bin_val1)
self.assertEqual(vl.getFeature(1).attributes()[idx2], bin_val2)
del vl
os.unlink(filename + '.gpkg')
开发者ID:boundlessgeo,项目名称:QGIS,代码行数:60,代码来源:test_qgsvectorfilewriter.py
示例20: on_btnLoad_clicked
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,代码行数:29,代码来源:ReliefColorsWidget.py
注:本文中的qgis.PyQt.QtCore.QDir类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论