[Qgis-developer] Replacing Raster and Vector menus with Processing algorithms (update)
Victor Olaya
volayaf at gmail.com
Wed Sep 23 03:21:29 PDT 2015
Hi all
As a first step to replace Raster and Vector menus with new menu
entries that call Processing algorithms to avoid redundancy (as we
have been discussing since sometime ago...), I have added a new method
to Processing named addAlgorithmEntry. It adds a menu entry in the
specified menu, which calls a Processign algorithm. Basically, it's an
easy way of placing an entry point to a Processing algorithm outside
of the Processing toolbox
Usage is rather straight forward
addAlgorithmEntry([name_of_algorithm], [menu_name], [submenu_name],
[menuentry_text], [icon])
The last two parameters can be ommited, and the original title and
icon of the algorithm will be used.
Here is an example, on how the Raster/Conversion menu could be
replaced with this:
import os
from GdalTools import GdalTools
from processing.gui.utils import addAlgorithmEntry
from PyQt4.QtGui import *
def addRasterAlgorithm(name, group, iconName):
icon = QIcon(os.path.join(os.path.dirname(GdalTools.__file__),
"icons", iconName + ".png"))
addAlgorithmEntry(name, "Raster", group, icon = icon)
addRasterAlgorithm("gdalogr:rasterize", "Conversion", "rasterize")
addRasterAlgorithm("gdalogr:translate", "Conversion", "translate")
addRasterAlgorithm("gdalogr:pcttorgb", "Conversion", "24-to-8-bits")
addRasterAlgorithm("gdalogr:rgbtopct", "Conversion", "8-to-24-bits")
addRasterAlgorithm("gdalogr:polygonize", "Conversion", "polygonize")
Now it's a matter of making sure that all algorithms are replaceable
with a Processing equivalent, and add more lines to the above a script
for creating the full alternative menu structure.
Then, that script can be called by Processing itself, or put it in a
separate plugin that adds GDAL/OGR functionality based on Processing
algorithms. (Paths to icons should be modified from the above example,
of course)
Let me know if you have questions or you want to help on this,
Regards
More information about the Qgis-developer
mailing list