[Qgis-developer] how to turn my plugin into a processing subplugin

Médéric Ribreux mederic.ribreux at medspx.fr
Thu Dec 1 12:47:25 PST 2016


Le 2016-11-28 16:20, Julie Pierson a écrit :
> Hi all,
> 
> I would like to answer this issue for my plugin :
> https://github.com/UMR-PASSAGES/DissolveWithStats/issues/2, and turn
> it into a processing subplugin. I read this :
> https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/processing.html,
> but I'm still not sure how to go on.
> 
> I'm guessing that my script will be accessible from the Scripts/Tools
> part of the processing toolbox. But I don't understand :
> - where these scripts are hosted, and how do I submit it
> - where do I start ? Should I just make  a new version of my plugin
> without the GUI ?
> 
> Sorry if the answers are obvious !
> 
> Thanks,
> 
> Julie.
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Hello,

I think that you can first try to convert your plugin to a Processing 
Python script as stated here:
https://docs.qgis.org/testing/en/docs/user_manual/processing/scripts.html

When you create a Processing Python script from the dedicated dialog, it 
is stored into your ~/.qgis3/processing/script/ directory.
To fill the script code, you will have to extract the "algorithm" part 
of your plugin (the things that do the stats or the dissolve part which 
seems to be stored into 'dissolve_stats_dialog.py') and put it into a 
Python script.

For input/output, just use the dedicated "comments" syntax at the 
beginning of the script:
     ##myvector=vector
defines an input vector which will be available in myvector Python 
variable.

Once inputs and outputs are defined, there is no need to deal with 
dialogs to open/choose files, just use the "comments" variables and 
Processing will build the dialogs for you.
The script will be processed by Processing as is: the code will be 
interpreted as a Python script. You can add as many classes/functions 
you'd like into the script. Don't use the `if __name__ == '__main__'` 
Python syntax for the main loop. I think it is not interpreted correctly 
by Processing (not 100% sure though).

Once your plugin is converted, you can make a PR to 
https://github.com/qgis/QGIS-Processing which is the repository for 'Get 
models from on-line scripts collection' Processing dialog box and it 
will become available to anybody.


Cheers,

-- 
Médéric RIBREUX
https://medspx.fr


More information about the Qgis-developer mailing list