Skip to content

Commit 95b5068

Browse files
committed
create history dialog from .ui file
1 parent 8cd52d0 commit 95b5068

File tree

2 files changed

+116
-49
lines changed

2 files changed

+116
-49
lines changed

python/plugins/sextante/gui/HistoryDialog.py

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,56 +25,34 @@
2525

2626
from PyQt4.QtCore import *
2727
from PyQt4.QtGui import *
28-
from PyQt4 import QtCore, QtGui
28+
2929
from sextante.core.SextanteLog import SextanteLog
3030

31-
class HistoryDialog(QtGui.QDialog):
31+
from sextante.ui.ui_DlgHistory import Ui_DlgHistory
32+
33+
class HistoryDialog(QDialog, Ui_DlgHistory):
3234
def __init__(self):
33-
QtGui.QDialog.__init__(self)
34-
self.setModal(True)
35-
self.setupUi()
36-
37-
def setupUi(self):
38-
self.resize(650, 505)
39-
self.verticalLayout = QtGui.QVBoxLayout()
40-
self.verticalLayout.setSpacing(2)
41-
self.verticalLayout.setMargin(0)
42-
self.tree = QtGui.QTreeWidget()
43-
self.tree.setHeaderHidden(True)
35+
QDialog.__init__(self)
36+
self.setupUi(self)
37+
38+
self.groupIcon = QIcon()
39+
self.groupIcon.addPixmap(self.style().standardPixmap(QStyle.SP_DirClosedIcon),
40+
QIcon.Normal, QIcon.Off)
41+
self.groupIcon.addPixmap(self.style().standardPixmap(QStyle.SP_DirOpenIcon),
42+
QIcon.Normal, QIcon.On)
43+
44+
self.keyIcon = QIcon()
45+
self.keyIcon.addPixmap(self.style().standardPixmap(QStyle.SP_FileIcon))
46+
47+
self.clearButton = QPushButton(self.tr("Clear"))
48+
self.clearButton.setToolTip(self.tr("Clear history and log"))
49+
self.buttonBox.addButton(self.clearButton, QDialogButtonBox.ActionRole)
50+
4451
self.tree.doubleClicked.connect(self.executeAlgorithm)
45-
self.verticalLayout.addWidget(self.tree)
4652
self.tree.currentItemChanged.connect(self.changeText)
47-
self.groupIcon = QtGui.QIcon()
48-
self.groupIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_DirClosedIcon),
49-
QtGui.QIcon.Normal, QtGui.QIcon.Off)
50-
self.groupIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_DirOpenIcon),
51-
QtGui.QIcon.Normal, QtGui.QIcon.On)
52-
self.keyIcon = QtGui.QIcon()
53-
self.keyIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_FileIcon))
53+
self.clearButton.clicked.connect(self.clearLog)
54+
5455
self.fillTree()
55-
self.text = QtGui.QTextEdit()
56-
self.verticalLayout.addWidget(self.text)
57-
self.text.setReadOnly(True)
58-
self.closeButton = QtGui.QPushButton()
59-
self.closeButton.setText("Close")
60-
self.clearButton = QtGui.QPushButton()
61-
self.clearButton.setText("Clear history")
62-
self.horizontalLayout= QtGui.QHBoxLayout()
63-
self.horizontalLayout.setSpacing(2)
64-
self.horizontalLayout.setMargin(0)
65-
self.horizontalLayout.addStretch(1000)
66-
self.horizontalLayout.addWidget(self.clearButton)
67-
self.horizontalLayout.addWidget(self.closeButton)
68-
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
69-
QObject.connect(self.clearButton, QtCore.SIGNAL("clicked()"), self.clearLog)
70-
self.verticalLayout.addLayout(self.horizontalLayout)
71-
self.setWindowTitle("History")
72-
self.setLayout(self.verticalLayout)
73-
QtCore.QMetaObject.connectSlotsByName(self)
74-
75-
76-
def closeWindow(self):
77-
self.close()
7856

7957
def clearLog(self):
8058
SextanteLog.clearLog()
@@ -84,7 +62,7 @@ def fillTree(self):
8462
self.tree.clear()
8563
elements = SextanteLog.getLogEntries()
8664
for category in elements.keys():
87-
groupItem = QtGui.QTreeWidgetItem()
65+
groupItem = QTreeWidgetItem()
8866
groupItem.setText(0,category)
8967
groupItem.setIcon(0, self.groupIcon)
9068
for entry in elements[category]:
@@ -93,7 +71,6 @@ def fillTree(self):
9371
groupItem.insertChild(0,item)
9472
self.tree.addTopLevelItem(groupItem)
9573

96-
9774
def executeAlgorithm(self):
9875
item = self.tree.currentItem()
9976
if isinstance(item, TreeLogEntryItem):
@@ -102,14 +79,12 @@ def executeAlgorithm(self):
10279
script+=item.entry.text.replace("runalg(","runandload(")
10380
exec(script)
10481

105-
10682
def changeText(self):
10783
item = self.tree.currentItem()
10884
if isinstance(item, TreeLogEntryItem):
10985
self.text.setText(item.entry.text.replace("|","\n"))
11086

111-
112-
class TreeLogEntryItem(QtGui.QTreeWidgetItem):
87+
class TreeLogEntryItem(QTreeWidgetItem):
11388
def __init__(self, entry, isAlg):
11489
QTreeWidgetItem.__init__(self)
11590
self.entry = entry
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>DlgHistory</class>
4+
<widget class="QDialog" name="DlgHistory">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>532</width>
10+
<height>377</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>History and log</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
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">
25+
<property name="orientation">
26+
<enum>Qt::Vertical</enum>
27+
</property>
28+
<widget class="QTreeWidget" name="tree">
29+
<attribute name="headerVisible">
30+
<bool>false</bool>
31+
</attribute>
32+
<column>
33+
<property name="text">
34+
<string notr="true">1</string>
35+
</property>
36+
</column>
37+
</widget>
38+
<widget class="QTextEdit" name="text">
39+
<property name="readOnly">
40+
<bool>true</bool>
41+
</property>
42+
</widget>
43+
</widget>
44+
</item>
45+
<item>
46+
<widget class="QDialogButtonBox" name="buttonBox">
47+
<property name="orientation">
48+
<enum>Qt::Horizontal</enum>
49+
</property>
50+
<property name="standardButtons">
51+
<set>QDialogButtonBox::Close</set>
52+
</property>
53+
</widget>
54+
</item>
55+
</layout>
56+
</widget>
57+
<resources/>
58+
<connections>
59+
<connection>
60+
<sender>buttonBox</sender>
61+
<signal>accepted()</signal>
62+
<receiver>DlgHistory</receiver>
63+
<slot>accept()</slot>
64+
<hints>
65+
<hint type="sourcelabel">
66+
<x>248</x>
67+
<y>254</y>
68+
</hint>
69+
<hint type="destinationlabel">
70+
<x>157</x>
71+
<y>274</y>
72+
</hint>
73+
</hints>
74+
</connection>
75+
<connection>
76+
<sender>buttonBox</sender>
77+
<signal>rejected()</signal>
78+
<receiver>DlgHistory</receiver>
79+
<slot>reject()</slot>
80+
<hints>
81+
<hint type="sourcelabel">
82+
<x>316</x>
83+
<y>260</y>
84+
</hint>
85+
<hint type="destinationlabel">
86+
<x>286</x>
87+
<y>274</y>
88+
</hint>
89+
</hints>
90+
</connection>
91+
</connections>
92+
</ui>

0 commit comments

Comments
 (0)