[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] Re: Re: multiple signal connect
From: Ruben Fonseca <rf () 7syntax ! com>
Date: 2008-08-24 18:18:31
Message-ID: 1219601906.30552.9.camel () replicator ! local
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
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
["signature.asc" (application/pgp-signature)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic