[Qgis-developer] Need help with Plugin button behavior connected to SIGNAL("selectionChanged()")

Bernhard Ströbl bernhard.stroebl at jena.de
Thu Aug 22 05:33:03 PDT 2013


Alexandre,

I have included your tool in the DigitizingTools plugin [1] as I have 
told you the other day. DigitizingTools is already QGIS 2.0 ready 
(though still marked as experimental). Feel free to join this effort.

Concerning your problem I reckon you have the same signal connected many 
times thus slowing down QGIS. See the enable method in any of the 
digitizing tools, e.g. [2] how I solved it.

regards

Bernhard

[1] http://plugins.qgis.org/plugins/DigitizingTools/
[2] 
https://github.com/bstroebl/DigitizingTools/blob/master/tools/dtprolongline.py

Am 22.08.2013 14:11, schrieb Alexandre Neto:
> Hello all,
>
> I'm updating the Multipart split plugin
> <http://plugins.qgis.org/plugins/splitmultipart/> to make it work with
> the 2.0 API.
>
> 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.
>
> 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()").
>
> Can someone please, point me in the right direction, or tell me where
> can I find some code example doing this?
>
> Thank you very much,
>
> Alexandre Neto
>
> Part of the code bellow:
>
> def initGui(self):
>          # Create action that will start plugin configuration
>          self.action = QAction(
>              QIcon(":/plugins/splitmultipart/icon.svg"),
>              QCoreApplication.translate('Multipart split', u"Split
> Selected Multipart features"), self.iface.mainWindow())
>          self.action.setEnabled(False)
>          # connect to signals for button behavior
>          QObject.connect(self.action, SIGNAL("triggered()"), self.run)
>          QObject.connect(self.iface,
> SIGNAL("currentLayerChanged(QgsMapLayer*)"), self.toggle)
>          #QObject.connect(self.iface,
> SIGNAL("selectionChanged(QgsMapLayer *)"), self.toggle)
>
>          # Add toolbar button and menu item
>          self.iface.advancedDigitizeToolBar().addAction(self.action)
>          self.iface.editMenu().addAction(self.action)
>      def toggle(self):
>          mc = self.canvas
>          layer = mc.currentLayer()
>          # Decide whether the plugin button is enable or disable
>          if layer <> None:
>              # set enable
>              if layer.isEditable():
>
> QObject.connect(layer,SIGNAL("editingStopped()"),self.toggle)
>                  QObject.connect(layer, SIGNAL("selectionChanged()"),
> self.toggle)
>
> QObject.disconnect(layer,SIGNAL("editingStarted()"),self.toggle)
>                  self.iface.messageBar().pushMessage("Debug"," Connect
> SIGNAL(selectionChanged()",0)
>                  if layer.selectedFeatureCount() > 0:
>                      self.action.setEnabled(True)
>                  else:
>                      self.action.setEnabled(False)
>              # set disable
>              else:
>                  self.action.setEnabled(False)
>
> QObject.connect(layer,SIGNAL("editingStarted()"),self.toggle)
>
> QObject.disconnect(layer,SIGNAL("editingStopped()"),self.toggle)
>                  QObject.disconnect(layer, SIGNAL("selectionChanged()"),
> self.toggle)
>                  self.iface.messageBar().pushMessage("Debug","
> Disconnect SIGNAL(selectionChanged()",0)
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
>
> __________ Information from ESET Mail Security, version of virus signature database 8715 (20130822) __________
>
> The message was checked by ESET Mail Security.
> http://www.eset.com
>



__________ Information from ESET Mail Security, version of virus signature database 8715 (20130822) __________

The message was checked by ESET Mail Security.
http://www.eset.com




More information about the Qgis-developer mailing list