Skip to content

Commit 97639aa

Browse files
committed
create help edition dialog from .ui
1 parent 6518a97 commit 97639aa

File tree

2 files changed

+183
-75
lines changed

2 files changed

+183
-75
lines changed

python/plugins/sextante/gui/HelpEditionDialog.py

Lines changed: 28 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -23,101 +23,49 @@
2323
# This will get replaced with a git SHA1 when you do a git archive
2424
__revision__ = '$Format:%H$'
2525

26-
from PyQt4.QtCore import *
27-
from PyQt4.QtGui import *
28-
from PyQt4 import QtCore, QtGui, QtWebKit
2926
import os
3027
import pickle
3128

32-
class HelpEditionDialog(QtGui.QDialog):
29+
from PyQt4.QtCore import *
30+
from PyQt4.QtGui import *
31+
32+
from sextante.ui.ui_DlgHelpEdition import Ui_DlgHelpEdition
33+
34+
class HelpEditionDialog(QDialog, Ui_DlgHelpEdition):
3335

3436
ALG_DESC = "ALG_DESC"
3537
ALG_CREATOR = "ALG_CREATOR"
3638
ALG_HELP_CREATOR = "ALG_HELP_CREATOR"
3739

3840
def __init__(self, alg):
41+
QDialog.__init__(self)
42+
self.setupUi(self)
43+
3944
self.alg = alg
40-
QtGui.QDialog.__init__(self)
41-
self.setModal(True)
4245
self.descriptions = {}
4346
if self.alg.descriptionFile is not None:
4447
helpfile = alg.descriptionFile + ".help"
4548
if os.path.exists(helpfile):
4649
f = open(helpfile, "rb")
4750
self.descriptions = pickle.load(f)
4851
self.currentName = self.ALG_DESC
49-
self.setupUi()
50-
51-
def setupUi(self):
52-
self.resize(700, 500)
53-
self.tree = QtGui.QTreeWidget()
54-
self.tree.setHeaderHidden(True)
55-
self.tree.setMinimumWidth(300)
56-
QObject.connect(self.tree, QtCore.SIGNAL("itemClicked(QTreeWidgetItem*, int)"), self.changeItem)
57-
self.groupIcon = QtGui.QIcon()
58-
self.groupIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_DirClosedIcon),
59-
QtGui.QIcon.Normal, QtGui.QIcon.Off)
60-
self.groupIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_DirOpenIcon),
61-
QtGui.QIcon.Normal, QtGui.QIcon.On)
62-
self.keyIcon = QtGui.QIcon()
63-
self.keyIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_FileIcon))
52+
53+
self.tree.itemClicked.connect(self.changeItem)
54+
6455
self.fillTree()
65-
self.setWindowTitle("Help editor")
66-
self.horizontalLayout= QtGui.QHBoxLayout()
67-
self.horizontalLayout.setSpacing(15)
68-
self.horizontalLayout.setMargin(0)
69-
self.label = QtGui.QLabel()
70-
self.label.setText("Select elements on the tree and fill their description in the text box below")
71-
self.labelName = QtGui.QLabel()
72-
self.labelName.setText("Algorithm description")
73-
self.text = QtGui.QTextEdit()
74-
self.text.setMinimumHeight(200)
75-
self.verticalLayout= QtGui.QVBoxLayout()
76-
self.verticalLayout.setSpacing(5)
77-
self.verticalLayout.setMargin(0)
78-
self.verticalLayout.addWidget(self.tree)
79-
self.verticalLayout.addSpacing(20)
80-
self.verticalLayout.addWidget(self.label)
81-
self.verticalLayout.addSpacing(20)
82-
self.verticalLayout.addWidget(self.labelName)
83-
self.verticalLayout.addWidget(self.text)
84-
self.horizontalLayout.addLayout(self.verticalLayout)
85-
self.webView = QtWebKit.QWebView()
86-
self.webView.setMinimumWidth(300)
87-
self.webView.setHtml(self.getHtml())
88-
self.horizontalLayout.addWidget(self.webView)
89-
self.closeButton = QtGui.QPushButton()
90-
self.closeButton.setText("Cancel")
91-
self.saveButton = QtGui.QPushButton()
92-
self.saveButton.setText("OK")
93-
self.horizontalLayout2= QtGui.QHBoxLayout()
94-
self.horizontalLayout2.setSpacing(2)
95-
self.horizontalLayout2.setMargin(0)
96-
self.horizontalLayout2.addStretch(1000)
97-
self.horizontalLayout2.addWidget(self.saveButton)
98-
self.horizontalLayout2.addWidget(self.closeButton)
99-
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
100-
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveHelp)
101-
self.verticalLayout2= QtGui.QVBoxLayout()
102-
self.verticalLayout2.setSpacing(2)
103-
self.verticalLayout2.setMargin(0)
104-
self.verticalLayout2.addLayout(self.horizontalLayout)
105-
self.verticalLayout2.addLayout(self.horizontalLayout2)
106-
self.setLayout(self.verticalLayout2)
107-
QtCore.QMetaObject.connectSlotsByName(self)
10856
self.updateHtmlView()
10957

