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
|
|
|
|
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
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from PyQt4.QtCore import Qt, QCoreApplication, QDir
|
|
|
|
from PyQt4.QtGui import QMenu, QAction, QIcon
|
2015-02-03 11:22:34 +02:00
|
|
|
|
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
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.gui.CommanderWindow import CommanderWindow
|
2015-02-03 11:22:34 +02:00
|
|
|
from processing.modeler.ModelerDialog import ModelerDialog
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
from processing.tools.system import tempFolder
|
|
|
|
|
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
|
|
|
|
2015-08-22 14:29:41 +02:00
|
|
|
|
2013-08-12 20:44:27 +02:00
|
|
|
class ProcessingPlugin:
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def __init__(self, iface):
|
2014-05-20 16:30:59 +02:00
|
|
|
self.iface = iface
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-05-01 23:45:20 +02:00
|
|
|
def initGui(self):
|
2014-09-24 10:40:36 +02:00
|
|
|
Processing.initialize()
|
|
|
|
|
2013-04-27 00:34:57 +02:00
|
|
|
self.commander = None
|
2013-09-12 13:19:00 +02:00
|
|
|
self.toolbox = ProcessingToolbox()
|
2014-05-20 16:30:59 +02:00
|
|
|
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
|
2012-10-30 15:00:07 +02:00
|
|
|
self.toolbox.hide()
|
2014-06-13 06:25:50 +02:00
|
|
|
Processing.addAlgListListener(self.toolbox)
|
2013-05-01 23:45:20 +02:00
|
|
|
|
2014-05-20 16:30:59 +02:00
|
|
|
self.menu = QMenu(self.iface.mainWindow().menuBar())
|
2015-02-03 11:22:34 +02:00
|
|
|
self.menu.setObjectName('processing')
|
|
|
|
self.menu.setTitle(self.tr('Pro&cessing'))
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2012-12-03 20:13:34 +02:00
|
|
|
self.toolboxAction = self.toolbox.toggleViewAction()
|
2015-02-03 11:22:34 +02:00
|
|
|
self.toolboxAction.setObjectName('toolboxAction')
|
2015-05-18 19:51:26 +03:00
|
|
|
self.toolboxAction.setIcon(
|
|
|
|
QIcon(os.path.join(cmd_folder, 'images', 'alg.png')))
|
2015-02-03 11:22:34 +02:00
|
|
|
self.toolboxAction.setText(self.tr('&Toolbox'))
|
2012-09-15 18:25:25 +03:00
|
|
|
self.menu.addAction(self.toolboxAction)
|
|
|
|
|
2015-05-18 19:51:26 +03:00
|
|
|
self.modelerAction = QAction(
|
|
|
|
QIcon(os.path.join(cmd_folder, 'images', 'model.png')),
|
2015-02-03 11:22:34 +02:00
|
|
|
self.tr('Graphical &Modeler...'), self.iface.mainWindow())
|
|
|
|
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)
|
|
|
|
|
2015-05-18 19:51:26 +03:00
|
|
|
self.historyAction = QAction(
|
|
|
|
QIcon(os.path.join(cmd_folder, 'images', 'history.gif')),
|
2015-05-20 19:33:47 +02:00
|
|
|
self.tr('&History...'), self.iface.mainWindow())
|
2015-02-03 11:22:34 +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)
|
|
|
|
|
2015-05-18 19:51:26 +03:00
|
|
|
self.configAction = QAction(
|
|
|
|
QIcon(os.path.join(cmd_folder, 'images', 'config.png')),
|
2015-02-03 11:22:34 +02:00
|
|
|
self.tr('&Options...'), self.iface.mainWindow())
|
|
|
|
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)
|
|
|
|
|
2015-05-18 19:51:26 +03:00
|
|
|
self.resultsAction = QAction(
|
|
|
|
QIcon(os.path.join(cmd_folder, 'images', 'results.png')),
|
2015-02-03 11:22:34 +02:00
|
|
|
self.tr('&Results Viewer...'), self.iface.mainWindow())
|
|
|
|
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)
|
|
|
|
|
2014-05-20 16:30:59 +02:00
|
|
|
menuBar = self.iface.mainWindow().menuBar()
|
2013-10-01 20:52:22 +03:00
|
|
|
menuBar.insertMenu(
|
2014-05-20 16:30:59 +02:00
|
|
|
self.iface.firstRightStandardMenu().menuAction(), self.menu)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
self.commanderAction = QAction(
|
2015-05-18 19:51:26 +03:00
|
|
|
QIcon(os.path.join(cmd_folder, 'images', 'commander.png')),
|
2015-02-03 11:22:34 +02:00
|
|
|
self.tr('&Commander'), self.iface.mainWindow())
|
|
|
|
self.commanderAction.setObjectName('commanderAction')
|
2013-04-13 15:05:19 +02:00
|
|
|
self.commanderAction.triggered.connect(self.openCommander)
|
|
|
|
self.menu.addAction(self.commanderAction)
|
2015-02-03 11:22:34 +02:00
|
|
|
self.iface.registerMainWindowAction(self.commanderAction,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('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
|
|
|
|
2014-05-20 16:30:59 +02:00
|
|
|
self.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:
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
self.commander = CommanderWindow(
|
|
|
|
self.iface.mainWindow(),
|
|
|
|
self.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()
|
|
|
|
dlg.exec_()
|
|
|
|
if dlg.update:
|
2014-03-26 10:18:27 +01:00
|
|
|
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_()
|
2015-02-03 11:22:34 +02:00
|
|
|
|
|
|
|
def tr(self, message):
|
2015-02-13 19:48:17 +01:00
|
|
|
return QCoreApplication.translate('ProcessingPlugin', message)
|