<div dir="ltr"><div>Denis,</div><div><br></div><div>You were right, using <span style="font-family:arial,sans-serif;font-size:13px">selectionChanged on mapCanvas worked just fine. </span></div><div><br></div><div>Thanks!</div>
<div><br></div><div>Alexandre Neto<br></div><div><br></div><div><br></div><div>this worked just great. I guess I had been in the right direction before, but some how lost it.<br></div><div><br></div>On Thu, Aug 22, 2013 at 1:37 PM, Denis Rouzaud <span dir="ltr"><<a href="mailto:denis.rouzaud@gmail.com" target="_blank">denis.rouzaud@gmail.com</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Hi Alexandre,<br>
<br>
Why don't you use selectionChanged on mapCanvas?<br>
</div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000">
You have a line commented, I suppose this was it. <br></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">Mainly, I suppose the problem is that you never disconnect you layer
from the signals since you always call the method for the current
layer....so the previous current is never disconnected....<br>
<br>
Hope this helps,<br>
<br>
Cheers,<br>
<br>
Denis<div><div class="h5"><br>
<br>
<br>
<div>On 08/22/2013 02:11 PM, Alexandre Neto
wrote:<br>
</div>
</div></div><blockquote type="cite"><div><div class="h5">
<div dir="ltr">
<div>Hello all,</div>
<div><br>
</div>
<div>I'm updating the <a href="http://plugins.qgis.org/plugins/splitmultipart/" target="_blank">Multipart
split plugin</a> to make it work with the 2.0 API.</div>
<div><br>
</div>
<div>Has I have successfully updated the plugin to make it work
in 2.0, I would like to improve it's button behavior to work
like the rest of the advanced editing toolbar. I am able to
enable and disable it if the current layer is editable. </div>
<div><br>
</div>
<div>Now I'm trying to get the same behavior if there are
selected features. I have made it work, but QGIS starts to get
really slow... I found out that's because lots of connections
are being created to SIGNAL("selectionChanged()").</div>
<div><br>
</div>
<div>Can someone please, point me in the right direction, or
tell me where can I find some code example doing this?</div>
<div><br>
</div>
<div>Thank you very much,</div>
<div><br>
</div>
<div>Alexandre Neto</div>
<div><br>
</div>
<div>Part of the code bellow:</div>
<div><br>
</div>
<div>
<div>def initGui(self):</div>
<div> # Create action that will start plugin
configuration</div>
<div> self.action = QAction(</div>
<div> QIcon(":/plugins/splitmultipart/icon.svg"),</div>
<div> QCoreApplication.translate('Multipart split',
u"Split Selected Multipart features"),
self.iface.mainWindow())</div>
<div> self.action.setEnabled(False)</div>
<div> </div>
<div>
# connect to signals for button behavior</div>
<div> QObject.connect(self.action,
SIGNAL("triggered()"), self.run)</div>
<div> QObject.connect(self.iface,
SIGNAL("currentLayerChanged(QgsMapLayer*)"), self.toggle)</div>
<div> #QObject.connect(self.iface,
SIGNAL("selectionChanged(QgsMapLayer *)"), self.toggle)</div>
<div><br>
</div>
<div> # Add toolbar button and menu item</div>
<div>
self.iface.advancedDigitizeToolBar().addAction(self.action)</div>
<div> self.iface.editMenu().addAction(self.action)</div>
<div> </div>
<div> def toggle(self):</div>
<div> mc = self.canvas</div>
<div> layer = mc.currentLayer()</div>
<div> </div>
<div> # Decide whether the plugin button is enable or
disable</div>
<div> if layer <> None:</div>
<div> # set enable</div>
<div> if layer.isEditable():</div>
<div>
QObject.connect(layer,SIGNAL("editingStopped()"),self.toggle)</div>
<div>
QObject.connect(layer,
SIGNAL("selectionChanged()"), self.toggle)</div>
<div>
QObject.disconnect(layer,SIGNAL("editingStarted()"),self.toggle)</div>
<div>
self.iface.messageBar().pushMessage("Debug"," Connect
SIGNAL(selectionChanged()",0)</div>
<div> if layer.selectedFeatureCount() > 0:</div>
<div> self.action.setEnabled(True)</div>
<div> else:</div>
<div> self.action.setEnabled(False)</div>
<div>
</div>
<div> # set disable </div>
<div> else:</div>
<div> self.action.setEnabled(False)</div>
<div>
QObject.connect(layer,SIGNAL("editingStarted()"),self.toggle)</div>
<div>
QObject.disconnect(layer,SIGNAL("editingStopped()"),self.toggle)</div>
<div> QObject.disconnect(layer,
SIGNAL("selectionChanged()"), self.toggle)</div>
<div>
self.iface.messageBar().pushMessage("Debug"," Disconnect
SIGNAL(selectionChanged()",0)</div>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><div class="im"><pre>_______________________________________________
Qgis-developer mailing list
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
</pre>
</div></blockquote>
<br>
</div>
</blockquote></div><br></div></div>