[PyQt] Re: Re: multiple signal connect

Ruben Fonseca rf at 7syntax.com
Sun Aug 24 19:18:31 BST 2008


On Thu, 2008-08-21 at 08:17 -0400, Daniel Miller wrote:
> FWIW, my second version was buggy too, so here's the third  
> attempt. I should probably refrain from posting untested code...
> 
> def make_slot(button):
>      def slot():
>          self.button_clicked(button)
>      button.__slot = slot
>      return slot # forgot this on the previous version
> 
> for button in [ ... ]:
>      QtCore.QObject.connect( ... , make_slot(button))
> 
> 
> ~ Daniel

I think I found a more elegant solution today! Using Python's partial
functions capabilities!

------

from functools import partial

for button in [self.button_1, self.button_2, ..., self.button_0]:
    QtCore.QObject.connect(button, QtCore.SIGNAL('clicked()'),
partial(self.button_clicked, button))

def button_clicked(self, button):
    print "yeah!"

------

It works great :)

Cheers
Ruben Fonseca
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080824/39ea40e9/attachment.bin


More information about the PyQt mailing list