QGIS/python/plugins/processing/ProcessingPlugin.py

164 lines
6.3 KiB
Python
Raw Normal View History

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. *
* *
***************************************************************************
"""
2012-10-05 23:28:47 +02:00
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
2012-10-05 23:28:47 +02:00
# This will get replaced with a git SHA1 when you do a git archive
2012-10-05 23:28:47 +02:00
__revision__ = '$Format:%H$'
import shutil
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
from processing.gui.CommanderWindow import CommanderWindow
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
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-08-12 20:44:27 +02:00
class ProcessingPlugin:
2012-09-15 18:25:25 +03:00
def __init__(self, iface):
self.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
self.toolbox = ProcessingToolbox()
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
self.toolbox.hide()
#Processing.addAlgListListener(self.toolbox)
2013-05-01 23:45:20 +02:00
self.menu = QMenu(self.iface.mainWindow().menuBar())
self.menu.setObjectName( 'processing' )
self.menu.setTitle(QCoreApplication.translate('Processing',
'Processing'))
2012-09-15 18:25:25 +03:00
self.toolboxAction = self.toolbox.toggleViewAction()
self.toolboxAction.setObjectName( 'toolboxAction' )
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)
self.modelerAction = QAction(QIcon(':/processing/images/model.png'),
QCoreApplication.translate('Processing',
'Graphical modeler'),
self.iface.mainWindow())
self.modelerAction.setObjectName( 'modelerAction' )
self.modelerAction.triggered.connect(self.openModeler)
2012-09-15 18:25:25 +03:00
self.menu.addAction(self.modelerAction)
self.historyAction = QAction(QIcon(':/processing/images/history.gif'),
QCoreApplication.translate('Processing',
'History and log'),
self.iface.mainWindow())
self.historyAction.setObjectName( 'historyAction' )
self.historyAction.triggered.connect(self.openHistory)
2012-09-15 18:25:25 +03:00
self.menu.addAction(self.historyAction)
self.configAction = QAction(QIcon(':/processing/images/config.png'),
QCoreApplication.translate('Processing',
'Options and configuration'),
self.iface.mainWindow())
self.configAction.setObjectName( 'configAction' )
self.configAction.triggered.connect(self.openConfig)
2012-09-15 18:25:25 +03:00
self.menu.addAction(self.configAction)
self.resultsAction = QAction(QIcon(':/processing/images/results.png'),
QCoreApplication.translate('Processing',
'&Results viewer'),
self.iface.mainWindow())
self.resultsAction.setObjectName( 'resultsAction' )
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(
self.iface.firstRightStandardMenu().menuAction(), self.menu)
2012-09-15 18:25:25 +03:00
self.commanderAction = QAction(
QIcon(':/processing/images/commander.png'),
QCoreApplication.translate('Processing', '&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)
self.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()
# delete temporary output files
folder = tempFolder()
if QDir(folder).exists():
shutil.rmtree(folder, True)
2013-05-01 23:45:20 +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:
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):
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.show()
2012-09-15 18:25:25 +03:00
dlg.exec_()
if dlg.update:
Processing.updateAlgsList()
self.toolbox.updateProvider('model')
2012-09-15 18:25:25 +03:00
def openResults(self):
dlg = ResultsDialog()
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_()