Skip to content

Commit 6def4b6

Browse files
committed
Merge pull request #1446 from volaya/new_modeler
[processing] overhaul of graphical modeler
2 parents a2a26c2 + 05cfd69 commit 6def4b6

37 files changed

+1046
-2268
lines changed

python/plugins/processing/algs/grass/GrassUtils.py

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import stat
2929
import shutil
3030
import codecs
31-
import traceback
3231
import subprocess
3332
from qgis.core import QgsApplication
3433
from PyQt4.QtCore import *
@@ -385,7 +384,6 @@ def checkGrassIsInstalled(ignorePreviousState=False):
385384
configured in your system.\nPlease install it before \
386385
running GRASS algorithms.'
387386
except:
388-
s = traceback.format_exc()
389387
return 'Error while checking GRASS installation. GRASS might not \
390388
be correctly configured.\n' + s
391389

python/plugins/processing/algs/grass7/Grass7Utils.py

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import stat
2929
import shutil
30-
import traceback
3130
import subprocess
3231
from qgis.core import QgsApplication
3332
from PyQt4.QtCore import *
@@ -387,7 +386,6 @@ def checkGrass7IsInstalled(ignorePreviousState=False):
387386
configured in your system.\nPlease install it before \
388387
running GRASS GIS 7 algorithms.'
389388
except:
390-
s = traceback.format_exc()
391389
return 'Error while checking GRASS GIS 7 installation. GRASS GIS 7 might not \
392390
be correctly configured.\n' + s
393391

python/plugins/processing/core/Processing.py

+10-41
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from processing.modeler.ModelerUtils import ModelerUtils
1920

2021
__author__ = 'Victor Olaya'
2122
__date__ = 'August 2012'
@@ -41,7 +42,6 @@
4142
from processing.gui.Postprocessing import handleAlgorithmResults
4243
from processing.gui.UnthreadedAlgorithmExecutor import \
4344
UnthreadedAlgorithmExecutor
44-
from processing.modeler.Providers import Providers
4545
from processing.modeler.ModelerAlgorithmProvider import \
4646
ModelerAlgorithmProvider
4747
from processing.modeler.ModelerOnlyAlgorithmProvider import \
@@ -119,8 +119,7 @@ def removeProvider(provider):
119119

120120
@staticmethod
121121
def getProviderFromName(name):
122-
"""Returns the provider with the given name.
123-
"""
122+
"""Returns the provider with the given name."""
124123
for provider in Processing.providers:
125124
if provider.getName() == name:
126125
return provider
@@ -139,8 +138,9 @@ def initialize():
139138
Processing.addProvider(SagaAlgorithmProvider())
140139
Processing.addProvider(GrassAlgorithmProvider())
141140
Processing.addProvider(Grass7AlgorithmProvider())
142-
Processing.addProvider(ScriptAlgorithmProvider())
141+
Processing.addProvider(ScriptAlgorithmProvider())
143142
Processing.addProvider(TauDEMAlgorithmProvider())
143+
Processing.addProvider(ModelerAlgorithmProvider())
144144
Processing.modeler.initializeSettings()
145145

146146
# And initialize
@@ -173,7 +173,8 @@ def updateProviders():
173173

174174
@staticmethod
175175
def addAlgListListener(listener):
176-
"""Listener should implement a algsListHasChanged() method.
176+
"""
177+
Listener should implement a algsListHasChanged() method.
177178
178179
Whenever the list of algorithms changes, that method will be
179180
called for all registered listeners.
@@ -196,33 +197,11 @@ def loadAlgorithms():
196197
algs[alg.commandLineName()] = alg
197198
Processing.algs[provider.getName()] = algs
198199

199-
# This is a special provider, since it depends on others.
200-
# TODO: Fix circular imports, so this provider can be
201-
# incorporated as a normal one.
202-
provider = Processing.modeler
203-
provider.setAlgsList(Processing.algs)
204-
provider.loadAlgorithms()
205-
providerAlgs = provider.algs
206-
algs = {}
207-
for alg in providerAlgs:
208-
algs[alg.commandLineName()] = alg
209-
Processing.algs[provider.getName()] = algs
210-
211-
# And we do it again, in case there are models containing
212-
# models.
213-
# TODO: Improve this
214-
provider.setAlgsList(Processing.algs)
215-
provider.loadAlgorithms()
216-
providerAlgs = provider.algs
217-
algs = {}
218-
for alg in providerAlgs:
219-
algs[alg.commandLineName()] = alg
220-
Processing.algs[provider.getName()] = algs
221200
provs = {}
222201
for provider in Processing.providers:
223202
provs[provider.getName()] = provider
224-
provs[Processing.modeler.getName()] = Processing.modeler
225-
Providers.providers = provs
203+
ModelerUtils.allAlgs = Processing.algs
204+
ModelerUtils.providers = provs
226205

227206
@staticmethod
228207
def loadActions():
@@ -232,11 +211,7 @@ def loadActions():
232211
for action in providerActions:
233212
actions.append(action)
234213
Processing.actions[provider.getName()] = actions
235-
236-
provider = Processing.modeler
237-
actions = list()
238-
for action in provider.actions:
239-
actions.append(action)
214+
240215
Processing.actions[provider.getName()] = actions
241216

242217
@staticmethod
@@ -247,11 +222,6 @@ def loadContextMenuActions():
247222
for action in providerActions:
248223
Processing.contextMenuActions.append(action)
249224

250-
provider = Processing.modeler
251-
providerActions = provider.contextMenuActions
252-
for action in providerActions:
253-
Processing.contextMenuActions.append(action)
254-
255225
@staticmethod
256226
def getAlgorithm(name):
257227
for provider in Processing.algs.values():
@@ -269,8 +239,7 @@ def getAlgorithmFromFullName(name):
269239

270240
@staticmethod
271241
def getObject(uri):
272-
"""Returns the QGIS object identified by the given URI.
273-
"""
242+
"""Returns the QGIS object identified by the given URI."""
274243
return dataobjects.getObjectFromUri(uri)
275244

276245
@staticmethod

python/plugins/processing/gui/HelpEditionDialog.py

+28-25
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
1920

2021

2122
__author__ = 'Victor Olaya'
@@ -44,21 +45,21 @@ class HelpEditionDialog(QDialog, Ui_DlgHelpEdition):
4445

4546
def __init__(self, alg):
4647
QDialog.__init__(self)
47-
4848
self.setupUi(self)
49-
5049
self.alg = alg
5150
self.descriptions = {}
52-
if self.alg.descriptionFile is not None:
53-
helpfile = alg.descriptionFile + '.help'
54-
if os.path.exists(helpfile):
55-
try:
56-
with open(helpfile) as f:
57-
self.descriptions = json.load(f)
58-
except Exception, e:
59-
print e
60-
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING, "Cannot open help file: " + helpfile)
61-
51+
if isinstance(self.alg, ModelerAlgorithm):
52+
self.descriptions = self.alg.helpContent
53+
else:
54+
if self.alg.descriptionFile is not None:
55+
helpfile = alg.descriptionFile + '.help'
56+
if os.path.exists(helpfile):
57+
try:
58+
with open(helpfile) as f:
59+
self.descriptions = json.load(f)
60+
except Exception, e:
61+
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING, "Cannot open help file: " + helpfile)
62+
6263
self.currentName = self.ALG_DESC
6364
if self.ALG_DESC in self.descriptions:
6465
self.text.setText(self.descriptions[self.ALG_DESC])
@@ -73,17 +74,20 @@ def reject(self):
7374

7475
def accept(self):
7576
self.descriptions[self.currentName] = unicode(self.text.toPlainText())
76-
if self.alg.descriptionFile is not None:
77-
try:
78-
with open(self.alg.descriptionFile + '.help', 'w') as f:
79-
json.dump(self.descriptions, f)
80-
except Exception, e:
81-
QMessageBox.warning(self, 'Error saving help file',
82-
'Help file could not be saved.\n'
83-
'Check that you have permission to modify the help\n'
84-
'file. You might not have permission if you are \n'
85-
'editing an example model or script, since they \n'
86-
'are stored on the installation folder')
77+
if isinstance(self.alg, ModelerAlgorithm):
78+
self.alg.helpContent = self.descriptions
79+
else:
80+
if self.alg.descriptionFile is not None:
81+
try:
82+
with open(self.alg.descriptionFile + '.help', 'w') as f:
83+
json.dump(self.descriptions, f)
84+
except Exception, e:
85+
QMessageBox.warning(self, 'Error saving help file',
86+
'Help file could not be saved.\n'
87+
'Check that you have permission to modify the help\n'
88+
'file. You might not have permission if you are \n'
89+
'editing an example model or script, since they \n'
90+
'are stored on the installation folder')
8791

