Executing Action on click

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Executing Action on click

Hi all

I would like to implement a python plugin consisting on the following control:
when the control is activated, the user could click on a feature to immediatly execute an action defined in the current layer.

I thought to use something like this:

        def run(self):
                # Create the appropriate map tool and connect the gotPoint() signal.
                self.emitPoint = QgsMapToolEmitPoint(mapCanvas)
                QObject.connect(self.emitPoint, SIGNAL("canvasClicked(const QgsPoint &, Qt::MouseButton)"), self.clickButton)
        def clickButton(self, pnt, but):
                currentLayer = self.iface.mapCanvas().currentLayer()
                currentLayer.select(QgsRectangle(pnt.x()-0.5, pnt.y()-0.5, pnt.x()+0.5, pnt.y()+0.5), False)
                for feature in currentLayer.selectedFeatures():
                        system(currentLayer.actions().expandAction("open", [("path", feature.attributeMap()[0])], 0))

Is it the right way ?

A problem is that the method doAction doesn't exist in python. Another one is that I don't know how to call the method expandAction (types of the arguments ?).

Any idea is welcome.

It could also be interesting to call the action with a double click.