[Qgis-developer] Re: how to call qgis signal?
Ricardo Filipe Soares Garcia da
ricardo.garcia.silva at gmail.com
Tue Aug 17 07:32:06 EDT 2010
I am sorry, I accidentally pressed some key combination that caused
gmail to send the previous message before it was finished...
Please follow the rest of the code in the attached version of the
previous e-mail.
On Tue, Aug 17, 2010 at 12:29 PM, Ricardo Filipe Soares Garcia da
<ricardo.garcia.silva at gmail.com> wrote:
> 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.layerRegistry = iface.QgsMapLayerRegistry.instance()
#more code
>
> 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
>
--
___________________________ ___ __
Ricardo Garcia Silva
More information about the Qgis-developer
mailing list