<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>Problem solved. I forgot to specify the "Function Name" in the widget. After doing that, it works fine.</p>
<p>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.</p>
<p>Andreas</p>
<p>On 2017-05-08 17:40, Neumann, Andreas wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<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>
<!-- html ignored --><br />
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">_______________________________________________<br /> QGIS-Developer mailing list<br /><a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br /> List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br /> Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></div>
</blockquote>
<p> </p>
<div> </div>
</body></html>