Skip to content

Commit

Permalink
[processing] store settings using QSettings instead of in a dedicated…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
volaya committed Apr 23, 2014
1 parent a3a3635 commit dce4a77
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
6 changes: 3 additions & 3 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -157,7 +157,7 @@ def initialize():
AlgorithmDecorator.loadClassification()
ProcessingLog.startLogging()
ProcessingConfig.initialize()
ProcessingConfig.loadSettings()
ProcessingConfig.readSettings()
RenderingStyles.loadStyles()
Processing.loadFromProviders()

Expand Down
43 changes: 17 additions & 26 deletions python/plugins/processing/core/ProcessingConfig.py
Expand Up @@ -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:
Expand All @@ -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):
Expand All @@ -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:
Expand All @@ -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)
5 changes: 3 additions & 2 deletions python/plugins/processing/gui/ConfigDialog.py
Expand Up @@ -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)
Expand Down

0 comments on commit dce4a77

Please sign in to comment.