Did you try to compare to QgsVectorLayer.Hidden? The list of types is here:
http://qgis.org/api/classQgsVectorLayer.html#a441a8cbb0170c48da6aa7b02dad4b5a3 Regards, Matthias On 23.06.2014 15:56, Tom Chadwin wrote: > Hi Matthias > > Ah, OK. I didn't gather that from the API docs. OK, I can print out the > editType() value now, which is 11 for hidden: > > print i.editType(fields.indexFromName(field)) > > However, I can't test for it: > > if i.editType(fields.indexFromName(field)) != 11 > > SyntaxError: invalid syntax > > I've tried int() or str() to cast the value into another datatype, but with > no effect. What am I getting wrong now? > > Thanks > > Tom > > PS And I shall keep an eye on this in version past 2.2 and report back. > > >> -----Original Message----- >> From: Matthias Kuhn [mailto:matthias.k...@gmx.ch] >> Sent: 23 June 2014 14:46 >> To: Tom Chadwin; qgis-developer@lists.osgeo.org >> Subject: Re: [Qgis-developer] Field visibility in Python >> >> Hi Tom, >> >> That works starting from 2.3 (master) / 2.4 (release/stable) >> >> For 2.2 you will have to work with >> >> i.editType( fields.indexFromName(field) ) >> >> This will continue to work with 2.4 (And it would be nice if you could >> test and report in case there's a difference between 2.2 and 2.3 as >> there's the last week of bugfixing before the release now). >> >> Best >> Matthias >> >> On 23.06.2014 15:39, Tom Chadwin wrote: >>> Hi Matthias >>> >>> Many thanks for this. It's not working for me quite yet: >>> >>> AttributeError: 'QgsVectorLayer' object has no attribute >> 'editorWidgetV2ByName' >>> Python version: >>> 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] >>> >>> QGIS version: >>> 2.2.0-Valmiera Valmiera, c3a2817 >>> >>> Any ideas? >>> >>> Tom >>> >>> >>>> -----Original Message----- >>>> From: Matthias Kuhn [mailto:matthias.k...@gmx.ch] >>>> Sent: 23 June 2014 13:55 >>>> To: Tom Chadwin; qgis-developer@lists.osgeo.org >>>> Subject: Re: [Qgis-developer] Field visibility in Python >>>> >>>> Hi Tom, >>>> >>>> The following example should should print the type for all widgets. >>>> editorWidgetV2ByName( fieldName ) will return "Hidden" for all hidden >>>> fields, so for checking simply use string comparison. >>>> editorWidgetV2Config can then be used to access further configuration >>>> options for the editor widgets (where applicable, "Hidden" has no config >>>> options) >>>> >>>> canvas = qgis.utils.iface.mapCanvas() >>>> allLayers = canvas.layers() >>>> for i in allLayers: >>>> fields = i.pendingFields() >>>> field_names = [field.name() for field in fields] >>>> for field in field_names: >>>> print i.editorWidgetV2ByName( field ) >>>> >>>> >>>> I hope that answers part of your question. >>>> >>>> Best, >>>> Matthias >>>> >>>> On 23.06.2014 14:00, Tom Chadwin wrote: >>>>> Apologies for cross-post from qgis-user - I thought -developer only dealt >>>> with QGIS core, rather than also with plugin development. >>>>> How do I determine in Python whether each field is hidden? I can't get >>>> editType() to work (and know it is deprecated). Does anyone have an >>>> example of this using editorWidgetV2Config()? I'm not getting it right: >>>>> canvas = qgis.utils.iface.mapCanvas() >>>>> allLayers = canvas.layers() >>>>> for i in allLayers: >>>>> fields = i.pendingFields() >>>>> field_names = [field.name() for field in fields] >>>>> for field in field_names: >>>>> >>>>> print(i.editorWidgetV2Config(fields.indexFromName(str(field)))) >>>>> >>>>> This just gives me lots of {}, suggesting perhaps that I am not setting >>>>> the >>>> field index for editorWidgetV2Config() correctly. >>>> fields.indexFromName(str(field)) works as the *attribute* index for >>>> attributeDisplayName(), but the docs say >>>> attributeDisplayName(attributeIndex), while they say >>>> editorWidgetV2Config(fieldIdx). What's the difference between >>>> attributeIndex and fieldIdx? >>>>> Thanks >>>>> >>>>> Tom >>>>> >>>>> >>>>> Tom Chadwin, UK National Parks Portal Manager >>>>> Telephone: 01434 611511 Mob: 07881 109617 >>>>> Web: >> www.northumberlandnationalpark.org.uk<http://www.northumberlandnati >>>> onalpark.org.uk/> >>>>> IMPORTANT NOTICE - Disclaimer - This communication is from >>>> Northumberland National Park Authority (NNPA).The Authority’s head >> office >>>> and principal place of business is Eastburn, South Park, Hexham, >>>> Northumberland, NE46 1BS, United Kingdom. If you are not the intended >>>> recipient(s) please note that any form of disclosure, distribution, copying >> or >>>> use of this communication or the information in it or in any attachments is >>>> strictly prohibited and may be unlawful. If you have received this >>>> communication in error, please delete the email and destroy any copies of >> it. >>>> Any views or opinions presented are solely those of the author and do >> not >>>> necessarily represent those of NNPA.Contractors or potential contractors >> are >>>> reminded that a formal Order or Contract is needed for NNPA to be >> bound >>>> by any offer or acceptance of terms for the supply of goods or services >>>> Although this email and any attachments are believed to be free of any >> virus >>>> or other defects which might affect any computer or IT system into which >>>> they are received, no responsibility is accepted by the NNPA for any loss >> or >>>> damage arising in any way from the receipt or use thereof. Computer >>>> systems of this Authority may be monitored and communications carried >> out >>>> on them recorded, to secure the effective operation of the system and >> for >>>> other lawful purpose. >>>>> _______________________________________________ >>>>> Qgis-developer mailing list >>>>> Qgis-developer@lists.osgeo.org >>>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer >>> >>> Tom Chadwin, UK National Parks Portal Manager >>> Telephone: 01434 611511 Mob: 07881 109617 >>> Web: >> www.northumberlandnationalpark.org.uk<http://www.northumberlandnati >> onalpark.org.uk/> >>> IMPORTANT NOTICE - Disclaimer - This communication is from >> Northumberland National Park Authority (NNPA).The Authority’s head office >> and principal place of business is Eastburn, South Park, Hexham, >> Northumberland, NE46 1BS, United Kingdom. If you are not the intended >> recipient(s) please note that any form of disclosure, distribution, copying >> or >> use of this communication or the information in it or in any attachments is >> strictly prohibited and may be unlawful. If you have received this >> communication in error, please delete the email and destroy any copies of it. >> Any views or opinions presented are solely those of the author and do not >> necessarily represent those of NNPA.Contractors or potential contractors are >> reminded that a formal Order or Contract is needed for NNPA to be bound >> by any offer or acceptance of terms for the supply of goods or services >> Although this email and any attachments are believed to be free of any virus >> or other defects which might affect any computer or IT system into which >> they are received, no responsibility is accepted by the NNPA for any loss or >> damage arising in any way from the receipt or use thereof. Computer >> systems of this Authority may be monitored and communications carried out >> on them recorded, to secure the effective operation of the system and for >> other lawful purpose. >>> _______________________________________________ >>> Qgis-developer mailing list >>> Qgis-developer@lists.osgeo.org >>> http://lists.osgeo.org/mailman/listinfo/qgis-developer >> > > > Tom Chadwin, UK National Parks Portal Manager > Telephone: 01434 611511 Mob: 07881 109617 > Web: > www.northumberlandnationalpark.org.uk<http://www.northumberlandnationalpark.org.uk/> > > IMPORTANT NOTICE - Disclaimer - This communication is from Northumberland > National Park Authority (NNPA).The Authority’s head office and principal > place of business is Eastburn, South Park, Hexham, Northumberland, NE46 1BS, > United Kingdom. If you are not the intended recipient(s) please note that any > form of disclosure, distribution, copying or use of this communication or the > information in it or in any attachments is strictly prohibited and may be > unlawful. If you have received this communication in error, please delete the > email and destroy any copies of it. Any views or opinions presented are > solely those of the author and do not necessarily represent those of > NNPA.Contractors or potential contractors are reminded that a formal Order or > Contract is needed for NNPA to be bound by any offer or acceptance of terms > for the supply of goods or services Although this email and any attachments > are believed to be free of any virus or other defects which might affect any > computer or IT system into which they are received, no responsibility is > accepted by the NNPA for any loss or damage arising in any way from the > receipt or use thereof. Computer systems of this Authority may be monitored > and communications carried out on them recorded, to secure the effective > operation of the system and for other lawful purpose. > _______________________________________________ > Qgis-developer mailing list > Qgis-developer@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/qgis-developer _______________________________________________ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer