GEOG 489
Advanced Python Programming for GIS

4.12.1 Create Template with Plugin Builder

PrintPrint

To create a folder with a template version for this plugin, please follow the steps below.

  1. Run the Plugin Builder plugin and fill out the first page as follows before clicking “Next >”:
     Screenshot of plugin builder firstt page
    Figure 4.40 First Plugin Builder dialog page with information about the new plugin
  2. Just click “Next >” again as we will skip the description part and then on the next page pick the “Tool button with dock widget” template at the top and fill out the rest of the information as shown below before pressing “Next >” again.
     Screenshot of plugin builder with template selection--see caption
    Figure 4.41 Picking the "Tool button with dock widget" template in Plugin Builder
  3. We will keep the default settings for the following setup pages, so just keep pressing “Next >” until you arrive at the last page where the button is called “Generate” instead. Take a look at the paths where Plugin Builder is going to create the folder for the new plugin. It might be a good idea to copy the path to somewhere from which you can retrieve it at any time. Now click on “Generate” and the folder for the plugin will be created.
  4. If you now navigate to the plugins folder from the previous step, it will contain a new folder called “bus_track_analyzer_for_qgis”. Enter that folder and check out the files that have been created. The content should look like this:
     Screenshot of created file
    Figure 4.42 Newly created plugin folder with files for our plugin
  5. Please close QGIS for a moment. We still need to compile the file resources.qrc into a Python .py file with the help of pyrcc5 as we did in Section 4.11. For this, run OSGeo4W.bat from your OSGeo4W/QGIS installation and, in the shell that opens up, navigate to the folder containing your plugin, e.g. type in the following command but adapt the path to match the path from steps 3 and 4:
    cd C:\Users\xyz\AppData\roaming\QGIS\QGIS3\profiles\default\python\plugins\bus_track_analyzer_for_qgis
  6. Finally, compile the file with the command below. There should now be a file called resources.py in your plugin folder.
    pyrcc5 resources.qrc –o resources.py
  7. You can now restart QGIS and open the plugin manager where “Bus Track Analyzer for QGIS” should now appear in the list of installed plugins. Enable it and then check the Plugins menu to make sure there is now an entry “Bus Track Analyzer for QGIS” there. Start the plugin and a rather empty dock widget will appear in the right part of the QGIS window. Try moving this dock widget around. You will see that you can move it to the other areas of the main QGIS window or completely undock it and have it as an independent window on the screen.