496 views
in GUI Development by
Hi,

I have a GUI comprising of a stack of modal screens. I want to trigger an event when the modal screen above is closed.

UpdateViewState gets called but if I close multiple modal screens with a while loop I get issues with closed screens trying to perform actions (timers).

What I am trying to achieve is a idle timer to close modal screens back to a main screen if there is no user interaction for a period of time.

Thanks

Phil

1 Answer

0 votes
by
 
Best answer

Hello Phil,

your application case is very comon. When the timer expires, you close all modal screens by iterating them in a loop. Why it does not work in your case is difficult to say. Possibly, the closed screens are still existing and their timers are still running. Even if you end the modal state and remove the affected screen by calling the method Remove(), the screen component still existis until it has been reclaimed by the next garbage collection cycle. Should there be a valid reference to the affected screen component, then the component will even survive the garage collection and continue existing. Acordingly, if there are any active timers used in the affected screen components, the timer continue running.

What you can do:

Option 1: disable explicitly the timers as soon as the affected screen ends its modal state. You could handle this aspect in the UpdateViewState() method.

Option 2: When the timer expires, verify whether the affected component is still presented. You can e.g. evaluate the variable Owner of the component. Is it null, then the component is not displayed anymore. Other possibiity is to use the method HasViewState() with Core::ViewStat.Modal as parameter. If the method returns false, then the affected component is not modal anymore. In such case ignore the timer expiration.

Hope it helps you further.

Best regards

Paul Banach

by
Sorry Paul, I have not been very clear.

I can get all the screens to close with the while loop.

Where I have problems is if I want to only close the top screen, how would I then restart the timer for the screen below? Everything I have tried so far cannot distinguish between 1 screen being closed or all screens being closed as UpdateViewState() gets called for each screen during the while loop.
by

Hello Phil,

What I still don't understand is: "... so far cannot distinguish between 1 screen being closed or all screens being closed as UpdateViewState() gets called for each screen during the while loop."

If you close the top screen only, then the UpdateViewState() is called for this screen and the next below one. The method parameter aState determines the new state of the affected GUI component:

- The screen you end the modal state: UpdateViewState() is called and you can see in the parameter aState that it is not Modal anymore. This screen also looses the Focused state.

- The next screen in the modal stacking order: its UpdateViewState() is called and you can see in the parameter aState that it has now the Focused state.

Accordingly, all actually existing modal screens have the state Modal but only the top-most modal screen (the screen the user actually interacts with) has the state Focused. You could thus start the timer as soon as the component enters the Focused state and stop it again when it leaves this state.

Please see also : Common component states.

Does it help you further?

Best regards

Paul Banach

by
Thanks Paul, yes, checking the Focused state appears to give me what I need.

Great support as always!

Kind Regards

Phil

Embedded Wizard Website | Privacy Policy | Imprint

...