110-
def closeWindow(self):
58+
def reject(self):
11159
self.descriptions = None
112-
self.close()
60+
QDialog.reject(self)
11361

114-
def saveHelp(self):
115-
self.descriptions[self.currentName] = str(self.text.toPlainText())
62+
def accept(self):
63+
self.descriptions[self.currentName] = unicode(self.text.toPlainText())
11664
if self.alg.descriptionFile is not None:
11765
f = open(self.alg.descriptionFile + ".help", "wb")
11866
pickle.dump(self.descriptions, f)
11967
f.close()
120-
self.close()
68+
QDialog.accept(self)
12169

12270
def getHtml(self):
12371
s = "<h2>Algorithm description</h2>\n"
@@ -140,7 +88,7 @@ def fillTree(self):
14088
for param in self.alg.parameters:
14189
item = TreeDescriptionItem(param.description, param.name)
14290
parametersItem.addChild(item)
143-
outputsItem = TreeDescriptionItem("Outputs", None)
91+
outputsItem = TreeDescriptionItem(self.tr("Outputs"), None)
14492
self.tree.addTopLevelItem(outputsItem)
14593
for out in self.alg.outputs:
14694
item = TreeDescriptionItem(out.description, out.name)
@@ -154,27 +102,32 @@ def changeItem(self):
154102
item = self.tree.currentItem()
155103
if isinstance(item, TreeDescriptionItem):
156104
if self.currentName:
157-
self.descriptions[self.currentName] = str(self.text.toPlainText())
105+
self.descriptions[self.currentName] = unicode(self.text.toPlainText())
158106
name = item.name
159107
if name:
108+
self.text.setEnabled(True)
160109
self.updateHtmlView()
161110
self.currentName = name
162-
self.labelName.setText(item.description)
163111
if name in self.descriptions:
164112
self.text.setText(self.descriptions[name])
165113
else:
166-
self.text.setText("")
114+
self.text.clear()
115+
else:
116+
self.currentName = None
117+
self.text.clear()
118+
self.text.setEnabled(False)
119+
self.updateHtmlView()
167120

168121
def updateHtmlView(self):
169122
self.webView.setHtml(self.getHtml())
170123

171124
def getDescription(self, name):
172-
if name in self.descriptions :
125+
if name in self.descriptions:
173126
return self.descriptions[name]
174127
else:
175128
return ""
176129

