Developing a qgis plugin, I found that if no layer is selected in the Layers panel I can iterate over all layers and do anything to them, but "activate" them.
Could someone give me a hint please? Thank you!
You can set the active layer using the qgis.utils.iface object (i.e. QgisInterface):
Clearing the selection, or the active layer (underlined QTreeWidget item in QGIS 2.0), in the legend is a bit more involved:
There are three ways to retrieve the current layers, relative to what you may want to do:
Reference these answers for information about the differences in those layer collections.