2012-10-05 23:28:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
HistoryDialog.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
from PyQt4.QtCore import *
|
|
|
|
from PyQt4.QtGui import *
|
2013-04-27 00:34:57 +02:00
|
|
|
from sextante.gui import TestTools
|
2012-09-15 18:25:25 +03:00
|
|
|
from sextante.core.SextanteLog import SextanteLog
|
2012-12-01 16:48:56 +02:00
|
|
|
from sextante.ui.ui_DlgHistory import Ui_DlgHistory
|
|
|
|
|
2013-02-17 23:14:12 +01:00
|
|
|
|
2012-12-01 16:48:56 +02:00
|
|
|
class HistoryDialog(QDialog, Ui_DlgHistory):
|
2012-09-15 18:25:25 +03:00
|
|
|
def __init__(self):
|
2012-12-01 16:48:56 +02:00
|
|
|
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)
|
|
|
|
|
2013-02-28 22:08:32 +01:00
|
|
|
self.tree.doubleClicked.connect(self.executeAlgorithm)
|
2012-09-15 18:25:25 +03:00
|
|
|
self.tree.currentItemChanged.connect(self.changeText)
|
2012-12-01 16:48:56 +02:00
|
|
|
self.clearButton.clicked.connect(self.clearLog)
|
2013-02-28 22:08:32 +01:00
|
|
|
|
2013-02-17 23:14:12 +01:00
|
|
|
self.tree.customContextMenuRequested.connect(self.showPopupMenu)
|
2012-12-01 16:48:56 +02:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
self.fillTree()
|
|
|
|
|
|
|
|
def clearLog(self):
|
|
|
|
SextanteLog.clearLog()
|
|
|
|
self.fillTree()
|
|
|
|
|
|
|
|
def fillTree(self):
|
|
|
|
self.tree.clear()
|
|
|
|
elements = SextanteLog.getLogEntries()
|
|
|
|
for category in elements.keys():
|
2012-12-01 16:48:56 +02:00
|
|
|
groupItem = QTreeWidgetItem()
|
2012-09-15 18:25:25 +03:00
|
|
|
groupItem.setText(0,category)
|
|
|
|
groupItem.setIcon(0, self.groupIcon)
|
|
|
|
for entry in elements[category]:
|
|
|
|
item = TreeLogEntryItem(entry, category==SextanteLog.LOG_ALGORITHM)
|
|
|
|
item.setIcon(0, self.keyIcon)
|
|
|
|
groupItem.insertChild(0,item)
|
|
|
|
self.tree.addTopLevelItem(groupItem)
|
|
|
|
|
|
|
|
def executeAlgorithm(self):
|
|
|
|
item = self.tree.currentItem()
|
|
|
|
if isinstance(item, TreeLogEntryItem):
|
|
|
|
if item.isAlg:
|
2012-11-28 01:56:44 +01:00
|
|
|
script = "import sextante\n"
|
2012-09-15 18:25:25 +03:00
|
|
|
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"))
|
2013-02-28 22:08:32 +01:00
|
|
|
|
2013-02-17 23:14:12 +01:00
|
|
|
def createTest(self):
|
|
|
|
item = self.tree.currentItem()
|
|
|
|
if isinstance(item, TreeLogEntryItem):
|
|
|
|
if item.isAlg:
|
2013-03-23 21:45:52 +01:00
|
|
|
TestTools.createTest(item.entry.text)
|
2013-02-28 22:08:32 +01:00
|
|
|
|
2013-02-17 23:14:12 +01:00
|
|
|
def showPopupMenu(self,point):
|
|
|
|
item = self.tree.currentItem()
|
|
|
|
if isinstance(item, TreeLogEntryItem):
|
|
|
|
if item.isAlg:
|
|
|
|
popupmenu = QMenu()
|
|
|
|
createTestAction = QAction(self.tr("Create test"), self.tree)
|
|
|
|
createTestAction.triggered.connect(self.createTest)
|
2013-02-28 22:08:32 +01:00
|
|
|
popupmenu.addAction(createTestAction)
|
|
|
|
popupmenu.exec_(self.tree.mapToGlobal(point))
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2012-12-01 16:48:56 +02:00
|
|
|
class TreeLogEntryItem(QTreeWidgetItem):
|
2012-09-15 18:25:25 +03:00
|
|
|
def __init__(self, entry, isAlg):
|
|
|
|
QTreeWidgetItem.__init__(self)
|
|
|
|
self.entry = entry
|
|
|
|
self.isAlg = isAlg
|
|
|
|
self.setText(0, "[" + entry.date + "] " + entry.text.split("|")[0])
|