Reputation: 5460
I have two buttons, which the user can click and will open a FileDiagloag to select a file. I need the user to select two files but I want one function to handle both button calls. So in my init I have:
QtCore.QObject.connect(self.ui.Button_SelectJoinFiles_1, QtCore.SIGNAL('clicked()'), self.SelectLogFileToJoin(1))
QtCore.QObject.connect(self.ui.Button_SelectJoinFiles_2, QtCore.SIGNAL('clicked()'), self.SelectLogFileToJoin(2))
And the function is basically something like:
def SelectLogFileToJoin(self, ButtonNum):
if(ButtonNum==1):
......
if(ButtonNum==2)
.....
But this doesn't work because when I start the program it start by giving me a file select dialog.
Could someone please tell me how to handle passing an argument to a callback function?
Upvotes: 0
Views: 609
Reputation: 89097
The issue here is you are passing the value returned by the function, not the function itself. To do what you want, you will want to use functools.partial()
to create a new function with pre-filled arguments:
from functools import partial
...
QtCore.QObject.connect(..., partial(self.SelectLogFileToJoin, 1))
Upvotes: 3