I have a project open with 6 layers (MapInfo .tab format), have set the style for each layer and added labels for 1 of them. So for a simple project the .qgs file is about 2000 lines long and among other things I can't quite make sense of there are 6 (duplicate) examples of a Python function my_form_open(dialog, layer, feature)
in the .qgs file (1 for every layer?). Does anyone know why they are there in the first place and then why would it write out the example 6 times...? the function doesn't have a return
statement so it wouldn't work anyway
-
1What version of QGIS is the .qgs file?– artwork21Commented Jun 10, 2016 at 12:12
-
version 2.14.2-Essen– AlexCommented Jun 10, 2016 at 13:20
1 Answer
There is the possibility to add python code to the QGIS attribute forms which will be executed when it opens. To configure it go to the Fields tab in the layer properties and change the Python Init Code combobox.
If you choose Provide code in this dialog you will see the code. As long as this combobox is set to a different entry the code will not be executed. The code which you see is the default template for the code.
N.b. python code does not require a return
statement to be working.
-
ok...the combobox was set to blank for each of my layers but the code was still included - but I get that it's just a template for inserting custom code. I changed it to Load from external file, saved and still there in the project file though. It's not too important just trying to understand why these things are there.– AlexCommented Jun 10, 2016 at 13:26
-
N.b. surely if you're defining a function then it needs to have a return value?– AlexCommented Jun 10, 2016 at 13:28
-
Once changed, the text should stay there so you don't lose your carefully written code if you temporarily change the combobox. A pull request that will not write the template code to the file would probably be accepted. concerning return value stackoverflow.com/questions/15300550/… Commented Jun 10, 2016 at 13:37