[Qgis-developer] How to add an action into a layer through python

Luca Mandolesi mandoluca at gmail.com
Sun Apr 16 13:21:27 PDT 2017


Hi Salvatore, so I will try to extend your python macro for selecting
records through relationship with the code of Andrea Borruso!!!

Regards
Luca

Il 16 apr 2017 9:58 PM, "Salvatore Larosa" <lrssvtml at gmail.com> ha scritto:

> Hi Luca,
>
> On Fri, Apr 14, 2017 at 10:31 PM, Luca Mandolesi <mandoluca at gmail.com>
> wrote:
> > Hi,
> > I would to know if it's possibile to add a python action into a layer
> > charged inside layer registry? There is a method inside pyQgis API?
>
> sure, it is possible. With 2.x version the below example should be working:
>
> >>> vl = iface.activeLayer()
> >>> actions = vl.actions()
> >>>
> >>> actionName = 'Show feature id'
> >>> actionContent = 'from qgis.utils import iface; iface.messageBar().pushMessage("Feature
> ID: [% $id %]", 0)'
> >>>
> >>> actions.addAction(QgsAction.GenericPython, actionName, actionContent)
>
> Since QGIS 3 the code for actions was revamped, please see
> https://goo.gl/rGgYHC.
>
> Ciao,
> -SL
>
>
> --
> Salvatore Larosa
> linkedIn: http://linkedin.com/in/larosasalvatore
> twitter: @lrssvt
> skype: s.larosa
> IRC: lrssvt on freenode
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170416/015f87a3/attachment.html>


More information about the Qgis-developer mailing list