[GIS] Enable single feature selection in QGIS using Python

pyqgisqgis-2qgis-pluginsqgis-processing

I want to enable single feature selection using Python. I want to make a script in Python that will first enable single feature selection, and then it will return the id of selected feature. I have coded the second part, but how do I enable single feature selection?

layer = iface.activeLayer()
h = layer.selectedFeatures()
    for f in h:
        g =  f['ID']
        print g

Best Answer

What do you mean by single feature selection? The Select Feature(s) tool is single feature select if you just click and do not drag the cursor.

You can set the active tool with:

iface.actionSelect().trigger()

You can write your own selection tool like described here:

Creating Selection MapTool in PyQgis Custom Application

Related Question