Executing Action on click

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Executing Action on click

determek
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):
                mapCanvas=self.iface.mapCanvas()
                # Create the appropriate map tool and connect the gotPoint() signal.
                self.emitPoint = QgsMapToolEmitPoint(mapCanvas)
                mapCanvas.setMapTool(self.emitPoint)
                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.

Thank's
Karl
Reply | Threaded
Open this post in threaded view
|

Re: Executing Action on click

Giovanni Manghi

Hi!


> when the control is activated, the user could click on a feature to
> immediatly execute an action defined in the current layer.


This would be a very cool plugin, do you plan do make it available in
the contributed repository?


cheers!

-- Giovanni --



_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Executing Action on click

Gavin Macaulay
In reply to this post by determek
Karl,

Are you aware that something similar (but not quite) already exists in Qgis? One can define actions for vector layers and and run actions for features. However, one can't do that by clicking on the feature in the map display, just in the table display.

If you are familiar with C++, perhaps you could build on the existing code rather than duplicate it with a python plugin?

Regards

Gavin

---- Original message ----

>Date: Wed, 4 Aug 2010 02:45:30 -0700 (PDT)
>From: Karl D <[hidden email]>  
>Subject: [Qgis-developer] Executing Action on click  
>To: [hidden email]
>
>
>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):
>                mapCanvas=self.iface.mapCanvas()
>                # Create the appropriate map tool and connect the gotPoint()
>signal.
>                self.emitPoint = QgsMapToolEmitPoint(mapCanvas)
>                mapCanvas.setMapTool(self.emitPoint)
>                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.
>
>Thank's
>Karl
>--
>View this message in context: http://osgeo-org.1803224.n2.nabble.com/Executing-Action-on-click-tp5371808p5371808.html
>Sent from the qgis-developer mailing list archive at Nabble.com.
>_______________________________________________
>Qgis-developer mailing list
>[hidden email]
>http://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Executing Action on click

Jürgen E. Fischer
In reply to this post by determek
Hi Karl,

On Wed, 04. Aug 2010 at 02:45:30 -0700, Karl D wrote:
> A problem is that the method doAction doesn't exist in python.

Fixed in r14010.


Jürgen

--
Jürgen E. Fischer         norBIT GmbH               Tel. +49-4931-918175-20
Dipl.-Inf. (FH)           Rheinstraße 13            Fax. +49-4931-918175-50
Software Engineer         D-26506 Norden               http://www.norbit.de

--
norBIT Gesellschaft fuer Unternehmensberatung und Informationssysteme mbH
Rheinstrasse 13, 26506 Norden
GF: Jelto Buurman, HR: Amtsgericht Emden, HRB 5502

_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Executing Action on click

determek
Good news !

At this stage, I call a unique method taking as parameters the attributes of the feature.
With doAction it will be more generic.

As first use case, I've thought to a map desktop where I can place all sort of shortcuts (files, folders or urls).
I call then an action to open the shortcut (gnome-open on ubuntu, explorer on windows, start on Mac, ...).

Thank's
Karl