Code Refactoring for Signals and Slots
I have writing a UI using pyside. Problem is I have around 15 buttons in my application that when pushed open a dialog box and ask for a file or directory and then update a related lineEdit.
I have a askforfile() method which I like to associate with all these buttons. Unfortunately using the clicked.connect way of handling slots in PySide I have to write a new function for each button that would actually do the same thing.
So I tried to use lamba function in order to be able to pass the name of the lineEdit as a parameter of the askforfile() method. but I am getting error implementing this.
Could anybody please help me figure out what I am doing wrong ?
def __init__(self, parent=None): super(MainAppWindow, self).__init__() self.ui = Ui_MainWindow.Ui_MainWindow() self.ui.setupUi(self) self.ui.X_Vel_pushButton.clicked.connect(lambda name="X_Vel_lineEdit": self.askforfile(name)) def askforfile(self,currentLineEdit): curFileName=self.ui.currentLineEdit.text() (fileName, _selectedFilter) = QtGui.QFileDialog.getOpenFileName(self, filter="*.txt;;*.*",viewMode="Detail") if fileName!="" and fileName!=curFileName: self.ui.X_Vel_lineEdit.setText(fileName)
I am guessting something is wrong in my passing of currentLineEdit to askforfile().
I would appreciate any help.
Thanks in advance