2012-10-05 23:28:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
SextantePlugin.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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2013-03-24 15:27:43 +01:00
|
|
|
import shutil
|
2012-10-05 23:28:47 +02:00
|
|
|
|
|
|
|
__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-18 14:47:49 +03:00
|
|
|
import os, sys
|
|
|
|
import inspect
|
2012-09-15 18:25:25 +03:00
|
|
|
from PyQt4.QtCore import *
|
|
|
|
from PyQt4.QtGui import *
|
|
|
|
from qgis.core import *
|
|
|
|
from sextante.core.Sextante import Sextante
|
|
|
|
from sextante.core.QGisLayers import QGisLayers
|
|
|
|
from sextante.core.SextanteUtils import SextanteUtils
|
2012-09-18 14:47:49 +03:00
|
|
|
|
|
|
|
from sextante.gui.SextanteToolbox import SextanteToolbox
|
|
|
|
from sextante.gui.HistoryDialog import HistoryDialog
|
2012-09-15 18:25:25 +03:00
|
|
|
from sextante.gui.ConfigDialog import ConfigDialog
|
|
|
|
from sextante.gui.ResultsDialog import ResultsDialog
|
2012-09-18 14:47:49 +03:00
|
|
|
|
|
|
|
from sextante.modeler.ModelerDialog import ModelerDialog
|
|
|
|
|
2012-10-30 15:00:07 +02:00
|
|
|
import sextante.resources_rc
|
2012-09-18 20:02:43 +03:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
cmd_folder = os.path.split(inspect.getfile( inspect.currentframe() ))[0]
|
|
|
|
if cmd_folder not in sys.path:
|
|
|
|
sys.path.insert(0, cmd_folder)
|
|
|
|
|
|
|
|
class SextantePlugin:
|
|
|
|
|
|
|
|
def __init__(self, iface):
|
|
|
|
self.iface = iface
|
|
|
|
QGisLayers.setInterface(iface)
|
|
|
|
Sextante.initialize()
|
|
|
|
Sextante.setInterface(iface)
|
|
|
|
|
|
|
|
def initGui(self):
|
|
|
|
self.toolbox = SextanteToolbox(self.iface)
|
2012-10-30 15:00:07 +02:00
|
|
|
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
|
|
|
|
self.toolbox.hide()
|
2012-09-15 18:25:25 +03:00
|
|
|
Sextante.addAlgListListener(self.toolbox)
|
|
|
|
|
|
|
|
self.menu = QMenu(self.iface.mainWindow())
|
2012-09-18 14:47:49 +03:00
|
|
|
self.menu.setTitle(QCoreApplication.translate("SEXTANTE", "Analysis"))
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2012-12-03 20:13:34 +02:00
|
|
|
self.toolboxAction = self.toolbox.toggleViewAction()
|
|
|
|
self.toolboxAction.setIcon(QIcon(":/sextante/images/toolbox.png"))
|
|
|
|
self.toolboxAction.setText(QCoreApplication.translate("SEXTANTE", "&SEXTANTE toolbox"))
|
2012-09-15 18:25:25 +03:00
|
|
|
self.menu.addAction(self.toolboxAction)
|
|
|
|
|
2012-09-18 20:02:43 +03:00
|
|
|
self.modelerAction = QAction(QIcon(":/sextante/images/model.png"),
|
2012-10-25 14:57:29 +03:00
|
|
|
QCoreApplication.translate("SEXTANTE", "&SEXTANTE modeler"),
|
2012-09-18 14:47:49 +03:00
|
|
|
self.iface.mainWindow())
|
2012-12-03 20:13:34 +02:00
|
|
|
self.modelerAction.triggered.connect(self.openModeler)
|
2012-09-15 18:25:25 +03:00
|
|
|
self.menu.addAction(self.modelerAction)
|
|
|
|
|
2012-09-18 20:02:43 +03:00
|
|
|
self.historyAction = QAction(QIcon(":/sextante/images/history.gif"),
|
2012-10-25 14:57:29 +03:00
|
|
|
QCoreApplication.translate("SEXTANTE", "&SEXTANTE history and log"),
|
2012-09-18 14:47:49 +03:00
|
|
|
self.iface.mainWindow())
|
2012-12-03 20:13:34 +02:00
|
|
|
self.historyAction.triggered.connect(self.openHistory)
|
2012-09-15 18:25:25 +03:00
|
|
|
self.menu.addAction(self.historyAction)
|
|
|
|
|
2012-09-18 20:02:43 +03:00
|
|
|
self.configAction = QAction(QIcon(":/sextante/images/config.png"),
|
2012-09-18 14:47:49 +03:00
|
|
|
QCoreApplication.translate("SEXTANTE", "&SEXTANTE options and configuration"),
|
|
|
|
self.iface.mainWindow())
|
2012-12-03 20:13:34 +02:00
|
|
|
self.configAction.triggered.connect(self.openConfig)
|
2012-09-15 18:25:25 +03:00
|
|
|
self.menu.addAction(self.configAction)
|
|
|
|
|
2012-09-18 20:02:43 +03:00
|
|
|
self.resultsAction = QAction(QIcon(":/sextante/images/results.png"),
|
2012-09-18 14:47:49 +03:00
|
|
|
QCoreApplication.translate("SEXTANTE", "&SEXTANTE results viewer"),
|
|
|
|
self.iface.mainWindow())
|
2012-12-03 20:13:34 +02:00
|
|
|
self.resultsAction.triggered.connect(self.openResults)
|
2012-09-15 18:25:25 +03:00
|
|
|
self.menu.addAction(self.resultsAction)
|
|
|
|
|
|
|
|
menuBar = self.iface.mainWindow().menuBar()
|
|
|
|
menuBar.insertMenu(menuBar.actions()[-1], self.menu)
|
|
|
|
|
|
|
|
def unload(self):
|
|
|
|
self.toolbox.setVisible(False)
|
|
|
|
self.menu.deleteLater()
|
|
|
|
#delete temporary output files
|
|
|
|
folder = SextanteUtils.tempFolder()
|
2012-12-20 10:42:44 +02:00
|
|
|
if QDir(folder).exists():
|
2013-03-24 15:27:43 +01:00
|
|
|
shutil.rmtree(folder, True)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def openToolbox(self):
|
2012-10-30 15:00:07 +02:00
|
|
|
if self.toolbox.isVisible():
|
|
|
|
self.toolbox.hide()
|
|
|
|
else:
|
|
|
|
self.toolbox.show()
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def openModeler(self):
|
|
|
|
dlg = ModelerDialog()
|
|
|
|
dlg.exec_()
|
|
|
|
if dlg.update:
|
|
|
|
self.toolbox.updateTree()
|
|
|
|
|
|
|
|
def openResults(self):
|
|
|
|
dlg = ResultsDialog()
|
|
|
|
dlg.exec_()
|
|
|
|
|
|
|
|
def openHistory(self):
|
|
|
|
dlg = HistoryDialog()
|
|
|
|
dlg.exec_()
|
|
|
|
|
|
|
|
def openConfig(self):
|
|
|
|
dlg = ConfigDialog(self.toolbox)
|
|
|
|
dlg.exec_()
|
|
|
|
|