Signals and slots
Python
One important aspect of adding a GUI to any code is that you must start thinking about events. Computations are easy from this point of view, either everything is serial or happens on a thread. With a GUI you must handle stuff like signals and slots.
Most of GUI libraries have some event handling primitives implemented, Qt uses signals and slots to connect events like pressing a button to a slot, that is, a function that is called when the event happens. I use Python to code GUIs so everything I'm saying from now on deals exclusively about Python.
A connection is a primitive that, needless to say, connects a signal to a slot. It has three arguments, the signal generator, the signal type and the slot. The slot is a function. More precisely a global function if you wan to avoid severe headaches trying to guess why your GUI is ignoring that function no matter how many times you press that button. There is a redundant question about this method. What can I do if I want to call a slot with arguments? A connection is between a signal and a function an there are no arguments present at any moment. I found an elegant solution this morning: use lambda functions in the connection calling. This will pre-eval the function with arguments and the connection won't see them.
Comentarios
En el prólogo del libro Matemáticas...
- jgpallero
- karma: 0
- jue 21 May 2009
One important aspect of adding a GUI to any code is that you must start thinking about events. Computations are easy from this point of view, either everything is serial or happens on a thread. With a GUI you must handle stuff like signals and slots.
Most of GUI libraries have some event handling primitives implemented, Qt uses signals and slots to connect events like pressing a button to a slot, that is, a function that is called when the event happens. I use Python to code GUIs so everything I'm saying from now on deals exclusively about Python.
A connection is a primitive that, needless to say, connects a signal to a slot. It has three arguments, the signal generator, the signal type and the slot. The slot is a function. More precisely a global function if you wan to avoid severe headaches trying to guess why your GUI is ignoring that function no matter how many times you press that button. There is a redundant question about this method. What can I do if I want to call a slot with arguments? A connection is between a signal and a function an there are no arguments present at any moment. I found an elegant solution this morning: use lambda functions in the connection calling. This will pre-eval the function with arguments and the connection won't see them.
Donde dices "Cuando tomé consciencia de ello..." creo que deberías poner "conciencia". No tengo ganas de poner el enlace a la RAE, que es un coñazo trucarlo para que la página no me lo eche para atrás.
@jgpallero
- guillem
- karma: 0
- lun 25 May 2009
fixed
