Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > (pyqt) Parameters when connecting a signal to a method?

Reply
Thread Tools

(pyqt) Parameters when connecting a signal to a method?

 
 
exhuma.twn
Guest
Posts: n/a
 
      09-24-2007
Some code:

----------------------------------------------------------------------

def foobar(w):
print w

QtCore.QObject,connect( my_line_edit,
QtCore.SIGNAL("returnPressed()"), foobar )

----------------------------------------------------------------------


How can I get this to work so "foobar" prints out the sender of the
signal (i.e. my_line_edit)?

 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      09-24-2007
exhuma.twn wrote:

> Some code:
>
> ----------------------------------------------------------------------
>
> def foobar(w):
> print w
>
> QtCore.QObject,connect( my_line_edit,
> QtCore.SIGNAL("returnPressed()"), foobar )
>
> ----------------------------------------------------------------------
>
>
> How can I get this to work so "foobar" prints out the sender of the
> signal (i.e. my_line_edit)?


I _think_ there is a way to get the signals sender in Qt itself. But I'm
unsure how to get that.

Alternatively, you can use a closure to create a reference:

def foobar(source, w):
print w

def slotgen(source, slot):
def _slot(*args):
return slot(*((source,) + args))
return _slot

my_slot = slotgen(my_line_edit, foobar)

QtCore.QObject,connect( my_line_edit,
QtCore.SIGNAL("returnPressed()"), my_slot )

However, be careful to keep a reference to my_slot around! Otherwise, it
will be garbage collected!

diez
 
Reply With Quote
 
 
 
 
exhuma.twn
Guest
Posts: n/a
 
      09-24-2007
On Sep 24, 4:47 pm, "Diez B. Roggisch" <(E-Mail Removed)> wrote:
> exhuma.twn wrote:
> > Some code:

>
> > ----------------------------------------------------------------------

>
> > def foobar(w):
> > print w

>
> > QtCore.QObject,connect( my_line_edit,
> > QtCore.SIGNAL("returnPressed()"), foobar )

>
> > ----------------------------------------------------------------------

>
> > How can I get this to work so "foobar" prints out the sender of the
> > signal (i.e. my_line_edit)?

>
> I _think_ there is a way to get the signals sender in Qt itself. But I'm
> unsure how to get that.
>
> Alternatively, you can use a closure to create a reference:
>
> def foobar(source, w):
> print w
>
> def slotgen(source, slot):
> def _slot(*args):
> return slot(*((source,) + args))
> return _slot
>
> my_slot = slotgen(my_line_edit, foobar)
>
> QtCore.QObject,connect( my_line_edit,
> QtCore.SIGNAL("returnPressed()"), my_slot )
>
> However, be careful to keep a reference to my_slot around! Otherwise, it
> will be garbage collected!
>
> diez


Thanks diez. This works
Although, I still have to digest *what* this closure does, but I will
leave this as an exercise to myself.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Target of signal assignment is not a signal" Nicolas Moreau VHDL 9 07-25-2007 04:21 PM
Re: How to make an internal signal embedded deep in hierarchy to a gloal output signal Weng Tianxiang VHDL 2 01-30-2007 12:58 PM
Aside from delta cycles and/or resolution functions, how can the effective value of a signal differ from a driving signal of its? Colin Paul Gloster VHDL 0 01-11-2007 01:31 PM
threading.Thread vs. signal.signal Jack Orenstein Python 0 09-17-2005 11:24 PM
Async-signal safe functions in signal handlers (unix) Michael Pronath Python 1 01-03-2005 01:10 PM



Advertisments