Skip to content
Permalink
Browse files
create help edition dialog from .ui
  • Loading branch information
alexbruy committed Dec 3, 2012
1 parent 6518a97 commit 97639aa2852233b2b3a48e0753f7baaaf132984c
Showing with 183 additions and 75 deletions.
  1. +28 −75 python/plugins/sextante/gui/HelpEditionDialog.py
  2. +155 −0 python/plugins/sextante/ui/DlgHelpEdition.ui
@@ -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"
@@ -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)
@@ -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
@@ -0,0 +1,155 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DlgHelpEdition</class>
<widget class="QDialog" name="DlgHelpEdition">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>460</height>
</rect>
</property>
<property name="windowTitle">
<string>Help editor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QWebView" name="webView">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Select element to edit</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="tree">
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="lblDescription">
<property name="text">
<string>Element description</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="text">
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</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>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKit/QWebView</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DlgHelpEdition</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>DlgHelpEdition</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>

0 comments on commit 97639aa

Please sign in to comment.