The Slot Notifier

Suppose that you have an application where there are two forms that show the same data (or the dame data but presented in a different way) and that you want to arrange that when the user updates data through one form, the corresponding changes appear in the second form. For instance, you might have a workshop booking form, where bookings are made on the basis of some number of hours on a particular day, and a diary form, which shows a per-day summary of the hours booked.

Arranging that changes made in the booking form are reflected in the diary could be managed by creating a script module where the diary registers its presence (eg., by setting a variable to point to its form object) and which is called from the bookings form whenever a change is made. This would work, but there would be complications; the diary form would have to unregister itself when it closes, and the code called from the booking form would have to check whether the diary was open. Plenty of scope for error!

This can be simplified using the slot notifier mechanism. The slot notifier mechanism allows you to register slots with the notifier, and to invoke them from elsewhere.

For the above example, you would create a slot in the form level. The slot if linked to a notional object getNotifier() (with that exact spelling, case and no spaces) and event, say updated_workshoplog. getNotifier() simply tells Rekall to connect the slot to the notifier. updated_workshoplog is a name which we will use below. The slot function might simply reload the form:

def slotFunc (form, sender, event, *args) :
    form.reload ()
      

Now we need to trigger the slot. This is done in the bookings form. We might have a Save button that saves changes, in which case the OnClick event function for this button would now look like:

def eventFunc (button) :
    #
    # Save code ...
    #
    button.notify ("updated_workshoplog")
      

The event function first does whatever it needs to save the user's changes. It then calls the notify method (which is available on all objects, not just buttons). The first argument to this identifies the slot to be triggered; the button itself becomes the sender argument to the slot, updated_workshoplog is the third argument, and any other arguments to notify become the remaining arguments to the slot function.

The notification goes to all slots that were registered with the slot notifier with the specified name, so you can trigger multiple slots with one call. If there are no slots registered with that name, nothing happens, so you need not check if the diary form is open. And, if the diary form is closed (or is switched into design mode) then the slot registration is cancelled. Hence, you do not need to worry about whether forms are opened or closed.