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

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to