2012-10-05 23:28:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
2013-08-12 20:44:27 +02:00
|
|
|
ProcessingConfig.py
|
2012-10-05 23:28:47 +02:00
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2016-09-21 18:24:26 +02:00
|
|
|
from builtins import str
|
|
|
|
from builtins import object
|
2012-10-05 23:28:47 +02:00
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-05 23:28:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-05 23:28:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
import os
|
|
|
|
|
2016-05-13 17:49:09 +02:00
|
|
|
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QObject, pyqtSignal
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtGui import QIcon
|
2017-01-12 12:51:08 +02:00
|
|
|
from qgis.core import NULL, QgsApplication
|
2015-11-05 09:16:00 +01:00
|
|
|
from processing.tools.system import defaultOutputFolder
|
2017-01-12 14:49:26 +02:00
|
|
|
import processing.tools.dataobjects
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2016-04-27 15:40:56 +03:00
|
|
|
|
2016-04-27 13:36:28 +02:00
|
|
|
class SettingsWatcher(QObject):
|
|
|
|
|
|
|
|
settingsChanged = pyqtSignal()
|
|
|
|
|
|
|
|
settingsWatcher = SettingsWatcher()
|
|
|
|
|
2015-10-30 23:30:16 +01:00
|
|
|
|
2016-09-21 18:24:26 +02:00
|
|
|
class ProcessingConfig(object):
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2015-11-05 09:16:00 +01:00
|
|
|
OUTPUT_FOLDER = 'OUTPUTS_FOLDER'
|
2013-10-01 20:52:22 +03:00
|
|
|
RASTER_STYLE = 'RASTER_STYLE'
|
|
|
|
VECTOR_POINT_STYLE = 'VECTOR_POINT_STYLE'
|
|
|
|
VECTOR_LINE_STYLE = 'VECTOR_LINE_STYLE'
|
|
|
|
VECTOR_POLYGON_STYLE = 'VECTOR_POLYGON_STYLE'
|
|
|
|
SHOW_RECENT_ALGORITHMS = 'SHOW_RECENT_ALGORITHMS'
|
|
|
|
USE_SELECTED = 'USE_SELECTED'
|
2016-12-15 09:43:31 +01:00
|
|
|
FILTER_INVALID_GEOMETRIES = 'FILTER_INVALID_GEOMETRIES'
|
2013-10-01 20:52:22 +03:00
|
|
|
USE_FILENAME_AS_LAYER_NAME = 'USE_FILENAME_AS_LAYER_NAME'
|
|
|
|
KEEP_DIALOG_OPEN = 'KEEP_DIALOG_OPEN'
|
|
|
|
SHOW_DEBUG_IN_DIALOG = 'SHOW_DEBUG_IN_DIALOG'
|
|
|
|
RECENT_ALGORITHMS = 'RECENT_ALGORITHMS'
|
|
|
|
PRE_EXECUTION_SCRIPT = 'PRE_EXECUTION_SCRIPT'
|
|
|
|
POST_EXECUTION_SCRIPT = 'POST_EXECUTION_SCRIPT'
|
|
|
|
SHOW_CRS_DEF = 'SHOW_CRS_DEF'
|
|
|
|
WARN_UNMATCHING_CRS = 'WARN_UNMATCHING_CRS'
|
2016-10-13 13:40:47 +02:00
|
|
|
WARN_UNMATCHING_EXTENT_CRS = 'WARN_UNMATCHING_EXTENT_CRS'
|
2015-10-24 21:11:46 +02:00
|
|
|
DEFAULT_OUTPUT_RASTER_LAYER_EXT = 'DEFAULT_OUTPUT_RASTER_LAYER_EXT'
|
|
|
|
DEFAULT_OUTPUT_VECTOR_LAYER_EXT = 'DEFAULT_OUTPUT_VECTOR_LAYER_EXT'
|
2017-01-10 14:17:25 +02:00
|
|
|
SHOW_PROVIDERS_TOOLTIP = 'SHOW_PROVIDERS_TOOLTIP'
|
|
|
|
MODELS_SCRIPTS_REPO = 'MODELS_SCRIPTS_REPO'
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
settings = {}
|
2013-10-01 20:52:22 +03:00
|
|
|
settingIcons = {}
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def initialize():
|
2017-01-09 12:34:46 +10:00
|
|
|
icon = QgsApplication.getThemeIcon("/processingAlgorithm.svg")
|
2013-10-01 20:52:22 +03:00
|
|
|
ProcessingConfig.settingIcons['General'] = icon
|
2015-08-22 14:29:41 +02:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.SHOW_DEBUG_IN_DIALOG,
|
|
|
|
ProcessingConfig.tr('Show extra info in Log panel'), True))
|
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.KEEP_DIALOG_OPEN,
|
|
|
|
ProcessingConfig.tr('Keep dialog open after running an algorithm'), False))
|
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.USE_SELECTED,
|
|
|
|
ProcessingConfig.tr('Use only selected features'), True))
|
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.USE_FILENAME_AS_LAYER_NAME,
|
|
|
|
ProcessingConfig.tr('Use filename as layer name'), False))
|
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.SHOW_RECENT_ALGORITHMS,
|
|
|
|
ProcessingConfig.tr('Show recently executed algorithms'), True))
|
2016-01-29 14:07:47 +01:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.SHOW_PROVIDERS_TOOLTIP,
|
|
|
|
ProcessingConfig.tr('Show tooltip when there are disabled providers'), True))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.OUTPUT_FOLDER,
|
2015-11-05 09:16:00 +01:00
|
|
|
ProcessingConfig.tr('Output folder'), defaultOutputFolder(),
|
2015-06-26 11:54:58 +02:00
|
|
|
valuetype=Setting.FOLDER))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.SHOW_CRS_DEF,
|
|
|
|
ProcessingConfig.tr('Show layer CRS definition in selection boxes'), True))
|
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.WARN_UNMATCHING_CRS,
|
|
|
|
ProcessingConfig.tr("Warn before executing if layer CRS's do not match"), True))
|
2016-10-13 13:40:47 +02:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.WARN_UNMATCHING_EXTENT_CRS,
|
|
|
|
ProcessingConfig.tr("Warn before executing if extent CRS might not match layers CRS"), True))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.RASTER_STYLE,
|
2015-10-24 21:11:46 +02:00
|
|
|
ProcessingConfig.tr('Style for raster layers'), '',
|
|
|
|
valuetype=Setting.FILE))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.VECTOR_POINT_STYLE,
|
2015-10-24 21:11:46 +02:00
|
|
|
ProcessingConfig.tr('Style for point layers'), '',
|
|
|
|
valuetype=Setting.FILE))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.VECTOR_LINE_STYLE,
|
2015-10-24 21:11:46 +02:00
|
|
|
ProcessingConfig.tr('Style for line layers'), '',
|
|
|
|
valuetype=Setting.FILE))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.VECTOR_POLYGON_STYLE,
|
2015-10-24 21:11:46 +02:00
|
|
|
ProcessingConfig.tr('Style for polygon layers'), '',
|
|
|
|
valuetype=Setting.FILE))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.PRE_EXECUTION_SCRIPT,
|
2015-10-24 21:11:46 +02:00
|
|
|
ProcessingConfig.tr('Pre-execution script'), '',
|
|
|
|
valuetype=Setting.FILE))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.POST_EXECUTION_SCRIPT,
|
2015-10-24 21:11:46 +02:00
|
|
|
ProcessingConfig.tr('Post-execution script'), '',
|
|
|
|
valuetype=Setting.FILE))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.RECENT_ALGORITHMS,
|
2016-12-21 21:06:56 +01:00
|
|
|
ProcessingConfig.tr('Recent algorithms'), '', hidden=True))
|
2017-01-10 14:17:25 +02:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.MODELS_SCRIPTS_REPO,
|
|
|
|
ProcessingConfig.tr('Scripts and models repository'),
|
|
|
|
'https://raw.githubusercontent.com/qgis/QGIS-Processing/master'))
|
2017-01-12 12:51:08 +02:00
|
|
|
|
|
|
|
invalidFeaturesOptions = [ProcessingConfig.tr('Do not filter (better performance'),
|
|
|
|
ProcessingConfig.tr('Ignore features with invalid geometries'),
|
|
|
|
ProcessingConfig.tr('Stop algorithm execution when a geometry is invalid')]
|
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.FILTER_INVALID_GEOMETRIES,
|
|
|
|
ProcessingConfig.tr('Invalid features filtering'),
|
|
|
|
invalidFeaturesOptions[2],
|
|
|
|
valuetype=Setting.SELECTION,
|
|
|
|
options=invalidFeaturesOptions))
|
|
|
|
|
2017-01-12 14:49:26 +02:00
|
|
|
extensions = processing.tools.dataobjects.getSupportedOutputVectorLayerExtensions()
|
2015-10-24 21:11:46 +02:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.DEFAULT_OUTPUT_VECTOR_LAYER_EXT,
|
2017-01-12 12:51:08 +02:00
|
|
|
ProcessingConfig.tr('Default output vector layer extension'),
|
|
|
|
extensions[0],
|
|
|
|
valuetype=Setting.SELECTION,
|
|
|
|
options=extensions))
|
|
|
|
|
2017-01-12 14:49:26 +02:00
|
|
|
extensions = processing.tools.dataobjects.getSupportedOutputRasterLayerExtensions()
|
2015-10-24 21:11:46 +02:00
|
|
|
ProcessingConfig.addSetting(Setting(
|
|
|
|
ProcessingConfig.tr('General'),
|
|
|
|
ProcessingConfig.DEFAULT_OUTPUT_RASTER_LAYER_EXT,
|
2017-01-12 12:51:08 +02:00
|
|
|
ProcessingConfig.tr('Default output raster layer extension'),
|
|
|
|
extensions[0],
|
|
|
|
valuetype=Setting.SELECTION,
|
|
|
|
options=extensions))
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def setGroupIcon(group, icon):
|
2013-08-12 20:44:27 +02:00
|
|
|
ProcessingConfig.settingIcons[group] = icon
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getGroupIcon(group):
|
2014-10-09 17:34:39 +03:00
|
|
|
if group == ProcessingConfig.tr('General'):
|
2017-01-09 12:34:46 +10:00
|
|
|
return QgsApplication.getThemeIcon("/processingAlgorithm.svg")
|
2013-08-12 20:44:27 +02:00
|
|
|
if group in ProcessingConfig.settingIcons:
|
|
|
|
return ProcessingConfig.settingIcons[group]
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
2017-01-09 12:34:46 +10:00
|
|
|
return QgsApplication.getThemeIcon("/processingAlgorithm.svg")
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def addSetting(setting):
|
2013-08-12 20:44:27 +02:00
|
|
|
ProcessingConfig.settings[setting.name] = setting
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def removeSetting(name):
|
2013-08-12 20:44:27 +02:00
|
|
|
del ProcessingConfig.settings[name]
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getSettings():
|
2014-04-23 18:24:23 +02:00
|
|
|
'''Return settings as a dict with group names as keys and lists of settings as values'''
|
2013-10-01 20:52:22 +03:00
|
|
|
settings = {}
|
2016-09-21 18:24:26 +02:00
|
|
|
for setting in list(ProcessingConfig.settings.values()):
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
if setting.group not in settings:
|
2012-09-15 18:25:25 +03:00
|
|
|
group = []
|
|
|
|
settings[setting.group] = group
|
|
|
|
else:
|
|
|
|
group = settings[setting.group]
|
|
|
|
group.append(setting)
|
|
|
|
return settings
|
|
|
|
|
|
|
|
@staticmethod
|
2014-05-02 10:32:37 +02:00
|
|
|
def readSettings():
|
2016-09-21 18:24:26 +02:00
|
|
|
for setting in list(ProcessingConfig.settings.values()):
|
2014-04-23 18:24:23 +02:00
|
|
|
setting.read()
|
2014-05-02 10:32:37 +02:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
@staticmethod
|
|
|
|
def getSetting(name):
|
2016-09-21 18:24:26 +02:00
|
|
|
if name in list(ProcessingConfig.settings.keys()):
|
2014-05-08 18:48:25 +02:00
|
|
|
v = ProcessingConfig.settings[name].value
|
2016-03-14 20:26:58 +01:00
|
|
|
try:
|
2016-05-13 17:49:09 +02:00
|
|
|
if v == NULL:
|
2016-03-14 20:26:58 +01:00
|
|
|
v = None
|
|
|
|
except:
|
|
|
|
pass
|
2017-01-13 16:38:30 +02:00
|
|
|
if ProcessingConfig.settings[name].valuetype == Setting.SELECTION:
|
|
|
|
return ProcessingConfig.settings[name].options.index(v)
|
|
|
|
else:
|
|
|
|
return v
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def setSettingValue(name, value):
|
2016-09-21 18:24:26 +02:00
|
|
|
if name in list(ProcessingConfig.settings.keys()):
|
2017-01-12 12:51:08 +02:00
|
|
|
if ProcessingConfig.settings[name].valuetype == Setting.SELECTION:
|
|
|
|
ProcessingConfig.settings[name].setValue(ProcessingConfig.settings[name].options[value])
|
|
|
|
else:
|
|
|
|
ProcessingConfig.settings[name].setValue(value)
|
2014-04-23 18:24:23 +02:00
|
|
|
ProcessingConfig.settings[name].save()
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2014-10-09 17:34:39 +03:00
|
|
|
@staticmethod
|
|
|
|
def tr(string, context=''):
|
|
|
|
if context == '':
|
|
|
|
context = 'ProcessingConfig'
|
|
|
|
return QCoreApplication.translate(context, string)
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2016-09-21 18:24:26 +02:00
|
|
|
class Setting(object):
|
2015-08-22 14:29:41 +02:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
"""A simple config parameter that will appear on the config dialog.
|
|
|
|
"""
|
2014-04-17 01:41:25 +02:00
|
|
|
STRING = 0
|
|
|
|
FILE = 1
|
|
|
|
FOLDER = 2
|
2015-10-24 21:11:46 +02:00
|
|
|
SELECTION = 3
|
2015-11-04 12:27:39 +01:00
|
|
|
FLOAT = 4
|
|
|
|
INT = 5
|
2016-05-24 21:56:17 +03:00
|
|
|
MULTIPLE_FOLDERS = 6
|
2014-04-19 22:04:24 +02:00
|
|
|
|
2015-11-04 12:27:39 +01:00
|
|
|
def __init__(self, group, name, description, default, hidden=False, valuetype=None,
|
|
|
|
validator=None, options=None):
|
2013-10-01 20:52:22 +03:00
|
|
|
self.group = group
|
2012-09-15 18:25:25 +03:00
|
|
|
self.name = name
|
2014-04-23 18:24:23 +02:00
|
|
|
self.qname = "Processing/Configuration/" + self.name
|
2012-09-15 18:25:25 +03:00
|
|
|
self.description = description
|
|
|
|
self.default = default
|
|
|
|
self.hidden = hidden
|
2014-04-17 01:41:25 +02:00
|
|
|
self.valuetype = valuetype
|
2015-10-24 21:11:46 +02:00
|
|
|
self.options = options
|
2017-01-12 12:51:08 +02:00
|
|
|
|
|
|
|
if self.valuetype is None:
|
|
|
|
if isinstance(default, int):
|
|
|
|
self.valuetype = self.INT
|
|
|
|
elif isinstance(default, float):
|
|
|
|
self.valuetype = self.FLOAT
|
|
|
|
|
2015-11-04 12:27:39 +01:00
|
|
|
if validator is None:
|
2017-01-12 12:51:08 +02:00
|
|
|
if self.valuetype == self.FLOAT:
|
2015-11-04 12:27:39 +01:00
|
|
|
def checkFloat(v):
|
|
|
|
try:
|
|
|
|
float(v)
|
|
|
|
except ValueError:
|
2016-09-21 18:24:26 +02:00
|
|
|
raise ValueError(self.tr('Wrong parameter value:\n%s') % str(v))
|
2015-11-04 12:27:39 +01:00
|
|
|
validator = checkFloat
|
2017-01-12 12:51:08 +02:00
|
|
|
elif self.valuetype == self.INT:
|
2015-11-04 12:27:39 +01:00
|
|
|
def checkInt(v):
|
|
|
|
try:
|
|
|
|
int(v)
|
|
|
|
except ValueError:
|
2016-09-21 18:24:26 +02:00
|
|
|
raise ValueError(self.tr('Wrong parameter value:\n%s') % str(v))
|
2015-11-04 12:27:39 +01:00
|
|
|
validator = checkInt
|
2017-01-12 12:51:08 +02:00
|
|
|
elif self.valuetype in [self.FILE, self.FOLDER]:
|
2015-11-04 12:27:39 +01:00
|
|
|
def checkFileOrFolder(v):
|
|
|
|
if v and not os.path.exists(v):
|
2016-09-21 18:24:26 +02:00
|
|
|
raise ValueError(self.tr('Specified path does not exist:\n%s') % str(v))
|
2015-11-04 12:27:39 +01:00
|
|
|
validator = checkFileOrFolder
|
2017-01-12 12:51:08 +02:00
|
|
|
elif self.valuetype == self.MULTIPLE_FOLDERS:
|
2016-05-24 21:56:17 +03:00
|
|
|
def checkMultipleFolders(v):
|
|
|
|
folders = v.split(';')
|
|
|
|
for f in folders:
|
|
|
|
if f and not os.path.exists(f):
|
2016-09-21 18:24:26 +02:00
|
|
|
raise ValueError(self.tr('Specified path does not exist:\n%s') % str(f))
|
2016-05-24 21:56:17 +03:00
|
|
|
validator = checkMultipleFolders
|
2015-11-04 12:27:39 +01:00
|
|
|
else:
|
2016-03-21 04:58:12 +01:00
|
|
|
def validator(x):
|
|
|
|
return True
|
2015-11-04 12:27:39 +01:00
|
|
|
self.validator = validator
|
|
|
|
self.value = default
|
|
|
|
|
|
|
|
def setValue(self, value):
|
|
|
|
self.validator(value)
|
2015-11-08 16:28:10 +01:00
|
|
|
self.value = value
|
2014-05-02 10:32:37 +02:00
|
|
|
|
2017-01-03 14:03:19 +07:00
|
|
|
def read(self, qsettings=QSettings()):
|
2014-04-23 18:24:23 +02:00
|
|
|
value = qsettings.value(self.qname, None)
|
|
|
|
if value is not None:
|
|
|
|
if isinstance(self.value, bool):
|
2016-09-21 18:24:26 +02:00
|
|
|
value = str(value).lower() == str(True).lower()
|
2017-01-12 12:51:08 +02:00
|
|
|
|
|
|
|
if self.valuetype == self.SELECTION:
|
2017-01-13 16:38:30 +02:00
|
|
|
self.value = self.options[int(value)]
|
2017-01-12 12:51:08 +02:00
|
|
|
else:
|
|
|
|
self.value = value
|
2014-05-02 10:32:37 +02:00
|
|
|
|
2017-01-03 14:03:19 +07:00
|
|
|
def save(self, qsettings=QSettings()):
|
2017-01-12 12:51:08 +02:00
|
|
|
if self.valuetype == self.SELECTION:
|
|
|
|
qsettings.setValue(self.qname, self.options.index(self.value))
|
|
|
|
else:
|
|
|
|
qsettings.setValue(self.qname, self.value)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def __str__(self):
|
2016-09-21 18:24:26 +02:00
|
|
|
return self.name + '=' + str(self.value)
|
2015-11-04 12:27:39 +01:00
|
|
|
|
|
|
|
def tr(self, string, context=''):
|
|
|
|
if context == '':
|
|
|
|
context = 'ProcessingConfig'
|
|
|
|
return QCoreApplication.translate(context, string)
|