Build the plugin

Important

Make sure, where is pyrcc5 the PyQt5 resource compiler available in your :env:`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, two scripts need to be executed 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

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

pb_tool compile

Next we deploy our plugin to the QGIS Plugin directory

pb_tool deploy

Deploying to /home/jachym/.local/share/QGIS/QGIS3/profiles/default/python/plugins/save_views
Deploying will:
        * Remove your currently deployed version
        * Compile the ui and resource files
        * Build the help docs
        * Copy everything to your
          /home/jachym/.local/share/QGIS/QGIS3/profiles/default/python/plugins/save_views
          directory

Proceed? [y/N]: y

Note

It seems, that pb_tool does require 7zip compression, which is not available in OSGeo4W project - therefore the QGIS Plugin can not be zipped. You will have to install it manually.

Using plugin in place

Instead of deploying the plugin using pb_tool it could be more flexible when developing the plugin to set up QGIS environment in order to be able to install the plugin from original destination without need of deployment.

You can copy your plugin to your plugins directory.

But it may be better to add your plugins 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 root directory where the directory with the plugin is located. Restart (close and open) QGIS and continue with installing the plugin.

_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 ‣ fibarplanitconvert ‣ CSV2FiberplanIT.

When running it, 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 yungovenv

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

$EDITOR yungovenv/bin/activate

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

To initialize the virtualenv, run

source yungovenv/bin/activate

Note

It’s generaly good advice to use virtualenvwrapper tool.