Skip to content
Sergio Botero edited this page Mar 4, 2014 · 6 revisions

Steps to add a new algorithm to the plugin.

For the impatient:

  1. Add the new methods to support the algorithm to clusterpy.py and test for the methods.
  2. Add a worker, on workers.py, that will run the algorithm in a background thread.
  3. Create a new dialog box, both the GUI and the code that will pass the user selected parameters to the worker (as seen on clusterpy_lightdialog.py).
  4. Load and unload the new dialog with the rest of algorithms and sections in the plugin, in clusterpy_light.py.

For the more patient:

This QGIS plugin has 3 parts mainly.

  1. First part: the algorithm core components, working with areas, crunching numbers or anything related to regional science. All this should go into the clusterpy.py file, but have considerations regarding the file size and readability. It is a good a idea to split the file into separate files.
  2. Second part: the worker, runs the algorithm in a background thread so that we do not block the UI with all the heavy computation. The worker receives all the parameters ready to be used with the algorithm and handles back the result (see workers.py).
  3. Third part: the algorithm dialog box, this has two sides, the graphical interface and the code that glues all together. The glue code will take the input parameters from the dialog box and cast or convert them for the worker. The graphics of the box can be created/modified using the qtcreator IDE. With this IDE you can add graphical elements, set constraints, change names and identifiers (to get up and running with a new dialog box, duplicate one of the .ui files and open it with the Qt Creator).

After adding the new components for the algorithm, after creating the worker and the GUI, the plugin needs to know what to load. The clusterpy_light.py file loads and unloads the algorithms.

One important thing to do when adding new files to the plugin is to make sure to add those files to the Makefile. In case that the files added are static files (icons, html, etc) those need to be added too to the resources.qrc file.


Development note

If you would like to use a virtual environment for the development, use the Vagrantfile with Vagrant. The machine has the qtcreator IDE installed and all the dependencies required to generate all the .py files from the .ui files.

Build

The Makefile was generated by the QGIS Plugin Builder(Third party plugin) and has most of the functionality needed to build the plugin. Running make will generally create the plugin and should be ready to transfer to ~/.qgis2/python/plugins.

Release

To create a zip file for release and distribution, the Makefile has a zip target that will create it. This is all that is needed. Note: Unzip the contents of this new file into the QGIS plugin directory to see if it loads correctly. If it doesn't you might be missing some files in the Makefile.

Also remember:

  • Update the names and information on the cite the plugin sections.
  • Update the plugin version (more here).
  • Create a git tag with the version
  • Create a release in Github from the previous tag and add the zipfile created by the Makefile.
Clone this wiki locally