Skip to main content
1 of 2
Joseph
  • 76.3k
  • 7
  • 172
  • 286

You can try replacing your def run(self): function in your script for the one below which should do something you want:

def run(self):
    """Run method that performs all the real work"""
    # show the dialog
    self.dlg.show()

    # Define layer list and add layers to comboBoxes
    layers = self.iface.legendInterface().layers()
    layer_list = []
    for layer in layers:
        layer_list.append(layer.name())
    self.dlg.comboBox.clear()
    self.dlg.comboBox.addItems(layer_list)
    self.dlg.comboBox_2.clear()
    self.dlg.comboBox_2.addItems(layer_list)

    def layer_field():
        # Identify selected layer and add fields to comboBoxes
        selectedLayerIndex = self.dlg.comboBox.currentIndex()
        selectedLayer = layers[selectedLayerIndex]
        fields = selectedLayer.pendingFields()
        fieldnames = [field.name() for field in fields]
        self.dlg.comboBox_5.clear()
        self.dlg.comboBox_5.addItems(fieldnames)

    def table_field():
        # Identify selected layer and add fields to comboBoxes
        selectedLayerIndex = self.dlg.comboBox_2.currentIndex()
        selectedLayer = layers[selectedLayerIndex]
        fields = selectedLayer.pendingFields()
        fieldnames = [field.name() for field in fields]
        self.dlg.comboBox_3.clear()            
        self.dlg.comboBox_3.addItems(fieldnames)
        self.dlg.comboBox_4.clear()
        self.dlg.comboBox_4.addItems(fieldnames)

    self.dlg.comboBox.currentIndexChanged.connect(layer_field)
    self.dlg.comboBox_2.currentIndexChanged.connect(table_field)
Joseph
  • 76.3k
  • 7
  • 172
  • 286