2012-10-05 23:28:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
ConfigDialog.py
|
|
|
|
---------------------
|
|
|
|
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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2013-04-21 15:12:00 +02:00
|
|
|
import os
|
|
|
|
from PyQt4 import QtGui
|
2012-10-05 23:28:47 +02:00
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
from PyQt4.QtCore import *
|
|
|
|
from PyQt4.QtGui import *
|
2012-12-01 17:56:18 +02:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
from sextante.core.SextanteConfig import SextanteConfig
|
|
|
|
|
2012-12-01 17:56:18 +02:00
|
|
|
from sextante.ui.ui_DlgConfig import Ui_DlgConfig
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2012-12-01 17:56:18 +02:00
|
|
|
class ConfigDialog(QDialog, Ui_DlgConfig):
|
2012-09-15 18:25:25 +03:00
|
|
|
def __init__(self, toolbox):
|
2012-12-01 17:56:18 +02:00
|
|
|
QDialog.__init__(self)
|
|
|
|
self.setupUi(self)
|
2012-09-15 18:25:25 +03:00
|
|
|
self.toolbox = toolbox
|
2012-12-01 17:56:18 +02:00
|
|
|
self.groupIcon = QIcon()
|
|
|
|
self.groupIcon.addPixmap(self.style().standardPixmap(QStyle.SP_DirClosedIcon),
|
|
|
|
QIcon.Normal, QIcon.Off)
|
|
|
|
self.groupIcon.addPixmap(self.style().standardPixmap(QStyle.SP_DirOpenIcon),
|
|
|
|
QIcon.Normal, QIcon.On)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2012-12-01 20:22:21 +02:00
|
|
|
if hasattr(self.searchBox, 'setPlaceholderText'):
|
|
|
|
self.searchBox.setPlaceholderText(self.tr("Search..."))
|
|
|
|
|
2012-12-05 16:49:49 +02:00
|
|
|
self.searchBox.textChanged.connect(self.fillTree)
|
2012-12-01 17:56:18 +02:00
|
|
|
self.fillTree()
|
2013-04-21 15:12:00 +02:00
|
|
|
self.tree.itemClicked.connect(self.edit)
|
|
|
|
self.tree.itemDoubleClicked.connect(self.edit)
|
|
|
|
|
|
|
|
def edit(self, item, column):
|
|
|
|
if column > 0:
|
|
|
|
self.tree.editItem(item, column)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def fillTree(self):
|
|
|
|
self.items = {}
|
|
|
|
self.tree.clear()
|
|
|
|
text = str(self.searchBox.text())
|
|
|
|
settings = SextanteConfig.getSettings()
|
2013-04-21 15:12:00 +02:00
|
|
|
priorityKeys = ['General', "Models", "Scripts"]
|
|
|
|
for group in priorityKeys:
|
2012-12-01 17:56:18 +02:00
|
|
|
groupItem = QTreeWidgetItem()
|
2012-09-15 18:25:25 +03:00
|
|
|
groupItem.setText(0,group)
|
|
|
|
icon = SextanteConfig.getGroupIcon(group)
|
|
|
|
groupItem.setIcon(0, icon)
|
|
|
|
for setting in settings[group]:
|
|
|
|
if setting.hidden:
|
|
|
|
continue
|
|
|
|
if text =="" or text.lower() in setting.description.lower():
|
|
|
|
settingItem = TreeSettingItem(setting, icon)
|
|
|
|
self.items[setting]=settingItem
|
|
|
|
groupItem.addChild(settingItem)
|
|
|
|
self.tree.addTopLevelItem(groupItem)
|
|
|
|
if text != "":
|
|
|
|
groupItem.setExpanded(True)
|
2013-04-21 15:12:00 +02:00
|
|
|
|
|
|
|
providersItem = QTreeWidgetItem()
|
|
|
|
providersItem.setText(0, "Providers")
|
|
|
|
icon = QtGui.QIcon(os.path.dirname(__file__) + "/../images/alg.png")
|
|
|
|
providersItem.setIcon(0, icon)
|
|
|
|
for group in settings.keys():
|
|
|
|
if group in priorityKeys:
|
|
|
|
continue
|
|
|
|
groupItem = QTreeWidgetItem()
|
|
|
|
groupItem.setText(0,group)
|
|
|
|
icon = SextanteConfig.getGroupIcon(group)
|
|
|
|
groupItem.setIcon(0, icon)
|
|
|
|
for setting in settings[group]:
|
|
|
|
if setting.hidden:
|
|
|
|
continue
|
|
|
|
if text =="" or text.lower() in setting.description.lower():
|
|
|
|
settingItem = TreeSettingItem(setting, icon)
|
|
|
|
self.items[setting]=settingItem
|
|
|
|
groupItem.addChild(settingItem)
|
|
|
|
if text != "":
|
|
|
|
groupItem.setExpanded(True)
|
|
|
|
providersItem.addChild(groupItem)
|
|
|
|
self.tree.addTopLevelItem(providersItem)
|
2012-12-01 17:56:18 +02:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
self.tree.sortItems(0, Qt.AscendingOrder)
|
2013-04-21 15:12:00 +02:00
|
|
|
self.tree.setColumnWidth(0, 400)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2012-12-01 17:56:18 +02:00
|
|
|
def accept(self):
|
2012-09-15 18:25:25 +03:00
|
|
|
for setting in self.items.keys():
|
|
|
|
if isinstance(setting.value,bool):
|
2012-12-01 17:56:18 +02:00
|
|
|
setting.value = (self.items[setting].checkState(1) == Qt.Checked)
|
2012-09-15 18:25:25 +03:00
|
|
|
elif isinstance(setting.value, (float,int, long)):
|
|
|
|
value = str(self.items[setting].text(1))
|
|
|
|
try:
|
|
|
|
value = float(value)
|
|
|
|
setting.value = value
|
|
|
|
except ValueError:
|
2012-12-01 17:56:18 +02:00
|
|
|
QMessageBox.critical(self,
|
|
|
|
self.tr("Wrong value"),
|
|
|
|
self.tr("Wrong parameter value:\n%1").arg(value)
|
|
|
|
)
|
2012-09-15 18:25:25 +03:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
setting.value = str(self.items[setting].text(1))
|
|
|
|
SextanteConfig.addSetting(setting)
|
|
|
|
SextanteConfig.saveSettings()
|
|
|
|
self.toolbox.updateTree()
|
|
|
|
|
2012-12-01 17:56:18 +02:00
|
|
|
QDialog.accept(self)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2012-12-01 17:56:18 +02:00
|
|
|
class TreeSettingItem(QTreeWidgetItem):
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def __init__(self, setting, icon):
|
|
|
|
QTreeWidgetItem.__init__(self)
|
|
|
|
self.setting = setting
|
2013-04-21 15:12:00 +02:00
|
|
|
self.setText(0, setting.description)
|
2012-09-15 18:25:25 +03:00
|
|
|
if isinstance(setting.value,bool):
|
|
|
|
if setting.value:
|
2012-12-01 17:56:18 +02:00
|
|
|
self.setCheckState(1, Qt.Checked)
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
2012-12-01 17:56:18 +02:00
|
|
|
self.setCheckState(1, Qt.Unchecked)
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
2013-04-21 15:12:00 +02:00
|
|
|
self.setFlags(self.flags() | Qt.ItemIsEditable)
|
2012-12-10 18:16:27 +02:00
|
|
|
self.setText(1, unicode(setting.value))
|
2012-09-15 18:25:25 +03:00
|
|
|
self.setIcon(0, icon)
|