Skip to content
Permalink
Browse files

[processing] store settings using QSettings instead of in a dedicated…

… file
  • Loading branch information
volaya committed Apr 23, 2014
1 parent a3a3635 commit dce4a771ffd445eccab9577253f9593f73831eee
@@ -90,7 +90,7 @@ def addProvider(provider, updateList=False):
try:
provider.initializeSettings()
Processing.providers.append(provider)
ProcessingConfig.loadSettings()
ProcessingConfig.readSettings()
if updateList:
Processing.updateAlgsList()
except:
@@ -110,7 +110,7 @@ def removeProvider(provider):
try:
provider.unload()
Processing.providers.remove(provider)
ProcessingConfig.loadSettings()
ProcessingConfig.readSettings()
Processing.updateAlgsList()
except:
# This try catch block is here to avoid problems if the
@@ -157,7 +157,7 @@ def initialize():
AlgorithmDecorator.loadClassification()
ProcessingLog.startLogging()
ProcessingConfig.initialize()
ProcessingConfig.loadSettings()
ProcessingConfig.readSettings()
RenderingStyles.loadStyles()
Processing.loadFromProviders()

@@ -129,6 +129,7 @@ def removeSetting(name):

@staticmethod
def getSettings():
'''Return settings as a dict with group names as keys and lists of settings as values'''
settings = {}
for setting in ProcessingConfig.settings.values():
if not setting.group in settings:
@@ -139,34 +140,12 @@ def getSettings():
group.append(setting)
return settings

@staticmethod
def configFile():
return os.path.join(userFolder(), 'processing.conf')

@staticmethod
def loadSettings():
if not os.path.isfile(ProcessingConfig.configFile()):
return
lines = open(ProcessingConfig.configFile())
line = lines.readline().strip('\n')
while line != '':
tokens = line.split('=')
if tokens[0] in ProcessingConfig.settings.keys():
setting = ProcessingConfig.settings[tokens[0]]
if isinstance(setting.value, bool):
setting.value = tokens[1].strip('\n\r ') == str(True)
else:
setting.value = tokens[1].strip('\n\r ')
ProcessingConfig.addSetting(setting)
line = lines.readline().strip('\n')
lines.close()

@staticmethod
def saveSettings():
fout = open(ProcessingConfig.configFile(), 'w')
def readSettings():
for setting in ProcessingConfig.settings.values():
fout.write(str(setting) + '\n')
fout.close()
setting.read()

@staticmethod
def getSetting(name):
@@ -179,7 +158,7 @@ def getSetting(name):
def setSettingValue(name, value):
if name in ProcessingConfig.settings.keys():
ProcessingConfig.settings[name].value = value
ProcessingConfig.saveSettings()
ProcessingConfig.settings[name].save()


class Setting:
@@ -192,11 +171,23 @@ class Setting:
def __init__(self, group, name, description, default, hidden=False, valuetype = None):
self.group = group
self.name = name
self.qname = "Processing/Configuration/" + self.name
self.description = description
self.default = default
self.value = default
self.hidden = hidden
self.valuetype = valuetype

def read(self):
qsettings = QSettings()
value = qsettings.value(self.qname, None)
if value is not None:
if isinstance(self.value, bool):
value = str(value).lower() == str(True).lower()
self.value = value

def save(self):
QSettings().setValue(self.qname, self.value)

def __str__(self):
return self.name + '=' + str(self.value)
@@ -145,8 +145,9 @@ def accept(self):
return
else:
setting.value = unicode(self.items[setting].text())
ProcessingConfig.addSetting(setting)
ProcessingConfig.saveSettings()
setting.save()
#ProcessingConfig.addSetting(setting)
#ProcessingConfig.saveSettings()
self.toolbox.updateTree()

QDialog.accept(self)

0 comments on commit dce4a77

Please sign in to comment.
You can’t perform that action at this time.