Skip to content

Commit

Permalink
simplified ui files
Browse files Browse the repository at this point in the history
added search functionality to toolbox

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@12 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf@gmail.com committed Jan 11, 2012
1 parent eb91e9a commit 398e2a3
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 320 deletions.
6 changes: 3 additions & 3 deletions src/sextante/core/GeoAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def canBeExecuted(self, layersCount):

def __str__(self):
s = "ALGORITHM: " + self.name + "\n"
s+=self._descriptionfile + "\n"
for param in self.parameters.values():
#s+=self._descriptionFile + "\n"
for param in self.parameters:
s+=(str(param) + "\n")
for out in self.outputs.values():
for out in self.outputs:
s+=(str(out) + "\n")
s+=("\n")
return s
Expand Down
119 changes: 116 additions & 3 deletions src/sextante/gui/ParametersDialog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
from sextante.core.QGisLayers import QGisLayers
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.parameters.ParameterSelection import ParameterSelection

from PyQt4 import QtGui

from sextante.gui.ui_ParametersDialog import Ui_ParametersDialog
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class ParametersDialog(QtGui.QDialog):
def __init__(self, alg):
Expand All @@ -11,3 +20,107 @@ def __init__(self, alg):
self.ui = Ui_ParametersDialog()
self.ui.setupUi(self)

class Ui_ParametersDialog(object):

SAVE_TO_TEMP_FILE = "[Save to temporary file]"

def setupUi(self, dialog):
self.alg = dialog.alg
self.dialog = dialog
self.valueItems = {}
dialog.setObjectName(_fromUtf8("Parameters"))
dialog.resize(650, 450)
self.buttonBox = QtGui.QDialogButtonBox(dialog)
self.buttonBox.setGeometry(QtCore.QRect(110, 400, 441, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.tableWidget = QtGui.QTableWidget(dialog)
self.tableWidget.setGeometry(QtCore.QRect(5, 5, 640, 350))
self.tableWidget.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
self.tableWidget.setColumnCount(2)
self.tableWidget.setColumnWidth(0,300)
self.tableWidget.setColumnWidth(1,300)
self.tableWidget.setHorizontalHeaderItem(0, QtGui.QTableWidgetItem("Parameter"))
self.tableWidget.setHorizontalHeaderItem(1, QtGui.QTableWidgetItem("Value"))
self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
self.tableWidget.verticalHeader().setVisible(False)
self.setTableContent()
dialog.setWindowTitle(self.alg.name)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), self.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), self.reject)
QtCore.QMetaObject.connectSlotsByName(dialog)


def getItemFromParameter(self, param):

if isinstance(param, ParameterRaster):
item = QtGui.QComboBox()
layers = QGisLayers.getRasterLayers()
for layer in layers:
item.addItem(layer.name())
elif isinstance(param, ParameterVector):
item = QtGui.QComboBox()
layers = QGisLayers.getVectorLayers()
for layer in layers:
item.addItem(layer.name())
elif isinstance(param, ParameterBoolean):
item = QtGui.QComboBox()
item.addItem("Yes")
item.addItem("No")
elif isinstance(param, ParameterSelection):
item = QtGui.QComboBox()
item.addItems(param.options)
else:
item = QtGui.QLineEdit()

return item


def setTableContent(self):
params = self.alg.parameters
outputs = self.alg.outputs
numParams = len(self.alg.parameters)
numOutputs = len(self.alg.outputs)
self.tableWidget.setRowCount(numParams + numOutputs)

i=0
for param in params:
item = QtGui.QTableWidgetItem(param.description)
item.setFlags(QtCore.Qt.ItemIsEnabled)
self.tableWidget.setItem(i,0, item)
item = self.getItemFromParameter(param)
self.valueItems[param.name] = item
self.tableWidget.setCellWidget(i,1, item)
self.tableWidget.setRowHeight(i,22)
i+=1

for output in outputs:
item = QtGui.QTableWidgetItem(output.description)
item.setFlags(QtCore.Qt.ItemIsEnabled)
self.tableWidget.setItem(i,0, item)
item = QtGui.QLineEdit()
item.setText(self.SAVE_TO_TEMP_FILE)
self.valueItems[output.name] = item
self.tableWidget.setCellWidget(i,1, item)
self.tableWidget.setRowHeight(i,22)
i+=1


def setParamValues(self):
return False


def accept(self):
if self.setParamValues():
self.dialog.close()
else:
QMessageBox.warning(self.dialog, "Unable to execute algorithm", "Wrong or missing parameter values")

def reject(self):
self.dialog.alg = None
self.dialog.close()




109 changes: 0 additions & 109 deletions src/sextante/gui/ParametersDialog.ui

This file was deleted.

98 changes: 96 additions & 2 deletions src/sextante/gui/SextanteToolbox.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,104 @@

from PyQt4 import QtGui
from sextante.gui.ui_SextanteToolbox import Ui_SextanteToolbox

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
from sextante.core.Sextante import Sextante
from sextante.gui.ParametersDialog import ParametersDialog
import copy
from sextante.core.QGisLayers import QGisLayers

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s


class SextanteToolbox(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
self.setModal(True)
self.ui = Ui_SextanteToolbox()
self.ui.setupUi(self)

class Ui_SextanteToolbox(object):

def setupUi(self, SextanteToolbox):
self.toolbox = SextanteToolbox
SextanteToolbox.setObjectName(_fromUtf8("SextanteToolbox"))
SextanteToolbox.resize(400, 300)
self.verticalLayoutWidget = QtGui.QWidget(SextanteToolbox)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 9, 381, 281))
self.verticalLayoutWidget.setObjectName(_fromUtf8("verticalLayoutWidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.algorithmTree = QtGui.QTreeWidget(self.verticalLayoutWidget)
self.algorithmTree.setObjectName(_fromUtf8("algorithmTree"))
self.algorithmTree.setHeaderHidden(True)
self.verticalLayout.addWidget(self.algorithmTree)
self.searchBox = QtGui.QLineEdit(self.verticalLayoutWidget)
self.searchBox.setObjectName(_fromUtf8("searchBox"))
self.searchBox.textChanged.connect(self.fillTree)
self.verticalLayout.addWidget(self.searchBox)
self.algorithmTree.doubleClicked.connect(self.executeAlgorithm)
self.fillTree()

self.retranslateUi(SextanteToolbox)
QtCore.QMetaObject.connectSlotsByName(SextanteToolbox)

def executeAlgorithm(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
alg = Sextante.getAlgorithm(item.getAlg().commandLineName())
alg = copy.deepcopy(alg)
dlg = ParametersDialog(alg)
dlg.exec_()
if dlg.alg != None:
QMessageBox.critical(None, "test", str(alg))



def fillTree(self):
self.algorithmTree.clear()
text = str(self.searchBox.text())
layersCount = QGisLayers.getLayersCount()
for providerName in Sextante.algs.keys():
groups = {}
provider = Sextante.algs[providerName]
algs = provider.values()
for alg in algs:
if text =="" or text.lower() in alg.name.lower():
if alg.group in groups:
groupItem = groups[alg.group]
else:
groupItem = QtGui.QTreeWidgetItem()
groupItem.setText(0,alg.group)
groups[alg.group] = groupItem
algItem = TreeAlgorithmItem(alg, layersCount)
groupItem.addChild(algItem)
providerItem = QtGui.QTreeWidgetItem()
providerItem.setText(0,providerName)
for groupItem in groups.values():
providerItem.addChild(groupItem)
self.algorithmTree.addTopLevelItem(providerItem)
providerItem.setExpanded(True)
for groupItem in groups.values():
if text != "":
groupItem.setExpanded(True)


def retranslateUi(self, SextantePlugin):
SextantePlugin.setWindowTitle("SEXTANTE Toolbox")

class TreeAlgorithmItem(QtGui.QTreeWidgetItem):

def __init__(self, alg, layersCount):
QTreeWidgetItem.__init__(self)
self.alg = alg
self.setText(0,alg.name)
if not alg.canBeExecuted(layersCount):
self.setForeground(0, QtGui.QBrush(QtGui.QColor(150,150,150)))

def getAlg(self):
return self.alg
Loading

0 comments on commit 398e2a3

Please sign in to comment.