[Qgis-developer] how to call qgis signal?

Ricardo Filipe Soares Garcia da ricardo.garcia.silva at gmail.com
Tue Aug 17 07:29:37 EDT 2010


Hello list
I am trying to call the layerWasAdded and layerWillBeRemoved signals
that are emmited by the mapLayerRegistry.instance() object, but I'm
getting no luck.
I am hoping to toggle my plugin on and off based on the user having
any vector layer of type 'line' loaded on the map canvas.
I've read [1], that says that the signal definition must match exactly
with the signature of the function... I think that is what I am doing,
but I'm not sure.

I am trying:

def __init__(self, iface):
    self.

def initGui(self):
    #...some other code
    QObject.connect(self.layerRegistry,
SIGNAL("layerWasAdded(QgsMapLayer *theMapLayer)"),
self.toggle_plugin_availability)
    QObject.connect(self.layerRegistry,
SIGNAL("layerWillBeRemoved(QString theLayerId)"),
self.toggle_plugin_availability)

def toggle_plugin_availability(self, arg):
    if len(self._get_loaded_layers()["vectorLine"]) == 0:
            self.action.setEnabled(False)
        else:
            self.action.setEnabled(True)




[1] - http://blog.qgis.org/node/102


-- 
___________________________ ___ __
Ricardo Garcia Silva


More information about the Qgis-developer mailing list