Skip to content
Permalink
Browse files
[processing] removed interface module
now all access to the interface is done through qgis.utils.iface
  • Loading branch information
volaya committed May 21, 2014
1 parent fcc24e9 commit 293ac607221ad176b5304cf9ca368c5a21fb2180
@@ -17,8 +17,6 @@
***************************************************************************
"""

from processing import interface

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
@@ -39,7 +37,6 @@
from processing.gui.ResultsDialog import ResultsDialog
from processing.modeler.ModelerDialog import ModelerDialog
from processing.gui.CommanderWindow import CommanderWindow
from processing.tools import dataobjects
from processing.tools.system import *
import processing.resources_rc

@@ -51,17 +48,17 @@
class ProcessingPlugin:

def __init__(self, iface):
interface.iface = iface
self.iface = iface
Processing.initialize()

def initGui(self):
self.commander = None
self.toolbox = ProcessingToolbox()
interface.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
self.toolbox.hide()
#Processing.addAlgListListener(self.toolbox)

self.menu = QMenu(interface.iface.mainWindow().menuBar())
self.menu = QMenu(self.iface.mainWindow().menuBar())
self.menu.setObjectName( 'processing' )
self.menu.setTitle(QCoreApplication.translate('Processing',
'Processing'))
@@ -76,47 +73,47 @@ def initGui(self):
self.modelerAction = QAction(QIcon(':/processing/images/model.png'),
QCoreApplication.translate('Processing',
'Graphical modeler'),
interface.iface.mainWindow())
self.iface.mainWindow())
self.modelerAction.setObjectName( 'modelerAction' )
self.modelerAction.triggered.connect(self.openModeler)
self.menu.addAction(self.modelerAction)

self.historyAction = QAction(QIcon(':/processing/images/history.gif'),
QCoreApplication.translate('Processing',
'History and log'),
interface.iface.mainWindow())
self.iface.mainWindow())
self.historyAction.setObjectName( 'historyAction' )
self.historyAction.triggered.connect(self.openHistory)
self.menu.addAction(self.historyAction)

self.configAction = QAction(QIcon(':/processing/images/config.png'),
QCoreApplication.translate('Processing',
'Options and configuration'),
interface.iface.mainWindow())
self.iface.mainWindow())
self.configAction.setObjectName( 'configAction' )
self.configAction.triggered.connect(self.openConfig)
self.menu.addAction(self.configAction)

self.resultsAction = QAction(QIcon(':/processing/images/results.png'),
QCoreApplication.translate('Processing',
'&Results viewer'),
interface.iface.mainWindow())
self.iface.mainWindow())
self.resultsAction.setObjectName( 'resultsAction' )
self.resultsAction.triggered.connect(self.openResults)
self.menu.addAction(self.resultsAction)

menuBar = interface.iface.mainWindow().menuBar()
menuBar = self.iface.mainWindow().menuBar()
menuBar.insertMenu(
interface.iface.firstRightStandardMenu().menuAction(), self.menu)
self.iface.firstRightStandardMenu().menuAction(), self.menu)

self.commanderAction = QAction(
QIcon(':/processing/images/commander.png'),
QCoreApplication.translate('Processing', '&Commander'),
interface.iface.mainWindow())
self.iface.mainWindow())
self.commanderAction.setObjectName( 'commanderAction' )
self.commanderAction.triggered.connect(self.openCommander)
self.menu.addAction(self.commanderAction)
interface.iface.registerMainWindowAction(self.commanderAction,
self.iface.registerMainWindowAction(self.commanderAction,
'Ctrl+Alt+M')

def unload(self):
@@ -128,12 +125,12 @@ def unload(self):
if QDir(folder).exists():
shutil.rmtree(folder, True)

interface.iface.unregisterMainWindowAction(self.commanderAction)
self.iface.unregisterMainWindowAction(self.commanderAction)

def openCommander(self):
if self.commander is None:
self.commander = CommanderWindow(interface.iface.mainWindow(),
interface.iface.mapCanvas())
self.commander = CommanderWindow(self.iface.mainWindow(),
self.iface.mapCanvas())
Processing.addAlgListListener(self.commander)
self.commander.prepareGui()
self.commander.show()
@@ -32,6 +32,7 @@
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.utils import iface

from processing import interface
from processing.core.GeoAlgorithm import GeoAlgorithm
@@ -469,7 +470,7 @@ def exportVectorLayer(self, orgFilename):

def setSessionProjectionFromProject(self, commands):
if not GrassUtils.projectionSet:
proj4 = interface.iface.mapCanvas().mapRenderer().destinationCrs().toProj4()
proj4 = iface.mapCanvas().mapRenderer().destinationCrs().toProj4()
command = 'g.proj'
command += ' -c'
command += ' proj4="' + proj4 + '"'
@@ -32,8 +32,8 @@
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.utils import iface

from processing import interface
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
@@ -471,7 +471,7 @@ def exportVectorLayer(self, orgFilename):

def setSessionProjectionFromProject(self, commands):
if not Grass7Utils.projectionSet:
proj4 = interface.iface.mapCanvas().mapRenderer().destinationCrs().toProj4()
proj4 = iface.mapCanvas().mapRenderer().destinationCrs().toProj4()
command = 'g.proj'
command += ' -c'
command += ' proj4="' + proj4 + '"'
@@ -27,7 +27,7 @@

from PyQt4.QtCore import *
from qgis.core import *
from processing import interface
from qgis.utils import iface
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import \
GeoAlgorithmExecutionException
@@ -101,7 +101,7 @@ def processAlgorithm(self, progress):

da = QgsDistanceArea()
da.setSourceCrs(layer.crs().srsid())
canvas = interface.iface.mapCanvas()
canvas = iface.mapCanvas()
da.setEllipsoidalMode(canvas.mapRenderer().hasCrsTransformEnabled())
da.setEllipsoid(QgsProject.instance().readEntry('Measure',
'/Ellipsoid',
@@ -27,7 +27,7 @@

from PyQt4.QtCore import *
from qgis.core import *
from processing import interface
from qgis.utils import iface
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterSelection import ParameterSelection
@@ -103,7 +103,7 @@ def processAlgorithm(self, progress):
'NONE')[0]
crs = layer.crs().srsid()
elif method == 1:
mapCRS = interface.iface.mapCanvas().mapRenderer().destinationCrs()
mapCRS = iface.mapCanvas().mapRenderer().destinationCrs()
layCRS = layer.crs()
coordTransform = QgsCoordinateTransform(layCRS, mapCRS)

@@ -358,10 +358,12 @@ def setOutputCRS(self):
if p is not None:
self.crs = p.crs()
return
qgis = dataobjects.interface.iface
if qgis is None:
return
self.crs = qgis.mapCanvas().mapRenderer().destinationCrs()
try:
from qgis.utils import iface
self.crs = iface.mapCanvas().mapRenderer().destinationCrs()
except:
pass


def checkInputCRS(self):
"""It checks that all input layers use the same CRS. If so,
@@ -30,7 +30,7 @@
from PyQt4.QtGui import *
from qgis.core import *
import processing
from processing import interface
from qgis.utils import iface
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
@@ -128,13 +128,6 @@ def getProviderFromName(name):
return provider
return Processing.modeler

