2012-10-05 23:28:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
2013-08-12 20:44:27 +02:00
|
|
|
ProcessingPlugin.py
|
2012-10-05 23:28:47 +02:00
|
|
|
---------------------
|
|
|
|
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-10-01 20:52:22 +03:00
|
|
|
|
2013-09-12 13:19:00 +02:00
|
|
|
from processing import interface
|
2012-10-05 23:28:47 +02:00
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-05 23:28:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-05 23:28:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2013-03-28 21:25:02 +01:00
|
|
|
import shutil
|
2012-09-18 14:47:49 +03:00
|
|
|
import inspect
|
2012-09-15 18:25:25 +03:00
|
|
|
from PyQt4.QtCore import *
|
|
|
|
from PyQt4.QtGui import *
|
|
|
|
from qgis.core import *
|
2013-08-12 20:44:27 +02:00
|
|
|
from processing.core.Processing import Processing
|
|
|
|
from processing.gui.ProcessingToolbox import ProcessingToolbox
|
|
|
|
from processing.gui.HistoryDialog import HistoryDialog
|
|
|
|
from processing.gui.ConfigDialog import ConfigDialog
|
|
|
|
from processing.gui.ResultsDialog import ResultsDialog
|
|
|
|
from processing.modeler.ModelerDialog import ModelerDialog
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.gui.CommanderWindow import CommanderWindow
|
2013-10-01 20:52:22 +03:00
|
|
|
from processing.tools import dataobjects
|
|
|
|
from processing.tools.system import *
|
2013-08-12 20:44:27 +02:00
|
|
|
import processing.resources_rc
|
2012-09-18 20:02:43 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
|
2012-09-15 18:25:25 +03:00
|
|
|
if cmd_folder not in sys.path:
|
2013-03-31 21:18:27 +02:00
|
|
|
sys.path.insert(0, cmd_folder)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-08-12 20:44:27 +02:00
|
|
|
class ProcessingPlugin:
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def __init__(self, iface):
|
2013-09-17 12:33:57 +02:00
|
|
|
interface.iface = iface
|
|
|
|
Processing.initialize()
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-05-01 23:45:20 +02:00
|
|
|
def initGui(self):
|
2013-04-27 00:34:57 +02:00
|
|
|
self.commander = None
|
2013-09-12 13:19:00 +02:00
|
|
|
self.toolbox = ProcessingToolbox()
|
|
|
|
interface.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
|
2012-10-30 15:00:07 +02:00
|
|
|
self.toolbox.hide()
|
2014-03-26 10:18:27 +01:00
|
|
|
#Processing.addAlgListListener(self.toolbox)
|
2013-05-01 23:45:20 +02:00
|
|
|
|
2014-04-03 18:12:56 +02:00
|
|
|
self.menu = QMenu(interface.iface.mainWindow().menuBar())
|
|
|
|
self.menu.setObjectName( 'processing' )
|
2013-10-01 20:52:22 +03:00
|
|
|
self.menu.setTitle(QCoreApplication.translate('Processing',
|
|
|
|
'Processing'))
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2012-12-03 20:13:34 +02:00
|
|
|
self.toolboxAction = self.toolbox.toggleViewAction()
|
2014-04-03 18:12:56 +02:00
|
|
|
self.toolboxAction.setObjectName( 'toolboxAction' )
|
2013-10-01 20:52:22 +03:00
|
|
|
self.toolboxAction.setIcon(QIcon(':/processing/images/alg.png'))
|
|
|
|
self.toolboxAction.setText(QCoreApplication.translate('Processing',
|
|
|
|
'Toolbox'))
|
2012-09-15 18:25:25 +03:00
|
|
|
self.menu.addAction(self.toolboxAction)
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
self.modelerAction = QAction(QIcon(':/processing/images/model.png'),
|
|
|
|
QCoreApplication.translate('Processing',
|
|
|
|
'Graphical modeler'),
|
|
|
|
interface.iface.mainWindow())
|
2014-04-03 18:12:56 +02:00
|
|
|
self.modelerAction.setObjectName( 'modelerAction' )
|
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)
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
self.historyAction = QAction(QIcon(':/processing/images/history.gif'),
|
|
|
|
QCoreApplication.translate('Processing',
|
|
|
|
'History and log'),
|
|
|
|
interface.iface.mainWindow())
|
2014-04-03 18:12:56 +02:00
|
|
|
self.historyAction.setObjectName( 'historyAction' )
|
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)
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
self.configAction = QAction(QIcon(':/processing/images/config.png'),
|
|
|
|
QCoreApplication.translate('Processing',
|
|
|
|
'Options and configuration'),
|
|
|
|
interface.iface.mainWindow())
|
2014-04-03 18:12:56 +02:00
|
|
|
self.configAction.setObjectName( 'configAction' )
|
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)
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
self.resultsAction = QAction(QIcon(':/processing/images/results.png'),
|
|
|
|
QCoreApplication.translate('Processing',
|
|
|
|
'&Results viewer'),
|
|
|
|
interface.iface.mainWindow())
|
2014-04-03 18:12:56 +02:00
|
|
|
self.resultsAction.setObjectName( 'resultsAction' )
|
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)
|
|
|
|
|
2013-09-12 13:19:00 +02:00
|
|
|
menuBar = interface.iface.mainWindow().menuBar()
|
2013-10-01 20:52:22 +03:00
|
|
|
menuBar.insertMenu(
|
|
|
|
interface.iface.firstRightStandardMenu().menuAction(), self.menu)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
self.commanderAction = QAction(
|
|
|
|
QIcon(':/processing/images/commander.png'),
|
|
|
|
QCoreApplication.translate('Processing', '&Commander'),
|
|
|
|
interface.iface.mainWindow())
|
2014-04-03 18:12:56 +02:00
|
|
|
self.commanderAction.setObjectName( 'commanderAction' )
|
2013-04-13 15:05:19 +02:00
|
|
|
self.commanderAction.triggered.connect(self.openCommander)
|
|
|
|
self.menu.addAction(self.commanderAction)
|
2013-10-01 20:52:22 +03:00
|
|
|
interface.iface.registerMainWindowAction(self.commanderAction,
|
|
|
|
'Ctrl+Alt+M')
|
2013-04-13 15:05:19 +02:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
def unload(self):
|
|
|
|
self.toolbox.setVisible(False)
|
|
|
|
self.menu.deleteLater()
|
2013-10-01 20:52:22 +03:00
|
|
|
|
|
|
|
# delete temporary output files
|
2013-09-12 13:19:00 +02:00
|
|
|
folder = 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)
|
2013-05-01 23:45:20 +02:00
|
|
|
|
2013-09-12 13:19:00 +02:00
|
|
|
interface.iface.unregisterMainWindowAction(self.commanderAction)
|
2013-05-01 23:45:20 +02:00
|
|
|
|
|
|
|
def openCommander(self):
|
2013-04-27 00:34:57 +02:00
|
|
|
if self.commander is None:
|
2013-10-01 20:52:22 +03:00
|
|
|
self.commander = CommanderWindow(interface.iface.mainWindow(),
|
|
|
|
interface.iface.mapCanvas())
|
2013-08-12 20:44:27 +02:00
|
|
|
Processing.addAlgListListener(self.commander)
|
2013-04-27 00:34:57 +02:00
|
|
|
self.commander.prepareGui()
|
2013-05-01 23:45:20 +02:00
|
|
|
self.commander.show()
|
|
|
|
|
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()
|
2014-03-25 16:45:59 +02:00
|
|
|
dlg.show()
|
2012-09-15 18:25:25 +03:00
|
|
|
dlg.exec_()
|
|
|
|
if dlg.update:
|
2014-03-26 10:18:27 +01:00
|
|
|
Processing.updateAlgsList()
|
|
|
|
self.toolbox.updateProvider('model')
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def openResults(self):
|
|
|
|
dlg = ResultsDialog()
|
2014-03-25 16:45:59 +02:00
|
|
|
dlg.show()
|
2012-09-15 18:25:25 +03:00
|
|
|
dlg.exec_()
|
|
|
|
|
|
|
|
def openHistory(self):
|
|
|
|
dlg = HistoryDialog()
|
|
|
|
dlg.exec_()
|
|
|
|
|
|
|
|
def openConfig(self):
|
|
|
|
dlg = ConfigDialog(self.toolbox)
|
|
|
|
dlg.exec_()
|