Build the plugin

Important

Make sure, where is the PyQt5 resource compiler (pyrcc5) available in your PATH

You can test it by running

pyrcc5 -help

You should obtain readable help message

_images/pyrcc5-help.png

Note

If you are on MS Windows, open OSGeo4W Shell (ideally as administrator) and run two scripts before any attempts: py3_env and qt5_env

c:\> py3_env

c:\> qt5_env

c:\> pyrcc5 -help
_images/pyrcc5-windows.png

To build the plugin pb_tool must be available in the system. This package is available via PyPI service (using pip install).

Note

It might look as good idea to use standard make, since Makefile is available too. This is considered deprecated option and should no longer be used. pb_tool is more complex build system (and supports various operating systems).

To install pb_tool, just use

python3 -m pip install pb_tool

Configuration file pb_tool.cfg

pb_tool needs a configuration file (generated by the Plugin Builder). In this file, you can modify target plugin path as well as locales, extra directories needed and other metadata.

First build of the plugin

First we compile UI files

cd /path/to/save_views
pb_tool compile

Note

If you have no administrator permission on MS Windows than you can run pb_tool by this command:

%homepath%\AppData\Roaming\Python\Python37\Scripts\pb_tool compile

Using plugin in place

Instead of deploying the plugin using pb_tool it is more flexible when the plugin to set up by QGIS environment in order to be able to install the plugin from current folder without need of deployment.

Let’s add your plugin location to the QGIS_PLUGINPATH in Settings ‣ Options ‣ System. Enable Use custom variables in Environment section and add a new variable: QGIS_PLUGINPATH. This variable should point to a parent directory where the plugin is located. Restart (close and open) QGIS and continue with installing the plugin.

Important

QGIS doesn’t allow in the path defined by QGIS_PLUGINPATH non-ascii characters. If your path contains such characters than consider to rename directories in the path which causing this issue.

_images/qgis-pluginpath.svg

Fig. 13 Setting of the QGIS_PLUGINPATH variable.

Activate plugin in QGIS

Open QGIS and find the new plugin in the Plugins ‣ Manage and Install Plugins…. Check the checkbox to activate the plugin in QGIS.

_images/save-views-enable.png

Fig. 14 Activate plugin Save Views.

An icon of the plugin new_plugin appears in the toolbar as well as new menu selection in Vector ‣ Save Views ‣ Save Views.

When running it, a new (empty) dialog will be open.

_images/plugin-ui-template.png

Notes

Virtualenv

Virtualenv is one of the possibilities, how to keep your code and it’s dependencies independent.

To create the virtualenv, run

python3 -m venv myvenv

For QGIS running within Python virtualenv, you need to adjust :file:``activate` script and add PYTHONPATH with Python, Qt and QGIS libraries.

$EDITOR myvenv/bin/activate

[...]
export PYTHONPATH=$PYTHONPATH:/usr/local/share/qgis/python/:/usr/lib/python3/dist-packages/
[...]

To initialize the virtualenv, run

source myenv/bin/activate

Note

It’s generally good advice to use virtualenvwrapper tool.