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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__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$'
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
import os.path
|
|
|
|
from PyQt4 import QtGui
|
2013-10-01 20:52:22 +03:00
|
|
|
from processing.tools.system import *
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
|
|
|
class ProcessingConfig:
|
|
|
|
|
|
|
|
OUTPUT_FOLDER = 'OUTPUT_FOLDER'
|
|
|
|
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'
|
|
|
|
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'
|
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():
|
2013-10-01 20:52:22 +03:00
|
|
|
icon = QtGui.QIcon(os.path.dirname(__file__) + '/../images/alg.png')
|
|
|
|
ProcessingConfig.settingIcons['General'] = icon
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.SHOW_DEBUG_IN_DIALOG,
|
|
|
|
'Show extra info in Log panel', True))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.KEEP_DIALOG_OPEN,
|
|
|
|
'Keep dialog open after running an algorithm', False))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.USE_SELECTED,
|
|
|
|
'Use only selected features', True))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.USE_FILENAME_AS_LAYER_NAME,
|
|
|
|
'Use filename as layer name', False))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.SHOW_RECENT_ALGORITHMS,
|
|
|
|
'Show recently executed algorithms', True))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.OUTPUT_FOLDER,
|
|
|
|
'Output folder', tempFolder()))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.SHOW_CRS_DEF,
|
|
|
|
'Show layer CRS definition in selection boxes', True))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.WARN_UNMATCHING_CRS,
|
|
|
|
"Warn before executing if layer CRS's do not match", True))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.RASTER_STYLE,
|
|
|
|
'Style for raster layers', ''))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.VECTOR_POINT_STYLE,
|
|
|
|
'Style for point layers', ''))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.VECTOR_LINE_STYLE,
|
|
|
|
'Style for line layers', ''))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.VECTOR_POLYGON_STYLE,
|
|
|
|
'Style for polygon layers', ''))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.VECTOR_POLYGON_STYLE,
|
|
|
|
'Style for polygon layers', ''))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.PRE_EXECUTION_SCRIPT,
|
|
|
|
'Pre-execution script', ''))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.POST_EXECUTION_SCRIPT,
|
|
|
|
'Post-execution script', ''))
|
|
|
|
ProcessingConfig.addSetting(Setting('General',
|
|
|
|
ProcessingConfig.RECENT_ALGORITHMS,
|
|
|
|
'Recent algs', '', hidden=True))
|
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):
|
2013-10-01 20:52:22 +03:00
|
|
|
if group == 'General':
|
|
|
|
return QtGui.QIcon(os.path.dirname(__file__) + '/../images/alg.png'
|
|
|
|
)
|
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:
|
2013-10-01 20:52:22 +03:00
|
|
|
return QtGui.QIcon(
|
|
|
|
os.path.dirname(__file__) + '/../images/alg.png')
|
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():
|
2013-10-01 20:52:22 +03:00
|
|
|
settings = {}
|
2013-08-12 20:44:27 +02:00
|
|
|
for setting in ProcessingConfig.settings.values():
|
2012-09-15 18:25:25 +03:00
|
|
|
if not setting.group in settings:
|
|
|
|
group = []
|
|
|
|
settings[setting.group] = group
|
|
|
|
else:
|
|
|
|
group = settings[setting.group]
|
|
|
|
group.append(setting)
|
|
|
|
return settings
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def configFile():
|
2013-10-01 20:52:22 +03:00
|
|
|
return os.path.join(userFolder(), 'processing.conf')
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def loadSettings():
|
2013-08-12 20:44:27 +02:00
|
|
|
if not os.path.isfile(ProcessingConfig.configFile()):
|
2012-09-15 18:25:25 +03:00
|
|
|
return
|
2013-08-12 20:44:27 +02:00
|
|
|
lines = open(ProcessingConfig.configFile())
|
2013-10-01 20:52:22 +03:00
|
|
|
line = lines.readline().strip('\n')
|
|
|
|
while line != '':
|
|
|
|
tokens = line.split('=')
|
2013-08-12 20:44:27 +02:00
|
|
|
if tokens[0] in ProcessingConfig.settings.keys():
|
|
|
|
setting = ProcessingConfig.settings[tokens[0]]
|
2012-09-15 18:25:25 +03:00
|
|
|
if isinstance(setting.value, bool):
|
2013-10-01 20:52:22 +03:00
|
|
|
setting.value = tokens[1].strip('\n\r ') == str(True)
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
2013-10-01 20:52:22 +03:00
|
|
|
setting.value = tokens[1].strip('\n\r ')
|
2013-08-12 20:44:27 +02:00
|
|
|
ProcessingConfig.addSetting(setting)
|
2013-10-01 20:52:22 +03:00
|
|
|
line = lines.readline().strip('\n')
|
2012-09-15 18:25:25 +03:00
|
|
|
lines.close()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def saveSettings():
|
2013-10-01 20:52:22 +03:00
|
|
|
fout = open(ProcessingConfig.configFile(), 'w')
|
2013-08-12 20:44:27 +02:00
|
|
|
for setting in ProcessingConfig.settings.values():
|
2013-10-01 20:52:22 +03:00
|
|
|
fout.write(str(setting) + '\n')
|
2012-09-15 18:25:25 +03:00
|
|
|
fout.close()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getSetting(name):
|
2013-08-12 20:44:27 +02:00
|
|
|
if name in ProcessingConfig.settings.keys():
|
|
|
|
return ProcessingConfig.settings[name].value
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def setSettingValue(name, value):
|
2013-08-12 20:44:27 +02:00
|
|
|
if name in ProcessingConfig.settings.keys():
|
|
|
|
ProcessingConfig.settings[name].value = value
|
|
|
|
ProcessingConfig.saveSettings()
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
class Setting:
|
|
|
|
"""A simple config parameter that will appear on the config dialog.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, group, name, description, default, hidden=False):
|
|
|
|
self.group = group
|
2012-09-15 18:25:25 +03:00
|
|
|
self.name = name
|
|
|
|
self.description = description
|
|
|
|
self.default = default
|
|
|
|
self.value = default
|
|
|
|
self.hidden = hidden
|
|
|
|
|
|
|
|
def __str__(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
return self.name + '=' + str(self.value)
|