Create a custom Plugin in Qgis

imagine you have a great idea to give even more power to your QGIS and you can do it with a simple language, python. Here’s how to create a Qgis plugin!!

A plugin to make another plugin

Install plugins builder 3 which describes itself, aptly, as “Creates a QGIS plugin template for use as a starting point in plugin development”.

In addition to this page, I recommend some online resources:

QGis tutorial – Plugin development – part 1

u Rob

i 29K views

Jan 15 2021

 

Attention, during installation, ignore this message:

The resource compiler pyrcc5 was not found in your path. You’ll have to manually compile the resources.qrc file with pyrcc5 before installing your plugin.

 

Upon running the Plugin Builder 3, you’ll be prompted to provide details such as the plugin’s name and desired destination. Note that the generated plugin files might not be placed in your preferred directory; you’ll likely need to manually move them to your desired location. Additional information required includes the developer’s email, stability status (whether it’s considered a stable release or not), and the version name.

The following text it’s similar to the one you’ll see.

Plugin Builder Results

Congratulations! You just built a plugin for QGIS!

Your plugin AndreaPluginCourse was created in:
/Users/ndrini/workspace/ndrini/pyqgis/my_plugins/ndrini_plugin.py

Your QGIS plugin directory is located at:
/Users/ndrini/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins

What’s Next

  1. If resources.py is not present in your plugin directory, compile the resources file using pyrcc5 (simply use pb_tool or make if you have automake)
  2. Optionally, test the generated sources using make test (or run tests from your IDE)
  3. Copy the entire directory containing your new plugin to the QGIS plugin directory (see Notes below)
  4. Test the plugin by enabling it in the QGIS plugin manager
  5. Customize it by editing the implementation file andrea_plugin_course.py.py
  6. Create your own custom icon, replacing the default icon.png
  7. Modify your user interface by opening andrea_plugin_course.py_dialog_base.ui in Qt Designer

Notes:

  • You can use pb_tool to compile, deploy, and manage your plugin. Tweak the pb_tool.cfg file included with your plugin as you add files. Install pb_tool using pip or easy_install. See http://loc8.cc/pb_tool for more information.
  • You can also use the Makefile to compile and deploy when you make changes. This requires GNU make (gmake). The Makefile is ready to use, however you will have to edit it to add addional Python source files, dialogs, and translations.

For information on writing PyQGIS code, see http://loc8.cc/pyqgis_resources for a list of resources.

©2011-2019 GeoApt LLC – geoapt.com

 

toolbar new icons

 

def test(self):
“”” This method allows to dialog with the user.”””

“”” User communication: QgsMessageBar “””
print(“Message printed into the QGIS’s Python console”)
# # Show messages in QGIS message bar
message_bar = iface.messageBar()
print(type(message_bar))

message_bar.pushMessage(“Title”, “Info message”, Qgis.Info, 100)
message_bar.pushMessage(“”, “Warning message”, Qgis.Warning, 10)

message_bar.pushMessage(“”, “Don’t worry. This `Critical message` is an expected failure 😂”, Qgis.Critical)

 

That’s all!

 

Message printed into the QGIS's Python console <class 'qgis._gui.QgsMessageBar'>

2024-09-30T17:44:37 INFO Title : Info message 2024-09-30T17:44:37 WARNING Warning message 2024-09-30T17:44:37 CRITICAL Don't worry. This `Critical message` is an expected failure 😂

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *