本文整理汇总了Python中PyQt.QtCore.QSettings.setValue方法的典型用法代码示例。如果您正苦于以下问题:Python QSettings.setValue方法的具体用法?Python QSettings.setValue怎么用?Python QSettings.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt.QtCore.QSettings
的用法示例。
在下文中一共展示了QSettings.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def execute(self):
settings = QSettings()
lastDir = settings.value('Processing/lastModelsDir', '')
filename = QFileDialog.getOpenFileName(self.toolbox,
self.tr('Open model', 'AddModelFromFileAction'), lastDir,
self.tr('Processing model files (*.model *.MODEL)', 'AddModelFromFileAction'))
if filename:
try:
settings.setValue('Processing/lastModelsDir',
QFileInfo(filename).absoluteDir().absolutePath())
ModelerAlgorithm.fromFile(filename)
except WrongModelException:
QMessageBox.warning(
self.toolbox,
self.tr('Error reading model', 'AddModelFromFileAction'),
self.tr('The selected file does not contain a valid model', 'AddModelFromFileAction'))
return
except:
QMessageBox.warning(self.toolbox,
self.tr('Error reading model', 'AddModelFromFileAction'),
self.tr('Cannot read file', 'AddModelFromFileAction'))
return
destFilename = os.path.join(ModelerUtils.modelsFolder(), os.path.basename(filename))
shutil.copyfile(filename, destFilename)
self.toolbox.updateProvider('model')
示例2: showSelectionDialog
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def showSelectionDialog(self):
# Find the file dialog's working directory
settings = QSettings()
text = self.leText.text()
if os.path.isdir(text):
path = text
elif os.path.isdir(os.path.dirname(text)):
path = os.path.dirname(text)
elif settings.contains('/Processing/LastInputPath'):
path = settings.value('/Processing/LastInputPath')
else:
path = ''
if self.isFolder:
folder = QFileDialog.getExistingDirectory(self,
self.tr('Select folder'), path)
if folder:
self.leText.setText(folder)
settings.setValue('/Processing/LastInputPath',
os.path.dirname(folder))
else:
filenames = QFileDialog.getOpenFileNames(self,
self.tr('Select file'), path, '*.' + self.ext)
if filenames:
self.leText.setText(u';'.join(filenames))
settings.setValue('/Processing/LastInputPath',
os.path.dirname(filenames[0]))
示例3: chooseOutputFile
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def chooseOutputFile(self):
# get last used dir
settings = QSettings()
lastUsedDir = settings.value(self.lastUsedVectorDirSettingsKey, ".")
# get selected filter
selectedFilter = self.cboFileFormat.itemData(self.cboFileFormat.currentIndex())
# ask for a filename
filename = QFileDialog.getSaveFileName(self, self.tr("Choose where to save the file"), lastUsedDir,
selectedFilter)
if filename == "":
return
filterString = qgis.core.QgsVectorFileWriter.filterForDriver(selectedFilter)
ext = filterString[filterString.find('.'):]
ext = ext[:ext.find(' ')]
if not filename.lower().endswith(ext):
filename += ext
# store the last used dir
settings.setValue(self.lastUsedVectorDirSettingsKey, QFileInfo(filename).filePath())
self.editOutputFile.setText(filename)
示例4: selectFile
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def selectFile(self):
fileFilter = self.output.getFileFilter(self.alg)
settings = QSettings()
if settings.contains('/Processing/LastOutputPath'):
path = settings.value('/Processing/LastOutputPath')
else:
path = ProcessingConfig.getSetting(ProcessingConfig.OUTPUT_FOLDER)
encoding = settings.value('/Processing/encoding', 'System')
fileDialog = QgsEncodingFileDialog(
self, self.tr('Save file'), path, fileFilter, encoding)
fileDialog.setFileMode(QFileDialog.AnyFile)
fileDialog.setAcceptMode(QFileDialog.AcceptSave)
fileDialog.setConfirmOverwrite(True)
if fileDialog.exec_() == QDialog.Accepted:
files = fileDialog.selectedFiles()
encoding = unicode(fileDialog.encoding())
self.output.encoding = encoding
fileName = unicode(files[0])
selectedFileFilter = unicode(fileDialog.selectedNameFilter())
if not fileName.lower().endswith(
tuple(re.findall("\*(\.[a-z]{1,10})", fileFilter))):
ext = re.search("\*(\.[a-z]{1,10})", selectedFileFilter)
if ext:
fileName += ext.group(1)
self.leText.setText(fileName)
settings.setValue('/Processing/LastOutputPath',
os.path.dirname(fileName))
settings.setValue('/Processing/encoding', encoding)
示例5: showFileSelectionDialog
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def showFileSelectionDialog(self):
settings = QSettings()
text = unicode(self.text.text())
if os.path.isdir(text):
path = text
elif os.path.isdir(os.path.dirname(text)):
path = os.path.dirname(text)
elif settings.contains('/Processing/LastInputPath'):
path = unicode(settings.value('/Processing/LastInputPath'))
else:
path = ''
ret = QFileDialog.getOpenFileNames(self, self.tr('Open file'), path,
self.tr('All files(*.*);;') + self.param.getFileFilter())
if ret:
files = list(ret)
settings.setValue('/Processing/LastInputPath',
os.path.dirname(unicode(files[0])))
for i, filename in enumerate(files):
files[i] = dataobjects.getRasterSublayer(filename, self.param)
if len(files) == 1:
self.text.setText(files[0])
else:
if isinstance(self.param, ParameterMultipleInput):
self.text.setText(';'.join(unicode(f) for f in files))
else:
rowdif = len(files) - (self.table.rowCount() - self.row)
for i in range(rowdif):
self.panel.addRow()
for i, f in enumerate(files):
self.table.cellWidget(i + self.row,
self.col).setText(f)
示例6: load
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def load(self):
""" populate the mRepositories dict"""
self.mRepositories = {}
settings = QSettings()
settings.beginGroup(reposGroup)
# first, update repositories in QSettings if needed
officialRepoPresent = False
for key in settings.childGroups():
url = settings.value(key + "/url", "", type=unicode)
if url == officialRepo[1]:
officialRepoPresent = True
if url == officialRepo[2]:
settings.setValue(key + "/url", officialRepo[1]) # correct a depreciated url
officialRepoPresent = True
if not officialRepoPresent:
settings.setValue(officialRepo[0] + "/url", officialRepo[1])
for key in settings.childGroups():
self.mRepositories[key] = {}
self.mRepositories[key]["url"] = settings.value(key + "/url", "", type=unicode)
self.mRepositories[key]["authcfg"] = settings.value(key + "/authcfg", "", type=unicode)
self.mRepositories[key]["enabled"] = settings.value(key + "/enabled", True, type=bool)
self.mRepositories[key]["valid"] = settings.value(key + "/valid", True, type=bool)
self.mRepositories[key]["Relay"] = Relay(key)
self.mRepositories[key]["xmlData"] = None
self.mRepositories[key]["state"] = 0
self.mRepositories[key]["error"] = ""
settings.endGroup()
示例7: saveToSpatialite
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def saveToSpatialite(self):
fileFilter = self.output.tr('Spatialite files(*.sqlite)', 'OutputFile')
settings = QSettings()
if settings.contains('/Processing/LastOutputPath'):
path = settings.value('/Processing/LastOutputPath')
else:
path = ProcessingConfig.getSetting(ProcessingConfig.OUTPUT_FOLDER)
encoding = settings.value('/Processing/encoding', 'System')
fileDialog = QgsEncodingFileDialog(
self, self.tr('Save Spatialite'), path, fileFilter, encoding)
fileDialog.setFileMode(QFileDialog.AnyFile)
fileDialog.setAcceptMode(QFileDialog.AcceptSave)
fileDialog.setConfirmOverwrite(False)
if fileDialog.exec_() == QDialog.Accepted:
files = fileDialog.selectedFiles()
encoding = unicode(fileDialog.encoding())
self.output.encoding = encoding
fileName = unicode(files[0])
selectedFileFilter = unicode(fileDialog.selectedNameFilter())
if not fileName.lower().endswith(
tuple(re.findall("\*(\.[a-z]{1,10})", fileFilter))):
ext = re.search("\*(\.[a-z]{1,10})", selectedFileFilter)
if ext:
fileName += ext.group(1)
settings.setValue('/Processing/LastOutputPath',
os.path.dirname(fileName))
settings.setValue('/Processing/encoding', encoding)
uri = QgsDataSourceURI()
uri.setDatabase(fileName)
uri.setDataSource('', self.output.name.lower(), 'the_geom')
self.leText.setText("spatialite:" + uri.uri())
示例8: setLastUsedDir
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def setLastUsedDir(filePath):
settings = QSettings()
fileInfo = QFileInfo(filePath)
if fileInfo.isDir():
dirPath = fileInfo.filePath()
else:
dirPath = fileInfo.path()
settings.setValue("/GdalTools/lastUsedDir", dirPath)
示例9: updateSeenPluginsList
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def updateSeenPluginsList(self):
""" update the list of all seen plugins """
settings = QSettings()
seenPlugins = settings.value(seenPluginGroup, self.mPlugins.keys(), type=unicode)
for i in self.mPlugins.keys():
if seenPlugins.count(i) == 0:
seenPlugins += [i]
settings.setValue(seenPluginGroup, seenPlugins)
示例10: NewConnectionDialog
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
class NewConnectionDialog(QDialog, BASE_CLASS):
"""Dialogue to add a new CSW entry"""
def __init__(self, conn_name=None):
"""init"""
QDialog.__init__(self)
self.setupUi(self)
self.settings = QSettings()
self.conn_name = None
self.conn_name_orig = conn_name
def accept(self):
"""add CSW entry"""
conn_name = self.leName.text().strip()
conn_url = self.leURL.text().strip()
if any([conn_name == '', conn_url == '']):
QMessageBox.warning(self, self.tr('Save connection'),
self.tr('Both Name and URL must be provided'))
return
if '/' in conn_name:
QMessageBox.warning(self, self.tr('Save connection'),
self.tr('Name cannot contain \'/\''))
return
if conn_name is not None:
key = '/MetaSearch/%s' % conn_name
keyurl = '%s/url' % key
key_orig = '/MetaSearch/%s' % self.conn_name_orig
# warn if entry was renamed to an existing connection
if all([self.conn_name_orig != conn_name,
self.settings.contains(keyurl)]):
res = QMessageBox.warning(self, self.tr('Save connection'),
self.tr('Overwrite %s?') % conn_name,
QMessageBox.Ok | QMessageBox.Cancel)
if res == QMessageBox.Cancel:
return
# on rename delete original entry first
if all([self.conn_name_orig is not None,
self.conn_name_orig != conn_name]):
self.settings.remove(key_orig)
self.settings.setValue(keyurl, conn_url)
self.settings.setValue('/MetaSearch/selected', conn_name)
QDialog.accept(self)
def reject(self):
"""back out of dialogue"""
QDialog.reject(self)
示例11: loadAPIFile
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def loadAPIFile(self):
settings = QSettings()
lastDirPath = settings.value("pythonConsole/lastDirAPIPath", "", type=str)
fileAPI = QFileDialog.getOpenFileName(
self, "Open API File", lastDirPath, "API file (*.api)")
if fileAPI:
self.addAPI(fileAPI)
lastDirPath = QFileInfo(fileAPI).path()
settings.setValue("pythonConsole/lastDirAPIPath", fileAPI)
示例12: closeEvent
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def closeEvent(self, e):
self.unregisterAllActions()
# clear preview, this will delete the layer in preview tab
self.preview.loadPreview(None)
# save the window state
settings = QSettings()
settings.setValue("/DB_Manager/mainWindow/windowState", self.saveState())
settings.setValue("/DB_Manager/mainWindow/geometry", self.saveGeometry())
QMainWindow.closeEvent(self, e)
示例13: processAlgorithm
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def processAlgorithm(self, progress):
settings = QSettings()
initial_method_setting = settings.value(settings_method_key, 1)
method = self.getParameterValue(self.METHOD)
if method != 0:
settings.setValue(settings_method_key, method)
try:
self.doCheck(progress)
finally:
settings.setValue(settings_method_key, initial_method_setting)
示例14: selectDirectory
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def selectDirectory(self):
settings = QSettings()
if settings.contains('/Processing/LastBatchOutputPath'):
lastDir = unicode(settings.value('/Processing/LastBatchOutputPath'))
else:
lastDir = ''
dirName = QFileDialog.getExistingDirectory(self,
self.tr('Select directory'), lastDir, QFileDialog.ShowDirsOnly)
if dirName:
self.table.cellWidget(self.row, self.col).setValue(dirName)
settings.setValue('/Processing/LastBatchOutputPath', dirName)
示例15: chooseInputFile
# 需要导入模块: from PyQt.QtCore import QSettings [as 别名]
# 或者: from PyQt.QtCore.QSettings import setValue [as 别名]
def chooseInputFile(self):
vectorFormats = qgis.core.QgsProviderRegistry.instance().fileVectorFilters()
# get last used dir and format
settings = QSettings()
lastDir = settings.value("/db_manager/lastUsedDir", "")
lastVectorFormat = settings.value("/UI/lastVectorFileFilter", "")
# ask for a filename
(filename, lastVectorFormat) = QFileDialog.getOpenFileNameAndFilter(self, self.tr("Choose the file to import"),
lastDir, vectorFormats, lastVectorFormat)
if filename == "":
return
# store the last used dir and format
settings.setValue("/db_manager/lastUsedDir", QFileInfo(filename).filePath())
settings.setValue("/UI/lastVectorFileFilter", lastVectorFormat)
self.cboInputLayer.setEditText(filename)