Skip to content

Commit 04e1749

Browse files
committed
Merge remote-tracking branch 'origin/patch-10' into patch-13
2 parents cbc17ea + 3b9d625 commit 04e1749

File tree

7 files changed

+84
-12
lines changed

7 files changed

+84
-12
lines changed

python/plugins/grassprovider/Grass7Algorithm.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,11 @@ def processAlgorithm(self, original_parameters, context, feedback):
509509
else:
510510
outputs[outName] = parameters[outName]
511511
if isinstance(out, QgsProcessingOutputHtml):
512-
self.convertToHtml(self.fileOutputs[outName])
513-
512+
if self.module and hasattr(self.module, 'convertToHtml'):
513+
func = getattr(self.module, 'convertToHtml')
514+
func(self, self.fileOutputs[outName], outputs)
515+
else:
516+
self.convertToHtml(self.fileOutputs[outName])
514517
return outputs
515518

516519
def processInputs(self, parameters, context, feedback):
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
g.extension
22
g.extension.list - List GRASS addons.
33
General (g.*)
4-
QgsProcessingParameterBoolean|-l|List available extensions in the official GRASS GIS Addons repository|False
5-
QgsProcessingParameterBoolean|-c|List available extensions in the official GRASS GIS Addons repository including module description|False
6-
QgsProcessingParameterBoolean|-a|List locally installed extensions|False
7-
QgsProcessingParameterFileDestination|html|List of addons|Html files (*.html)|addons_list.html|False
4+
QgsProcessingParameterEnum|list|List|Locally installed extensions;Extensions available in the official GRASS GIS Addons repository;Extensions available in the official GRASS GIS Addons repository including module description|False|0|False
5+
QgsProcessingParameterFileDestination|html|List of addons|Html files (*.html)|addons_list.html|True
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
g.version
2+
g.version - Display GRASS GIS version info. <p>Prints only version if run with no options checked.
3+
General (g.*)
4+
QgsProcessingParameterBoolean|-c|Print copyright message|False
5+
QgsProcessingParameterBoolean|-x|Print citation options|False
6+
QgsProcessingParameterBoolean|-b|Print build information|False
7+
QgsProcessingParameterBoolean|-r|Print GIS library revision number and date|True
8+
QgsProcessingParameterBoolean|-e|Print info for additional libraries|True
9+
QgsProcessingParameterBoolean|-g|Print in shell script style (with Git commit reference)|False
10+
QgsProcessingParameterBoolean|--verbose|Print verbose output|False
11+
QgsProcessingParameterFileDestination|html|Output file|Html files (*.html)|grass_version_info.html|True

python/plugins/grassprovider/ext/g_extension_list.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,31 @@
1919
__date__ = 'May 2023'
2020
__copyright__ = '(C) 2023, Alister Hood'
2121

22+
from qgis.core import QgsProcessingParameterBoolean
23+
2224

2325
def processInputs(alg, parameters, context, feedback):
24-
pass
26+
# get the option we want to run
27+
# we would need to update the if statements below if the order in the description file is changed
28+
selectedOption = alg.parameterAsInt(parameters, 'list', context)
29+
# Locally installed extensions
30+
if selectedOption == 0:
31+
optionString = '-a'
32+
# Extensions available in the official GRASS GIS Addons repository
33+
elif selectedOption == 1:
34+
optionString = '-l'
35+
# Extensions available in the official GRASS GIS Addons repository including module description
36+
else:
37+
optionString = '-c'
38+
param = QgsProcessingParameterBoolean(optionString, '', True)
39+
alg.addParameter(param)
40+
# Don't forget to remove the old input parameter
41+
alg.removeParameter('list')
42+
43+
44+
def convertToHtml(alg, fileName, outputs):
45+
# don't copy this for something that will have lots of data like r.stats
46+
# it will be very slow
47+
outputs['GRASS_ADDONS'] = open(fileName, 'r').read()
48+
# this will read the file a second time, but calling it saves us duplicating the code here
49+
alg.convertToHtml(fileName)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
***************************************************************************
3+
g_version.py
4+
------------------
5+
Date : May 2023
6+
Copyright : (C) 2023 by Alister Hood
7+
Email : alister.hood at gmail dot com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************
16+
"""
17+
18+
__author__ = 'Alister Hood'
19+
__date__ = 'May 2023'
20+
__copyright__ = '(C) 2023, Alister Hood'
21+
22+
23+
def processInputs(alg, parameters, context, feedback):
24+
pass
25+
26+
27+
def convertToHtml(alg, fileName, outputs):
28+
# don't copy this for something that will have lots of data like r.stats
29+
# it will be very slow
30+
outputs['GRASS_VERSIONINFO'] = open(fileName, 'r').read()
31+
# this will read the file a second time, but calling it saves us duplicating the code here
32+
alg.convertToHtml(fileName)

python/plugins/grassprovider/grass7.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,20 @@ There are 4 different levels where you can add logic:
172172
- Processing inputs import: if you need to do more than importing input layers.
173173
- Processing the command itself: if you need to chain more than one GRASS command for your algorithm.
174174
- Processing the outputs: if you need to do special things before exporting layers or if you need special export methods.
175+
- Customising html outputs: if you need to do special processing to an html output, or save the raw output to an output variable.
175176

176-
To add some logic on one (or more) level(s), you have to create a .py file named according to the algorithm name in python/plugins/grassprovider/ext, replacing '.' with '_'.
177-
Then you need to create methods using the respective names:
177+
To add some logic on one or more of these levels you have to create a .py file named according to the algorithm name in python/plugins/grassprovider/ext, replacing '.' with '_'.
178+
Then create methods using the respective names:
178179
- Input parameters: checkParameterValuesBeforeExecuting
179180
- Inputs import: processInputs
180181
- Command: processCommand
181182
- Outputs: processOutputs
183+
- Custom html outputs: convertToHtml
182184

183-
If there is a Python file with the algorithm name in the ext directory, methods will be imported from the file and run instead of the common methods (there are "standard" processCommand/processInputs/processOutputs/checkParameterValuesBeforeExecuting methods in the code of the GRASS provider for QGIS Processing, in python/plugins/grassprovider/Grass7Algorithm.py).
185+
If there is a Python file with the algorithm name in the ext directory, these methods will be imported from the file.
186+
In the case of processCommand, processInputs, processOutputs and convertToHtml these will override the "standard" versions of these methods in the code of the GRASS provider.
187+
You will need to read (and understand) the code for the standard methods in python/plugins/grassprovider/Grass7Algorithm.py.
184188

185189
If we take the example of v.what.rast, there is an ext file: ext/v_what_rast.py.
186190
In this file there is a processCommand method. It just launches the standard processCommand but with the delOutputs option set to True (we do not want to have standard outputs).
187191
Then there is also a customized processOutputs which exports the input vector as an output for QGIS. We need to do this because v.what.rast modifies values directly in the input vector layer instead of generating a new output, so we have to build this output ourself.
188-
189-
If you want to do special things in the ext mechanism, you will need to read (and understand) the GRASS provider code standard methods in Grass7Algorithm.py.

python/plugins/processing/gui/AlgorithmDialog.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def on_complete(ok, results):
283283
self.feedback.pushInfo(
284284
self.tr(elapsed_time(start_time, 'Execution completed in')))
285285
self.feedback.pushFormattedResults(self.algorithm(), self.context, results)
286+
286287
else:
287288
self.feedback.reportError(
288289
self.tr(elapsed_time(start_time, 'Execution failed after')))

0 commit comments

Comments
 (0)