8892
QDialog.accept(self)
8993

@@ -126,8 +130,7 @@ def changeItem(self):
126130
item = self.tree.currentItem()
127131
if isinstance(item, TreeDescriptionItem):
128132
if self.currentName:
129-
self.descriptions[self.currentName] = \
130-
unicode(self.text.toPlainText())
133+
self.descriptions[self.currentName] = unicode(self.text.toPlainText())
131134
name = item.name
132135
if name:
133136
self.text.setEnabled(True)

python/plugins/processing/gui/MultipleInputPanel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from PyQt4 import QtCore, QtGui
28+
from PyQt4 import QtGui
2929
from processing.gui.MultipleInputDialog import MultipleInputDialog
3030

3131

python/plugins/processing/gui/ProcessingToolbox.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
***************************************************************************
1818
"""
1919

20+
2021
__author__ = 'Victor Olaya'
2122
__date__ = 'August 2012'
2223
__copyright__ = '(C) 2012, Victor Olaya'
@@ -28,6 +29,7 @@
2829
from PyQt4.QtCore import *
2930
from PyQt4.QtGui import *
3031
from qgis.utils import iface
32+
from processing.modeler.ModelerUtils import ModelerUtils
3133
from processing.core.Processing import Processing
3234
from processing.core.ProcessingLog import ProcessingLog
3335
from processing.core.ProcessingConfig import ProcessingConfig
@@ -37,7 +39,6 @@
3739
from processing.gui.ParametersDialog import ParametersDialog
3840
from processing.gui.BatchProcessingDialog import BatchProcessingDialog
3941
from processing.gui.EditRenderingStylesDialog import EditRenderingStylesDialog
40-
from processing.modeler.Providers import Providers
4142

4243
from processing.ui.ui_ProcessingToolbox import Ui_ProcessingToolbox
4344

@@ -259,7 +260,7 @@ def fillTreeUsingCategories(self):
259260
if not ProcessingConfig.getSetting(name):
260261
continue
261262
if providerName in providersToExclude \
262-
or len(Providers.providers[providerName].actions) != 0:
263+
or len(ModelerUtils.providers[providerName].actions) != 0:
263264
continue
264265
algs = provider.values()
265266

python/plugins/processing/gui/ScriptEditorDialog.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from processing.modeler.ModelerUtils import ModelerUtils
1920

2021
__author__ = 'Alexander Bruy'
2122
__date__ = 'December 2012'
@@ -38,7 +39,6 @@
3839

3940
from processing.gui.ParametersDialog import ParametersDialog
4041
from processing.gui.HelpEditionDialog import HelpEditionDialog
41-
from processing.modeler.Providers import Providers
4242
from processing.algs.r.RAlgorithm import RAlgorithm
4343
from processing.algs.r.RUtils import RUtils
4444
from processing.script.ScriptAlgorithm import ScriptAlgorithm
@@ -180,10 +180,10 @@ def setHasChanged(self, hasChanged):
180180
def runAlgorithm(self):
181181
if self.algType == self.SCRIPT_PYTHON:
182182
alg = ScriptAlgorithm(None, unicode(self.editor.text()))
183-
alg.provider = Providers.providers['script']
183+
alg.provider = ModelerUtils.providers['script']
184184
if self.algType == self.SCRIPT_R:
185185
alg = RAlgorithm(None, unicode(self.editor.text()))
186-
alg.provider = Providers.providers['r']
186+
alg.provider = ModelerUtils.providers['r']
187187

188188
dlg = alg.getCustomParametersDialog()
189189
if not dlg:

python/plugins/processing/modeler/AddModelFromFileAction.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ def execute(self):
4747
'*.model')
4848
if filename:
4949
try:
50-
model = ModelerAlgorithm()
51-
model.openModel(filename)
50+
ModelerAlgorithm.fromJsonFile(filename)
5251
except WrongModelException:
5352
QtGui.QMessageBox.warning(self.toolbox, "Error reading model", "The selected file does not contain a valid model")
5453
return
54+
except:
55+
QtGui.QMessageBox.warning(self.toolbox, "Error reading model", "Cannot read file")
5556
destFilename = os.path.join(ModelerUtils.modelsFolder(), os.path.basename(filename))
5657
shutil.copyfile(filename,destFilename)
5758
self.toolbox.updateProvider('script')

0 commit comments

Comments
 (0)