I got another issue writing a plugin to convert three shape files into an .obs input file. I created a UI (Qt) with a QComboBox to select a layer (that works fine). As soon as one of the layers in the QComboBox is selected, a second ComboBox should be filled with the fields of the layer to select from. To do that I'm trying to call a function, that is to be called, as soon, as a layer is selected in the first ComboBox. Unfortuntelly that does not work. Here is what I tried:
First I wrote a function to fill the second ComboBox with the field names:
def build_Layer_Index_Changed():
QMessageBox.information(None, "DEBUG", "Build Layer routine called. :)")
canvas = self.iface.mapCanvas()
dlg2 = ShowDialog2()
build = canvas.layer(int(dlg2.Sel_Build_Layer.currentIndex()))
if int(dlg2.Sel_Build_Layer.currentIndex()) >= 0:
if not build.geomTypeDict == 2: # Types: 0:"point",1:"line",2:"polygon", Buildings layer has to be of type 2
QMessageBox.critical(self.iface.mainWindow(), ":-/ Selected buillding layer is not of type vector(polygon)! :-/" )
else:
build_fields = self.getFields(build)
dlg2.Sel_buildhight_field.clear()
dlg2.Sel_buildhight_field.addItems(build_fields)
"dlg2.Sel_buildhight_field" is the second QComboBox. I tried to connect it to the first ComboBox's (dlg2.Sel_Build_Layer) Signal by
QtCore.QObject.connect(dlg2.Sel_Build_Layer, QtCore.SIGNAL("currentIndexChanged"), self.build_Layer_Index_Changed())
but I get an error: "TypeError: build_Layer_Index_Changed() takes no arguments (1 given)". If I remove the brackets after self.build_Layer_Index_Changed, I get no eror, but the function is not called (as the MessageBox doesn't appear. I thought I did it exactly as given in the Example at http://techbase.kde.org/Development/Tutorials/Python_introduction_to_signals_and_slots, but obviously I'm doing something wrong…