@staticmethod
def getInterface():
return interface.iface

@staticmethod
def setInterface(iface):
pass

@staticmethod
def initialize():
@@ -351,8 +344,8 @@ def runAlgorithm(algOrName, onFinish, *args):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

progress = SilentProgress()
if interface.iface is not None :
progress = MessageBarProgress()
if iface is not None :
progress = MessageBarProgress()
ret = UnthreadedAlgorithmExecutor.runalg(alg, progress)
if onFinish is not None and ret:
onFinish(alg, progress)
@@ -58,7 +58,7 @@
from processing.outputs.OutputVector import OutputVector
from processing.outputs.OutputTable import OutputTable
from processing.tools import dataobjects

from qgis.utils import iface

class AlgorithmExecutionDialog(QtGui.QDialog):

@@ -68,7 +68,7 @@ def __init__(self, param, widget):
(self.parameter, self.widget) = (param, widget)

def __init__(self, alg, mainWidget):
QtGui.QDialog.__init__(self, None, QtCore.Qt.WindowSystemMenuHint
QtGui.QDialog.__init__(self, iface.mainWindow(), QtCore.Qt.WindowSystemMenuHint
| QtCore.Qt.WindowTitleHint)
self.executed = False
self.mainWidget = mainWidget
@@ -29,7 +29,7 @@
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from processing import interface
from qgis.utils import iface
from processing.core.Processing import Processing
from processing.gui.MissingDependencyDialog import MissingDependencyDialog
from processing.gui.ParametersDialog import ParametersDialog
@@ -112,7 +112,7 @@ def fillCombo(self):

#Add menu entries
menuActions = []
actions = Processing.getInterface().mainWindow().menuBar().actions()
actions = iface.mainWindow().menuBar().actions()
for action in actions:
menuActions.extend(self.getActions(action))
for action in menuActions:
@@ -170,8 +170,7 @@ def run(self):
elif s.startswith('Menu action: '):
actionName = s[len('Menu action: '):]
menuActions = []
actions = \
Processing.getInterface().mainWindow().menuBar().actions()
actions = iface.mainWindow().menuBar().actions()
for action in actions:
menuActions.extend(self.getActions(action))
for action in menuActions:
@@ -212,7 +211,7 @@ def runAlgorithm(self, alg):
dlg = alg.getCustomParametersDialog()
if not dlg:
dlg = ParametersDialog(alg)
canvas = interface.iface.mapCanvas()
canvas = iface.mapCanvas()
prevMapTool = canvas.mapTool()
dlg.show()
dlg.exec_()
@@ -29,13 +29,12 @@
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from processing import interface
from processing.gui.RectangleMapTool import RectangleMapTool
from processing.parameters.ParameterRaster import ParameterRaster
from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterMultipleInput import ParameterMultipleInput
from processing.tools import dataobjects

from qgis.utils import iface

class ExtentSelectionPanel(QtGui.QWidget):

@@ -59,7 +58,7 @@ def __init__(self, dialog, alg, default):
self.pushButton.clicked.connect(self.buttonPushed)
self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout)
canvas = interface.iface.mapCanvas()
canvas = iface.mapCanvas()
self.prevMapTool = canvas.mapTool()
self.tool = RectangleMapTool(canvas)
self.connect(self.tool, SIGNAL('rectangleCreated()'), self.fillCoords)
@@ -143,7 +142,7 @@ def addToRegion(self, layer, first):
def useLayerExtent(self):
CANVAS_KEY = 'Use canvas extent'
extentsDict = {}
extentsDict[CANVAS_KEY] = interface.iface.mapCanvas().extent()
extentsDict[CANVAS_KEY] = iface.mapCanvas().extent()
extents = [CANVAS_KEY]
layers = dataobjects.getAllLayers()
for layer in layers:
@@ -155,7 +154,7 @@ def useLayerExtent(self):
self.setValueFromRect(extentsDict[item])

def selectOnCanvas(self):
canvas = interface.iface.mapCanvas()
canvas = iface.mapCanvas()
canvas.setMapTool(self.tool)
self.dialog.showMinimized()

@@ -168,7 +167,7 @@ def setValueFromRect(self, r):
+ str(r.yMinimum()) + ',' + str(r.yMaximum())
self.text.setText(s)
self.tool.reset()
canvas = interface.iface.mapCanvas()
canvas = iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
self.dialog.showNormal()
self.dialog.raise_()
@@ -27,25 +27,25 @@

from PyQt4.QtCore import *
from PyQt4 import QtGui
from processing import interface
from qgis.utils import iface
from qgis.gui import *


class MessageBarProgress:

def __init__(self):
self.progressMessageBar = \
interface.iface.messageBar().createMessage('Executing algorithm')
iface.messageBar().createMessage('Executing algorithm')
self.progress = QtGui.QProgressBar()
self.progress.setMaximum(100)
self.progress.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
self.progressMessageBar.layout().addWidget(self.progress)
interface.iface.messageBar().pushWidget(self.progressMessageBar,
interface.iface.messageBar().INFO)
iface.messageBar().pushWidget(self.progressMessageBar,
iface.messageBar().INFO)

def error(self, msg):
interface.iface.messageBar().clearWidgets()
interface.iface.messageBar().pushMessage("Error", msg,
iface.messageBar().clearWidgets()
iface.messageBar().pushMessage("Error", msg,
level = QgsMessageBar.CRITICAL,
duration = 3)

@@ -68,4 +68,4 @@ def setConsoleInfo(self, _):
pass

def close(self):
interface.iface.messageBar().clearWidgets()
iface.messageBar().clearWidgets()

1 comment on commit 293ac60

@gacarrillor

This comment has been minimized.

Copy link
Member

@gacarrillor gacarrillor commented on 293ac60 Jan 30, 2015

Hi @volaya , as far as I understand, this commit breaks any attempt to run Processing algorithms (that make use of iface) from standalone scripts like this one using the qgis:fieldcalculator Do you have any opinion about that? Was it intentional? I'm able to run qgis:fieldcalculator algorithm from standalone scripts with Processing v.2.2.0-2, but now that I start using v.2.6 I cannot do it anymore.

Please sign in to comment.