本文整理汇总了Python中qgis.core.QgsApplication.translate方法的典型用法代码示例。如果您正苦于以下问题:Python QgsApplication.translate方法的具体用法?Python QgsApplication.translate怎么用?Python QgsApplication.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsApplication
的用法示例。
在下文中一共展示了QgsApplication.translate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resetScriptFolder
# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import translate [as 别名]
def resetScriptFolder(folder):
"""Check if script folder exist. If not, notify and try to check if it is absolute to another user setting.
If so, modify folder to change user setting to the current user setting."""
newFolder = folder
if os.path.exists(newFolder):
return newFolder
QgsMessageLog.logMessage(QgsApplication .translate("loadAlgorithms", "Script folder {} does not exist").format(newFolder),
QgsApplication.translate("loadAlgorithms", "Processing"),
Qgis.Warning)
if not os.path.isabs(newFolder):
return None
# try to check if folder is absolute to other QgsApplication.qgisSettingsDirPath()
# isolate "QGIS3/profiles/"
appIndex = -4
profileIndex = -3
currentSettingPath = QgsApplication.qgisSettingsDirPath()
paths = currentSettingPath.split(os.sep)
commonSettingPath = os.path.join(paths[appIndex], paths[profileIndex])
if commonSettingPath in newFolder:
# strip not common folder part. e.g. preserve the profile path
# stripping the heading part that come from another location
tail = newFolder[newFolder.find(commonSettingPath):]
# tail folder with the actual userSetting path
header = os.path.join(os.sep, os.path.join(*paths[:appIndex]))
newFolder = os.path.join(header, tail)
# skip if it does not exist
if not os.path.exists(newFolder):
return None
QgsMessageLog.logMessage(QgsApplication .translate("loadAlgorithms", "Script folder changed into {}").format(newFolder),
QgsApplication.translate("loadAlgorithms", "Processing"),
Qgis.Warning)
return newFolder