Does one create an event to notify parent window/GUI of something?

Michael Torrie torriem at gmail.com
Mon Mar 13 11:15:39 EDT 2017


On 03/13/2017 02:37 AM, Chris Green wrote:
> Michael Torrie <torriem at gmail.com> wrote:
>> On 03/12/2017 06:14 AM, Chris Green wrote:
>>> There are (of course) event handlers for the 'Save' and 'Cancel'
>>> button click events in abookeditgui, what I need is hooks from these
>>> to run some code in abookgui after the abookeditgui has completed. How
>>> should one do this, is there a way for a class to call code in the
>>> class 'above' which instantiated it?
>>
>> Sure.  Have the child object emit custom signal that your parent object
>> attaches to a callback.
>>
> Thanks, I guess this is probably the 'proper' event driven way to do
> it.  What I have actually done for the moment is to hand a function
> handle from the parent to the child so that the child can execute the
> code at the required time.

Sure.  What you are doing is perfectly acceptable and is a common
pattern.  Callbacks are potentially faster than signals and slots (to
use the Qt parlance) also.

Makes me wonder in what cases are signals and slots desired vs
callbacks. Async frameworks tend to use callbacks and they often chain
them up just like signals can be connected to multiple slots.  I suppose
one advantage of signals and lots is that you can get a handle to each
connection for disconnecting later, whereas with callback chains it's
pretty opaque once you set them up (say in Twisted or something similar).


More information about the Python-list mailing list