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

Neumann, Andreas a.neumann at carto.net
Tue May 9 00:11:52 PDT 2017


Hi, 

Problem solved. I forgot to specify the "Function Name" in the widget.
After doing that, it works fine. 

On the other issue: it seems like it "autoloads" the code every time I
did some changes in the code. So that seems to work well either. 

Andreas 

On 2017-05-08 17:40, Neumann, Andreas wrote:

> 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 
> 
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170509/0980dce9/attachment.html>


More information about the QGIS-Developer mailing list