Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 293ac60
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 72 deletions.
31 changes: 14 additions & 17 deletions python/plugins/processing/ProcessingPlugin.py
Expand Up @@ -17,8 +17,6 @@
***************************************************************************
"""

from processing import interface

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -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

Expand All @@ -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'))
Expand All @@ -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):
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/processing/algs/grass/GrassAlgorithm.py
Expand Up @@ -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
Expand Down Expand Up @@ -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 + '"'
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Expand Up @@ -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
Expand Down Expand Up @@ -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 + '"'
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/FieldsCalculator.py
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 6 additions & 4 deletions python/plugins/processing/core/GeoAlgorithm.py
Expand Up @@ -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,
Expand Down
13 changes: 3 additions & 10 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/AlgorithmExecutionDialog.py
Expand Up @@ -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):

Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions python/plugins/processing/gui/CommanderWindow.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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_()
Expand Down
11 changes: 5 additions & 6 deletions python/plugins/processing/gui/ExtentSelectionPanel.py
Expand Up @@ -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):

Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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()

Expand All @@ -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_()
Expand Down
14 changes: 7 additions & 7 deletions python/plugins/processing/gui/MessageBarProgress.py
Expand Up @@ -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)

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

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

1 comment on commit 293ac60

@gacarrillor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.