[QGIS-Developer] Troubles with Python init script for forms

Neumann, Andreas a.neumann at carto.net
Mon May 8 08:40:35 PDT 2017


Hi, 

It's been a long time since I last wrote python init scripts for forms. 

Now I have troubles writing even the simplest code. Nothing happens if I
click on a feature. The form opens, but no error messages and no
reaction to my code ... This is on QGIS 2.18.7. I use the mode "Provide
code in this dialog" and add the code in the "Python init code" widget
of the "Fields" tab. 

Below is my really simple code that should write something to the
message bar when the form is loaded: 

---------------------------------- 

# -*- coding: utf-8 -*-
"""
QGIS-Formulare können eine Python-Funktion haben, die beim Öffnen des
Formulars gestartet wird. 

Hier kann dem Formular Extra-Logik hinzugefügt werden. 

Der Name der Funktion wird im Feld "Python-Init-Function" angegeben.
Ein Beispiel:
"""
from PyQt4.QtGui import QWidget

def my_form_open(dialog, layer, feature):
    msgBar = iface.messageBar()
    msgBar.pushInfo("Message from init script: ","Hi There") 

------------------------------------ 

My other question: 

If I change the code in the "Fields" widget - would it "auto-load" or do
I have to do something to trigger a reload of the script? 

-------------- 

Thank you for your help, 

Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170508/15f3bc48/attachment.html>


More information about the QGIS-Developer mailing list