4 changes: 4 additions & 0 deletions python/plugins/sextante/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ ADD_SUBDIRECTORY(script)
ADD_SUBDIRECTORY(taudem)
#ADD_SUBDIRECTORY(tests)

FILE(GLOB UI_FILES ui/*.ui)
PYQT4_WRAP_UI(PYUI_FILES ${UI_FILES})

FILE(GLOB OTHER_FILES metadata.txt)
FILE(GLOB PY_FILES *.py)

PYQT4_ADD_RESOURCES(PYRC_FILES resources.qrc)

PLUGIN_INSTALL(sextante . ${PY_FILES} ${OTHER_FILES} ${PYRC_FILES})
PLUGIN_INSTALL(sextante ui ${PYUI_FILES} ui/__init__.py)
27 changes: 15 additions & 12 deletions python/plugins/sextante/SextantePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

from sextante.modeler.ModelerDialog import ModelerDialog

import resources_rc
import sextante.resources_rc

cmd_folder = os.path.split(inspect.getfile( inspect.currentframe() ))[0]
if cmd_folder not in sys.path:
Expand All @@ -58,47 +58,47 @@ def __init__(self, iface):

def initGui(self):
self.toolbox = SextanteToolbox(self.iface)
self.toolbox.setVisible(False)
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
self.toolbox.hide()
Sextante.addAlgListListener(self.toolbox)

self.menu = QMenu(self.iface.mainWindow())
self.menu.setTitle(QCoreApplication.translate("SEXTANTE", "Analysis"))

self.toolboxAction = QAction(QIcon(":/sextante/images/toolbox.png"),
QCoreApplication.translate("SEXTANTE", "&SEXTANTE toolbox"),
self.iface.mainWindow())
QObject.connect(self.toolboxAction, SIGNAL("triggered()"), self.openToolbox)
self.toolboxAction = self.toolbox.toggleViewAction()
self.toolboxAction.setIcon(QIcon(":/sextante/images/toolbox.png"))
self.toolboxAction.setText(QCoreApplication.translate("SEXTANTE", "&SEXTANTE toolbox"))
self.menu.addAction(self.toolboxAction)

self.modelerAction = QAction(QIcon(":/sextante/images/model.png"),
QCoreApplication.translate("SEXTANTE", "&SEXTANTE modeler"),
self.iface.mainWindow())
QObject.connect(self.modelerAction, SIGNAL("triggered()"), self.openModeler)
self.modelerAction.triggered.connect(self.openModeler)
self.menu.addAction(self.modelerAction)

self.historyAction = QAction(QIcon(":/sextante/images/history.gif"),
QCoreApplication.translate("SEXTANTE", "&SEXTANTE history and log"),
self.iface.mainWindow())
QObject.connect(self.historyAction, SIGNAL("triggered()"), self.openHistory)
self.historyAction.triggered.connect(self.openHistory)
self.menu.addAction(self.historyAction)

self.configAction = QAction(QIcon(":/sextante/images/config.png"),
QCoreApplication.translate("SEXTANTE", "&SEXTANTE options and configuration"),
self.iface.mainWindow())
QObject.connect(self.configAction, SIGNAL("triggered()"), self.openConfig)
self.configAction.triggered.connect(self.openConfig)
self.menu.addAction(self.configAction)

self.resultsAction = QAction(QIcon(":/sextante/images/results.png"),
QCoreApplication.translate("SEXTANTE", "&SEXTANTE results viewer"),
self.iface.mainWindow())
QObject.connect(self.resultsAction, SIGNAL("triggered()"), self.openResults)
self.resultsAction.triggered.connect(self.openResults)
self.menu.addAction(self.resultsAction)

#=======================================================================
# self.helpAction = QAction(QIcon(":/sextante/images/help.png"),
# QCoreApplication.translate("SEXTANTE", "&SEXTANTE help"),
# self.iface.mainWindow())
# QObject.connect(self.helpAction, SIGNAL("triggered()"), self.openHelp)
# self.helpAction.triggered.connect(self.openHelp)
# self.menu.addAction(self.helpAction)
#=======================================================================

Expand All @@ -119,7 +119,10 @@ def unload(self):
pass

def openToolbox(self):
self.toolbox.setVisible(True)
if self.toolbox.isVisible():
self.toolbox.hide()
else:
self.toolbox.show()

def openModeler(self):
dlg = ModelerDialog()
Expand Down
85 changes: 31 additions & 54 deletions python/plugins/sextante/gui/ConfigDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,64 +25,39 @@

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)

if hasattr(self.searchBox, 'setPlaceholderText'):
self.searchBox.setPlaceholderText(self.tr("Search..."))

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
Expand All @@ -93,44 +68,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)
103 changes: 28 additions & 75 deletions python/plugins/sextante/gui/HelpEditionDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,101 +23,49 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui, QtWebKit
import os
import pickle

class HelpEditionDialog(QtGui.QDialog):
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from sextante.ui.ui_DlgHelpEdition import Ui_DlgHelpEdition

class HelpEditionDialog(QDialog, Ui_DlgHelpEdition):

ALG_DESC = "ALG_DESC"
ALG_CREATOR = "ALG_CREATOR"
ALG_HELP_CREATOR = "ALG_HELP_CREATOR"

def __init__(self, alg):
QDialog.__init__(self)
self.setupUi(self)

self.alg = alg
QtGui.QDialog.__init__(self)
self.setModal(True)
self.descriptions = {}
if self.alg.descriptionFile is not None:
helpfile = alg.descriptionFile + ".help"
if os.path.exists(helpfile):
f = open(helpfile, "rb")
self.descriptions = pickle.load(f)
self.currentName = self.ALG_DESC
self.setupUi()

def setupUi(self):
self.resize(700, 500)
self.tree = QtGui.QTreeWidget()
self.tree.setHeaderHidden(True)
self.tree.setMinimumWidth(300)
QObject.connect(self.tree, QtCore.SIGNAL("itemClicked(QTreeWidgetItem*, int)"), self.changeItem)
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.itemClicked.connect(self.changeItem)

self.fillTree()
self.setWindowTitle("Help editor")
self.horizontalLayout= QtGui.QHBoxLayout()
self.horizontalLayout.setSpacing(15)
self.horizontalLayout.setMargin(0)
self.label = QtGui.QLabel()
self.label.setText("Select elements on the tree and fill their description in the text box below")
self.labelName = QtGui.QLabel()
self.labelName.setText("Algorithm description")
self.text = QtGui.QTextEdit()
self.text.setMinimumHeight(200)
self.verticalLayout= QtGui.QVBoxLayout()
self.verticalLayout.setSpacing(5)
self.verticalLayout.setMargin(0)
self.verticalLayout.addWidget(self.tree)
self.verticalLayout.addSpacing(20)
self.verticalLayout.addWidget(self.label)
self.verticalLayout.addSpacing(20)
self.verticalLayout.addWidget(self.labelName)
self.verticalLayout.addWidget(self.text)
self.horizontalLayout.addLayout(self.verticalLayout)
self.webView = QtWebKit.QWebView()
self.webView.setMinimumWidth(300)
self.webView.setHtml(self.getHtml())
self.horizontalLayout.addWidget(self.webView)
self.closeButton = QtGui.QPushButton()
self.closeButton.setText("Cancel")
self.saveButton = QtGui.QPushButton()
self.saveButton.setText("OK")
self.horizontalLayout2= QtGui.QHBoxLayout()
self.horizontalLayout2.setSpacing(2)
self.horizontalLayout2.setMargin(0)
self.horizontalLayout2.addStretch(1000)
self.horizontalLayout2.addWidget(self.saveButton)
self.horizontalLayout2.addWidget(self.closeButton)
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveHelp)
self.verticalLayout2= QtGui.QVBoxLayout()
self.verticalLayout2.setSpacing(2)
self.verticalLayout2.setMargin(0)
self.verticalLayout2.addLayout(self.horizontalLayout)
self.verticalLayout2.addLayout(self.horizontalLayout2)
self.setLayout(self.verticalLayout2)
QtCore.QMetaObject.connectSlotsByName(self)
self.updateHtmlView()

def closeWindow(self):
def reject(self):
self.descriptions = None
self.close()
QDialog.reject(self)

def saveHelp(self):
self.descriptions[self.currentName] = str(self.text.toPlainText())
def accept(self):
self.descriptions[self.currentName] = unicode(self.text.toPlainText())
if self.alg.descriptionFile is not None:
f = open(self.alg.descriptionFile + ".help", "wb")
pickle.dump(self.descriptions, f)
f.close()
self.close()
QDialog.accept(self)

def getHtml(self):
s = "<h2>Algorithm description</h2>\n"
Expand All @@ -140,7 +88,7 @@ def fillTree(self):
for param in self.alg.parameters:
item = TreeDescriptionItem(param.description, param.name)
parametersItem.addChild(item)
outputsItem = TreeDescriptionItem("Outputs", None)
outputsItem = TreeDescriptionItem(self.tr("Outputs"), None)
self.tree.addTopLevelItem(outputsItem)
for out in self.alg.outputs:
item = TreeDescriptionItem(out.description, out.name)
Expand All @@ -154,27 +102,32 @@ def changeItem(self):
item = self.tree.currentItem()
if isinstance(item, TreeDescriptionItem):
if self.currentName:
self.descriptions[self.currentName] = str(self.text.toPlainText())
self.descriptions[self.currentName] = unicode(self.text.toPlainText())
name = item.name
if name:
self.text.setEnabled(True)
self.updateHtmlView()
self.currentName = name
self.labelName.setText(item.description)
if name in self.descriptions:
self.text.setText(self.descriptions[name])
else:
self.text.setText("")
self.text.clear()
else:
self.currentName = None
self.text.clear()
self.text.setEnabled(False)
self.updateHtmlView()

def updateHtmlView(self):
self.webView.setHtml(self.getHtml())

def getDescription(self, name):
if name in self.descriptions :
if name in self.descriptions:
return self.descriptions[name]
else:
return ""

class TreeDescriptionItem(QtGui.QTreeWidgetItem):
class TreeDescriptionItem(QTreeWidgetItem):
def __init__(self, description, name):
QTreeWidgetItem.__init__(self)
self.name = name
Expand Down
Loading