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)? 2 2448
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
On Sep 24, 4:47 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
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. ;) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kim |
last post by:
Hi everybody,
I tried to write simple FTP program using PyQt version 3.11. The
document say that QFtp has been implemented, but i keep getting error
message from my simple program :
My Program:...
|
by: Sibylle Koczian |
last post by:
Still trying to learn PyQt from a book about several Python GUI
toolkits, I seem to learn first what doesn't work. The following small
script seems to work, but after closing the window I get the...
|
by: Adrian Casey |
last post by:
I'm using a QTimer object to expire certain password protected GUI options
in my application after 2 minutes. Currently, the timer is reset each time
the user presses the 'OK' button. This is not...
|
by: Peter |
last post by:
I want to draw some lines on a widget.
This works ok, but when I want to redraw, the old lines are still there.
How do I clear or refresh the widget, so I can draw a new set of lines?
Code...
|
by: Flavio |
last post by:
Hi,
I have a QListview widget that allows me to store a bunch of strings in
it. This strings can be visualized, sorted, selected, etc.
My Problem is that I cant find a way to get the user...
|
by: Marcpp |
last post by:
Hi, I'm introducing to program in python + pyqt.
I have a main window that call a second window (to introduce a info
with textedit)
when press the second window button I need to return to the main...
|
by: Alexander Eisenhuth |
last post by:
Hello pyqt users,
i tried to use signal / slot across threads. With the following example I want
to emit a signal when the thread loop is entered. The connected slot is never
called. Why?
...
|
by: Markus Dahlbokum |
last post by:
Hello,
I'm trying to link python statically with qt and pyqt. I've tried this in
several ways but never succeeded. At the moment the final make runs without
errors but I get import errors when...
|
by: Alex Gusarov |
last post by:
Hello, I have strong .NET background with C# and want to do some
familiar things from it with Python, but don't know how. For example,
I created form in qt designer with QCalendarWidget, translated...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |