selectionChanged connection is being called twice

by Thriskel   Last Updated May 15, 2019 20:22 PM

I have this function with: self.iface.mapCanvas().selectionChanged.connect(self.openThePano)

which waits for a feature selection change to connect to the function openThePano the issue is that once a single feature is selected the function is called twice and there is only one line that has this signal.

example code:

def actualapp(self):
    #waits for the signal
    self.iface.mapCanvas().selectionChanged.connect(self.openThePano)

def openThePano(self,fId):
    #gets the feature's attributes
    featget = fId.selectedFeatures()
    atributos = [i.attributes() for i in featget]

    source = ogr.Open(self.shproute)
    layer = source.GetLayer() 
    schema = [] 
    ldef = layer.GetLayerDefn()
    for n in range(ldef.GetFieldCount()): # gets the attributes' names
        fdef = ldef.GetFieldDefn(n)
        schema.append(fdef.name)

    # This loop prints attributes of the selected feature and is being printed twice.
    for i in range(len(atributos[0])): 
        print('{}: {}'.format(str(schema[i]),str(atributos[0][i])))

    self.iface.actionZoomToSelected().trigger() 

I expect it to only print once the list of attributes but for some reason I ignore it does it twice, any ideas?

Tags : qgis pyqgis-3


Related Questions


Updated September 29, 2018 02:22 AM

Updated January 10, 2019 15:22 PM

Updated January 20, 2019 15:22 PM

Updated May 15, 2019 21:22 PM

Updated May 19, 2019 11:22 AM