Creare un Plugin personalizzato in Qgis

Immagina di avere una grande idea per dare ancora più potenza al tuo QGIS e di poterlo fare con un linguaggio semplice, python.

Ecco come creare un pluggin di Qgis!!

Un plugin per fare un altro plugin

Installate il plugins builder 3 che si descrive, giustamente, come “Creates a QGIS plugin template for use as a starting point in plugin development”.

Oltre a questa pagina, ti consiglio alcune risorse online:

QGis tutorial – Plugin development – part 1

u Rob

i 29K views

Jan 15 2021

 

Attenzione, durante l’installazione, ignorate questo messaggio:

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.

 

Quindi avrete questo risultato dopo lesecuzione di  plugins builder 3, durate il quale avrete specificato il nome e la posizione del plugin (non viene generato nella cartella ‘giusta’, deve essere spostato poi a mano),  l’email dello sviluppatore, se stabile o no, nome della versione…

Vedrai un testo come quello che segue.

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

 

E’ molto utile un altro “meta plugin”, che si chiama plugin reload. In questo modo, posso definire un plugin che si aggiorna

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)

 

 

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 😂

 

 

 

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *