If you need to perform any actions just before the window closes, connect the aboutToCloseWidget event of the Window part to an action in your part.
If you need to perform any actions just before the window opens, connect the aboutToOpenWidget event of the Window part to an action in your part.