<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi,</p>
<p>It's been a long time since I last wrote python init scripts for forms.</p>
<p>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.</p>
<p>Below is my really simple code that should write something to the message bar when the form is loaded:</p>
<p>----------------------------------</p>
<p><span style="font-family: 'courier new', courier, monospace;"># -*- coding: utf-8 -*-</span><br /><span style="font-family: 'courier new', courier, monospace;">"""</span><br /><span style="font-family: 'courier new', courier, monospace;">QGIS-Formulare können eine Python-Funktion haben, die beim Öffnen des Formulars gestartet wird.</span></p>
<p><span style="font-family: 'courier new', courier, monospace;">Hier kann dem Formular Extra-Logik hinzugefügt werden.</span></p>
<p><span style="font-family: 'courier new', courier, monospace;">Der Name der Funktion wird im Feld "Python-Init-Function" angegeben.</span><br /><span style="font-family: 'courier new', courier, monospace;">Ein Beispiel:</span><br /><span style="font-family: 'courier new', courier, monospace;">"""</span><br /><span style="font-family: 'courier new', courier, monospace;">from PyQt4.QtGui import QWidget<br /></span><span style="font-family: 'courier new', courier, monospace;"></span></p>
<p><span style="font-family: 'courier new', courier, monospace;">def my_form_open(dialog, layer, feature):</span><br /><span style="font-family: 'courier new', courier, monospace;">    msgBar = iface.messageBar()</span><br /><span style="font-family: 'courier new', courier, monospace;">    msgBar.pushInfo("Message from init script: ","Hi There")</span></p>
<p>------------------------------------</p>
<p>My other question:</p>
<p>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?</p>
<p>--------------</p>
<p>Thank you for your help,</p>
<p>Andreas</p>
<p> </p>
<div> </div>
</body></html>