[Qgis-developer] Replacing Raster and Vector menus with Processing algorithms (update)

2015-09-23 Thread Victor Olaya
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
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Replacing Raster and Vector menus with Processing algorithms (update)

2015-09-23 Thread kimaidou
Hi Victor,

Thanks a lot for this work !

I think this kind of script must ben called by Processing which can check
if all the needed providers are well configured ( grass, otb, etc.). Menu
item could then be removed (or just set inactive) if Processing finds any
issue with each one.

Regards
Michaƫl

2015-09-23 12:21 GMT+02:00 Victor Olaya :

> 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
> ___
> Qgis-developer mailing list
> Qgis-developer@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer