Skip to main content
deleted 32 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I made a little plugin in QGIS, and I got some strange results. The program now mirrors the "Layers Panel". When I add or delete layers from the Panel the QListWidget module get the names of layers. I connected the function to the legendLayersAdded and to layersRemoved SIGNAL.

THE PROBLEM: The add part is ok, and if I remove ONE layer that's fine too. But if I remove multiple layers, the widget gets back the rest of layers' names multiple times (count of removed layers).

Community edit: For however many multiple layers are removed, the remaining layers appear in the list that many times. Ergo, if 3 layers are removed, and there is 1 remaining, that layer appears 3 times in the additional layer pane:

image of the issue

It's like the signal calls the function recursively!? I tried with the layerWasRemoved Signal and the result was the same I made a video of it because it is hard to explain.

[https://www.youtube.com/watch?v=NuLtANtlLtE&feature=youtu.be]

Here is the code:

def ablak(self):
layers = [] 
self.dockwidget.telepules_kezelo.clear()
layers = self.iface.legendInterface().layers()
print "Befor" # Befor layer list
print layers # Layer list "from Layers Panel"
print "After" # After layer list
i = 0 # Just a counter for debubing
lista = self.dockwidget.telepules_kezelo
for layer in layers:
    print layer.name()
    lista.addItem(layer.name())
    i = i+1
    print i # Counter for debuging
layers = []


QgsMapLayerRegistry.instance().legendLayersAdded.connect(self.ablak)

QgsMapLayerRegistry.instance().layersRemoved.connect(self.ablak)

I fade out the problem with transfer the self.dockwidget.telepules_kezelo.clear() line after the Print After line. And it's working fine, but I am really frustrated with it..

Any help will be welcome.

I made a little plugin in QGIS, and I got some strange results. The program now mirrors the "Layers Panel". When I add or delete layers from the Panel the QListWidget module get the names of layers. I connected the function to the legendLayersAdded and to layersRemoved SIGNAL.

THE PROBLEM: The add part is ok, and if I remove ONE layer that's fine too. But if I remove multiple layers, the widget gets back the rest of layers' names multiple times (count of removed layers).

Community edit: For however many multiple layers are removed, the remaining layers appear in the list that many times. Ergo, if 3 layers are removed, and there is 1 remaining, that layer appears 3 times in the additional layer pane:

image of the issue

It's like the signal calls the function recursively!? I tried with the layerWasRemoved Signal and the result was the same I made a video of it because it is hard to explain.

[https://www.youtube.com/watch?v=NuLtANtlLtE&feature=youtu.be]

Here is the code:

def ablak(self):
layers = [] 
self.dockwidget.telepules_kezelo.clear()
layers = self.iface.legendInterface().layers()
print "Befor" # Befor layer list
print layers # Layer list "from Layers Panel"
print "After" # After layer list
i = 0 # Just a counter for debubing
lista = self.dockwidget.telepules_kezelo
for layer in layers:
    print layer.name()
    lista.addItem(layer.name())
    i = i+1
    print i # Counter for debuging
layers = []


QgsMapLayerRegistry.instance().legendLayersAdded.connect(self.ablak)

QgsMapLayerRegistry.instance().layersRemoved.connect(self.ablak)

I fade out the problem with transfer the self.dockwidget.telepules_kezelo.clear() line after the Print After line. And it's working fine, but I am really frustrated with it..

Any help will be welcome.

I made a little plugin in QGIS, and I got some strange results. The program now mirrors the "Layers Panel". When I add or delete layers from the Panel the QListWidget module get the names of layers. I connected the function to the legendLayersAdded and to layersRemoved SIGNAL.

THE PROBLEM: The add part is ok, and if I remove ONE layer that's fine too. But if I remove multiple layers, the widget gets back the rest of layers' names multiple times (count of removed layers).

Community edit: For however many multiple layers are removed, the remaining layers appear in the list that many times. Ergo, if 3 layers are removed, and there is 1 remaining, that layer appears 3 times in the additional layer pane:

image of the issue

It's like the signal calls the function recursively!? I tried with the layerWasRemoved Signal and the result was the same I made a video of it because it is hard to explain.

[https://www.youtube.com/watch?v=NuLtANtlLtE&feature=youtu.be]

Here is the code:

def ablak(self):
layers = [] 
self.dockwidget.telepules_kezelo.clear()
layers = self.iface.legendInterface().layers()
print "Befor" # Befor layer list
print layers # Layer list "from Layers Panel"
print "After" # After layer list
i = 0 # Just a counter for debubing
lista = self.dockwidget.telepules_kezelo
for layer in layers:
    print layer.name()
    lista.addItem(layer.name())
    i = i+1
    print i # Counter for debuging
layers = []


QgsMapLayerRegistry.instance().legendLayersAdded.connect(self.ablak)

QgsMapLayerRegistry.instance().layersRemoved.connect(self.ablak)

I fade out the problem with transfer the self.dockwidget.telepules_kezelo.clear() line after the Print After line. And it's working fine, but I am really frustrated with it.

edited tags; edited tags
Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286
corrected spelling, fixed grammar, added explanation of problem with a picture.
Source Link

QGIS, Python PyQGIS SIGNAL call wirednessweirdness

I makemade a little plugin in QGIS, and I getgot some strange resultresults. The program now mirrormirrors the "Layers Panel". When I add or delete layers from the Panel the QListWidget module get the namenames of layers. I connectconnected the function to the legendLayersAdded and to layersRemoved SIGNAL.

THE PROBLEM: The add part is ok, and if I remove ONE layer that's fine totoo. But if I remove multiple layers, the widget getgets back the rest of layers namelayers' names multiple times (count of removed layers). I's

Community edit: For however many multiple layers are removed, the remaining layers appear in the list that many times. Ergo, if 3 layers are removed, and there is 1 remaining, that layer appears 3 times in the additional layer pane:

image of the issue

It's like the signal calls the function recursiverecursively!? I tried whit layerWasRemovedwith the layerWasRemoved Signal and the result was the same I made a video of it becousebecause it is hard to explainedexplain.

[https://www.youtube.com/watch?v=NuLtANtlLtE&feature=youtu.be]

Here is the code:

def ablak(self):
layers = [] 
self.dockwidget.telepules_kezelo.clear()
layers = self.iface.legendInterface().layers()
print "Befor" # Befor layer list
print layers # Layer list "from Layers Panel"
print "After" # After layer list
i = 0 # Just a counter for debubing
lista = self.dockwidget.telepules_kezelo
for layer in layers:
    print layer.name()
    lista.addItem(layer.name())
    i = i+1
    print i # Counter for debuging
layers = []


QgsMapLayerRegistry.instance().legendLayersAdded.connect(self.ablak)

QgsMapLayerRegistry.instance().layersRemoved.connect(self.ablak)

I fade out the problem whitwith transfer the self.dockwidget.telepules_kezelo.clear() line after the Print After line. And it's working fine, but I am really fluster aboutfrustrated with it..

Any help will be welcome.

QGIS, Python SIGNAL call wiredness

I make a little plugin, and I get some strange result. The program now mirror the "Layers Panel". When I add or delete layers from the Panel the QListWidget module get the name of layers. I connect the function to the legendLayersAdded and to layersRemoved SIGNAL.

THE PROBLEM: The add part is ok, and if I remove ONE layer that's fine to. But if I remove multiple layers, the widget get back the rest of layers name multiple times (count of removed layers). I's like the signal calls the function recursive!? I tried whit layerWasRemoved Signal and the result was the same I made a video of it becouse it hard to explained.

[https://www.youtube.com/watch?v=NuLtANtlLtE&feature=youtu.be]

Here is the code:

def ablak(self):
layers = [] 
self.dockwidget.telepules_kezelo.clear()
layers = self.iface.legendInterface().layers()
print "Befor" # Befor layer list
print layers # Layer list "from Layers Panel"
print "After" # After layer list
i = 0 # Just a counter for debubing
lista = self.dockwidget.telepules_kezelo
for layer in layers:
    print layer.name()
    lista.addItem(layer.name())
    i = i+1
    print i # Counter for debuging
layers = []


QgsMapLayerRegistry.instance().legendLayersAdded.connect(self.ablak)

QgsMapLayerRegistry.instance().layersRemoved.connect(self.ablak)

I fade out the problem whit transfer the self.dockwidget.telepules_kezelo.clear() line after the Print After line. And it's working fine, but I really fluster about it..

Any help will be welcome.

PyQGIS SIGNAL call weirdness

I made a little plugin in QGIS, and I got some strange results. The program now mirrors the "Layers Panel". When I add or delete layers from the Panel the QListWidget module get the names of layers. I connected the function to the legendLayersAdded and to layersRemoved SIGNAL.

THE PROBLEM: The add part is ok, and if I remove ONE layer that's fine too. But if I remove multiple layers, the widget gets back the rest of layers' names multiple times (count of removed layers).

Community edit: For however many multiple layers are removed, the remaining layers appear in the list that many times. Ergo, if 3 layers are removed, and there is 1 remaining, that layer appears 3 times in the additional layer pane:

image of the issue

It's like the signal calls the function recursively!? I tried with the layerWasRemoved Signal and the result was the same I made a video of it because it is hard to explain.

[https://www.youtube.com/watch?v=NuLtANtlLtE&feature=youtu.be]

Here is the code:

def ablak(self):
layers = [] 
self.dockwidget.telepules_kezelo.clear()
layers = self.iface.legendInterface().layers()
print "Befor" # Befor layer list
print layers # Layer list "from Layers Panel"
print "After" # After layer list
i = 0 # Just a counter for debubing
lista = self.dockwidget.telepules_kezelo
for layer in layers:
    print layer.name()
    lista.addItem(layer.name())
    i = i+1
    print i # Counter for debuging
layers = []


QgsMapLayerRegistry.instance().legendLayersAdded.connect(self.ablak)

QgsMapLayerRegistry.instance().layersRemoved.connect(self.ablak)

I fade out the problem with transfer the self.dockwidget.telepules_kezelo.clear() line after the Print After line. And it's working fine, but I am really frustrated with it..

Any help will be welcome.

deleted 11 characters in body; edited title
Source Link
ahmadhanb
  • 41.4k
  • 5
  • 54
  • 109
Loading
Source Link
Sanyi
  • 63
  • 4
Loading