177-
class TreeDescriptionItem(QtGui.QTreeWidgetItem):
130+
class TreeDescriptionItem(QTreeWidgetItem):
178131
def __init__(self, description, name):
179132
QTreeWidgetItem.__init__(self)
180133
self.name = name
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>DlgHelpEdition</class>
4+
<widget class="QDialog" name="DlgHelpEdition">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>600</width>
10+
<height>460</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Help editor</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout_3">
17+
<property name="spacing">
18+
<number>2</number>
19+
</property>
20+
<property name="margin">
21+
<number>0</number>
22+
</property>
23+
<item>
24+
<widget class="QSplitter" name="splitter_2">
25+
<property name="orientation">
26+
<enum>Qt::Vertical</enum>
27+
</property>
28+
<widget class="QWebView" name="webView">
29+
<property name="url">
30+
<url>
31+
<string>about:blank</string>
32+
</url>
33+
</property>
34+
</widget>
35+
<widget class="QSplitter" name="splitter">
36+
<property name="orientation">
37+
<enum>Qt::Horizontal</enum>
38+
</property>
39+
<widget class="QWidget" name="">
40+
<layout class="QVBoxLayout" name="verticalLayout">
41+
<property name="spacing">
42+
<number>2</number>
43+
</property>
44+
<item>
45+
<widget class="QLabel" name="label">
46+
<property name="text">
47+
<string>Select element to edit</string>
48+
</property>
49+
</widget>
50+
</item>
51+
<item>
52+
<widget class="QTreeWidget" name="tree">
53+
<property name="minimumSize">
54+
<size>
55+
<width>0</width>
56+
<height>200</height>
57+
</size>
58+
</property>
59+
<property name="alternatingRowColors">
60+
<bool>true</bool>
61+
</property>
62+
<attribute name="headerVisible">
63+
<bool>false</bool>
64+
</attribute>
65+
<column>
66+
<property name="text">
67+
<string notr="true">1</string>
68+
</property>
69+
</column>
70+
</widget>
71+
</item>
72+
</layout>
73+
</widget>
74+
<widget class="QWidget" name="">
75+
<layout class="QVBoxLayout" name="verticalLayout_2">
76+
<property name="spacing">
77+
<number>2</number>
78+
</property>
79+
<item>
80+
<widget class="QLabel" name="lblDescription">
81+
<property name="text">
82+
<string>Element description</string>
83+
</property>
84+
</widget>
85+
</item>
86+
<item>
87+
<widget class="QTextEdit" name="text">
88+
<property name="minimumSize">
89+
<size>
90+
<width>0</width>
91+
<height>200</height>
92+
</size>
93+
</property>
94+
</widget>
95+
</item>
96+
</layout>
97+
</widget>
98+
</widget>
99+
</widget>
100+
</item>
101+
<item>
102+
<widget class="QDialogButtonBox" name="buttonBox">
103+
<property name="orientation">
104+
<enum>Qt::Horizontal</enum>
105+
</property>
106+
<property name="standardButtons">
107+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
108+
</property>
109+
</widget>
110+
</item>
111+
</layout>
112+
</widget>
113+
<customwidgets>
114+
<customwidget>
115+
<class>QWebView</class>
116+
<extends>QWidget</extends>
117+
<header>QtWebKit/QWebView</header>
118+
</customwidget>
119+
</customwidgets>
120+
<resources/>
121+
<connections>
122+
<connection>
123+
<sender>buttonBox</sender>
124+
<signal>accepted()</signal>
125+
<receiver>DlgHelpEdition</receiver>
126+
<slot>accept()</slot>
127+
<hints>
128+
<hint type="sourcelabel">
129+
<x>248</x>
130+
<y>254</y>
131+
</hint>
132+
<hint type="destinationlabel">
133+
<x>157</x>
134+
<y>274</y>
135+
</hint>
136+
</hints>
137+
</connection>
138+
<connection>
139+
<sender>buttonBox</sender>
140+
<signal>rejected()</signal>
141+
<receiver>DlgHelpEdition</receiver>
142+
<slot>reject()</slot>
143+
<hints>
144+
<hint type="sourcelabel">
145+
<x>316</x>
146+
<y>260</y>
147+
</hint>
148+
<hint type="destinationlabel">
149+
<x>286</x>
150+
<y>274</y>
151+
</hint>
152+
</hints>
153+
</connection>
154+
</connections>
155+
</ui>

0 commit comments

Comments
 (0)