<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi Alexandre,<br>
    <br>
    Why don't you use selectionChanged on mapCanvas?<br>
    You have a line commented, I suppose this was it. <br>
    <br>
    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<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 08/22/2013 02:11 PM, Alexandre Neto
      wrote:<br>
    </div>
    <blockquote
cite="mid:CA+H0G_ESUYjzoBMOPQF1BtBk0XLCpgjK_gMpus7kczkU4xk02g@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>Hello all,</div>
        <div><br>
        </div>
        <div>I'm updating the <a moz-do-not-send="true"
            href="http://plugins.qgis.org/plugins/splitmultipart/">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 class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Qgis-developer mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/qgis-developer">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>