Skip to content
Permalink
Browse files
create history dialog from .ui file
  • Loading branch information
alexbruy committed Dec 3, 2012
1 parent 8cd52d0 commit 95b506882dd420d98ebfe63eebacc73012c77348
Showing with 116 additions and 49 deletions.
  1. +24 −49 python/plugins/sextante/gui/HistoryDialog.py
  2. +92 −0 python/plugins/sextante/ui/DlgHistory.ui
@@ -25,56 +25,34 @@

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui

from sextante.core.SextanteLog import SextanteLog

class HistoryDialog(QtGui.QDialog):
from sextante.ui.ui_DlgHistory import Ui_DlgHistory

class HistoryDialog(QDialog, Ui_DlgHistory):
def __init__(self):
QtGui.QDialog.__init__(self)
self.setModal(True)
self.setupUi()

def setupUi(self):
self.resize(650, 505)
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setSpacing(2)
self.verticalLayout.setMargin(0)
self.tree = QtGui.QTreeWidget()
self.tree.setHeaderHidden(True)
QDialog.__init__(self)
self.setupUi(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)

self.keyIcon = QIcon()
self.keyIcon.addPixmap(self.style().standardPixmap(QStyle.SP_FileIcon))

self.clearButton = QPushButton(self.tr("Clear"))
self.clearButton.setToolTip(self.tr("Clear history and log"))
self.buttonBox.addButton(self.clearButton, QDialogButtonBox.ActionRole)

self.tree.doubleClicked.connect(self.executeAlgorithm)
self.verticalLayout.addWidget(self.tree)
self.tree.currentItemChanged.connect(self.changeText)
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.clearButton.clicked.connect(self.clearLog)

self.fillTree()
self.text = QtGui.QTextEdit()
self.verticalLayout.addWidget(self.text)
self.text.setReadOnly(True)
self.closeButton = QtGui.QPushButton()
self.closeButton.setText("Close")
self.clearButton = QtGui.QPushButton()
self.clearButton.setText("Clear history")
self.horizontalLayout= QtGui.QHBoxLayout()
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.addStretch(1000)
self.horizontalLayout.addWidget(self.clearButton)
self.horizontalLayout.addWidget(self.closeButton)
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
QObject.connect(self.clearButton, QtCore.SIGNAL("clicked()"), self.clearLog)
self.verticalLayout.addLayout(self.horizontalLayout)
self.setWindowTitle("History")
self.setLayout(self.verticalLayout)
QtCore.QMetaObject.connectSlotsByName(self)


def closeWindow(self):
self.close()

def clearLog(self):
SextanteLog.clearLog()
@@ -84,7 +62,7 @@ def fillTree(self):
self.tree.clear()
elements = SextanteLog.getLogEntries()
for category in elements.keys():
groupItem = QtGui.QTreeWidgetItem()
groupItem = QTreeWidgetItem()
groupItem.setText(0,category)
groupItem.setIcon(0, self.groupIcon)
for entry in elements[category]:
@@ -93,7 +71,6 @@ def fillTree(self):
groupItem.insertChild(0,item)
self.tree.addTopLevelItem(groupItem)


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


def changeText(self):
item = self.tree.currentItem()
if isinstance(item, TreeLogEntryItem):
self.text.setText(item.entry.text.replace("|","\n"))


class TreeLogEntryItem(QtGui.QTreeWidgetItem):
class TreeLogEntryItem(QTreeWidgetItem):
def __init__(self, entry, isAlg):
QTreeWidgetItem.__init__(self)
self.entry = entry
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DlgHistory</class>
<widget class="QDialog" name="DlgHistory">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>532</width>
<height>377</height>
</rect>
</property>
<property name="windowTitle">
<string>History and log</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTreeWidget" name="tree">
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
<widget class="QTextEdit" name="text">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DlgHistory</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>DlgHistory</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 95b5068

Please sign in to comment.