Skip to content
Permalink
Browse files
create config dialog from .ui
add tooltips to search boxes
  • Loading branch information
alexbruy committed Dec 3, 2012
1 parent 90c8536 commit d8ec3804126a203a8cb63c7a8069be30e79ba0d6
@@ -25,64 +25,36 @@

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui

from sextante.core.SextanteConfig import SextanteConfig

from sextante.ui.ui_DlgConfig import Ui_DlgConfig

class ConfigDialog(QtGui.QDialog):
class ConfigDialog(QDialog, Ui_DlgConfig):
def __init__(self, toolbox):
QtGui.QDialog.__init__(self)
QDialog.__init__(self)
self.setupUi(self)

self.toolbox = toolbox
self.setupUi()

def setupUi(self):
self.resize(700, 500)
self.setWindowTitle("SEXTANTE options")
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setSpacing(2)
self.verticalLayout.setMargin(0)
self.searchBox = QtGui.QLineEdit()
self.searchBox.textChanged.connect(self.fillTree)
self.verticalLayout.addWidget(self.searchBox)
self.groupIcon = QtGui.QIcon()
self.groupIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_DirClosedIcon),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.groupIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_DirOpenIcon),
QtGui.QIcon.Normal, QtGui.QIcon.On)
self.keyIcon = QtGui.QIcon()
self.keyIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_FileIcon))
self.tree = QtGui.QTreeWidget()
self.tree.setHeaderLabels(("Setting", "Value"))
self.tree.header().setResizeMode(0, QtGui.QHeaderView.Stretch)
self.tree.header().setResizeMode(1, QtGui.QHeaderView.Stretch)
self.fillTree()
self.verticalLayout.addWidget(self.tree)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.horizontalLayout.addSpacing(100)
self.horizontalLayout.addWidget(self.buttonBox)
self.verticalLayout.addLayout(self.horizontalLayout)
self.setLayout(self.verticalLayout)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.okPressed)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.cancelPressed)
QtCore.QMetaObject.connectSlotsByName(self)
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)

self.fillTree()

def fillTree(self):
self.items = {}
self.tree.clear()
text = str(self.searchBox.text())
settings = SextanteConfig.getSettings()
for group in settings.keys():
groupItem = QtGui.QTreeWidgetItem()
groupItem = QTreeWidgetItem()
groupItem.setText(0,group)
icon = SextanteConfig.getGroupIcon(group)
groupItem.setIcon(0, icon)
#groupItem.setIcon(0,self.groupIcon)
for setting in settings[group]:
if setting.hidden:
continue
@@ -93,44 +65,46 @@ def fillTree(self):
self.tree.addTopLevelItem(groupItem)
if text != "":
groupItem.setExpanded(True)

self.tree.sortItems(0, Qt.AscendingOrder)
self.tree.resizeColumnToContents(0)
self.tree.resizeColumnToContents(1)

def okPressed(self):
def accept(self):
for setting in self.items.keys():
if isinstance(setting.value,bool):
setting.value = (self.items[setting].checkState(1) == QtCore.Qt.Checked)
setting.value = (self.items[setting].checkState(1) == Qt.Checked)
elif isinstance(setting.value, (float,int, long)):
value = str(self.items[setting].text(1))
try:
value = float(value)
setting.value = value
except ValueError:
QtGui.QMessageBox.critical(self, "Wrong value","Wrong parameter value:\n" + value)
QMessageBox.critical(self,
self.tr("Wrong value"),
self.tr("Wrong parameter value:\n%1").arg(value)
)
return
else:
setting.value = str(self.items[setting].text(1))
SextanteConfig.addSetting(setting)
SextanteConfig.saveSettings()
self.toolbox.updateTree()
self.close()


def cancelPressed(self):
self.close()

QDialog.accept(self)

class TreeSettingItem(QtGui.QTreeWidgetItem):
class TreeSettingItem(QTreeWidgetItem):

def __init__(self, setting, icon):
QTreeWidgetItem.__init__(self)
self.setting = setting
self.setText(0, setting.description)
self.setFlags(self.flags() | QtCore.Qt.ItemIsEditable)
self.setFlags(self.flags() | Qt.ItemIsEditable)
if isinstance(setting.value,bool):
if setting.value:
self.setCheckState(1, QtCore.Qt.Checked)
self.setCheckState(1, Qt.Checked)
else:
self.setCheckState(1, QtCore.Qt.Unchecked)
self.setCheckState(1, Qt.Unchecked)
else:
self.setText(1, str(setting.value))
self.setIcon(0, icon)
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DlgConfig</class>
<widget class="QDialog" name="DlgConfig">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>450</height>
</rect>
</property>
<property name="windowTitle">
<string>SEXTANTE options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QgsFilterLineEdit" name="searchBox">
<property name="toolTip">
<string>Enter setting name to filter list</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="tree">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Setting</string>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFilterLineEdit</class>
<extends>QLineEdit</extends>
<header>qgis.gui</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DlgConfig</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DlgConfig</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
@@ -30,7 +30,11 @@ additional algorithm providers</string>
</widget>
</item>
<item>
<widget class="QgsFilterLineEdit" name="searchBox"/>
<widget class="QgsFilterLineEdit" name="searchBox">
<property name="toolTip">
<string>Enter algorithm name to filter list</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="algorithmTree">

0 comments on commit d8ec380

Please sign in to comment.