cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a blocking message box in touchGFX?

zzzzz
Senior

We have an existing embedded application with older GUI which is being ported to TGFX. For keeping the old logic, we want to display a blocking message box and wait for user response (button click) in a widget callback(GUI button callback). The problem is that the tick is ignored during executing the callback and screen stop rendering. Is there anyway to keep the screen alive during executing widget callback?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

Oh, okay.

It should definitely not be necessary to do this. Is it possible to move this logic to a different task?

/Martin

View solution in original post

14 REPLIES 14
cameronf
Senior

In general, to avoid having the callback execution freeze your screen you can have the button callback set a flag or push a message to a queue that notifies something in another thread to call whatever you want executed when the button is pressed. Then that execution doesn't block the GUI thread from continuing to update/render the screen.

For your specific question though, are you saying you want the message popup to prevent the user from clicking on other parts of the screen or are you saying some other execution in your application should be blocked while that message is displayed?

zzzzz
Senior

Thanks for your reply. We want our application be blocked while message is displayed. Here is pseudo code:

widget callback handler

{

statement1;

response=MessageBox1(); //wait till button in message box 1 is clicked

statement2; //we want statement 2 to be executed only after Messagebox1 is closed

response=MessageBox2(); //wait till button in message box 2 is clicked

statement3; //we want statement 3 to be executed only after Messagebox2 is closed

etc...

}

cameronf
Senior

Gotcha, if I understand what you want to happen correctly:

  1. Push button on screen
  2. Sequence step 1 runs and finishes
  3. Message 1 pops up and waits for user to hit button to trigger next part of sequence
  4. Sequence step 2 runs
  5. ... and so on.

I would put the logic for this sequence in its own thread and be polling and pushing to message queues to coordinate triggering these popups and waiting for user input on the popups.

Could look like:

SequenceRunnerThread()
{
    WaitForWidgetButtonPress();
    Sequence1();
    ShowMessageBox1();
    WaitForMessageBoxNextButton();
    Sequence2();
    ShowMessageBox2();
    WaitForMessageBoxNextButton();
    ...
}

The "show message box" methods would push messages to a queue to notify the GUI to show the popup.

The "wait for" methods would loop and wait while polling a message queue that the GUI button callbacks would push a message to to let the sequence know the button has been pressed.

zzzzz
Senior

Thanks for the quick response. I understand this will make it work. But in our project there have hundred of places like the pseudo code and they have different logic. We don't want to create a thread for each place.

A simpler solution like this would work for us:

A message box that covers the whole screen and responds to buttons (OK, Cancel).

After a button on the message box is clicked, the message box is closed/hidden and the screen is redrawn.

Is it possible to implement a message box that way without using another thread?

Thank you in advance.

cameronf
Senior

If you don't mind the screen being frozen during execution, there may be a way to close the popup, manually invoke a redraw of the screen, and then execute your sequence out of the GUI thread. I have never done this in touchgfx so I'm not sure if there's a way to manually trigger a redraw.

Martin KJELDSEN
Chief III

Hi @zzzzz​,

Did you check out the ModalWindow Example through the designer yet? The view is alive and well and receiving ticks. You could also close it programatically from the presenter when receiving some message from the backend.

0690X000008vz9RQAQ.png

/Martin

zzzzz
Senior

Yes we did try modal window. Here is how we try using modal window to solve our problem

button callback handler(or any widget click callback handler)

{

statement1;

ShowMyModalwindow();//initialize modal window based on statement1, set widget visible and invalidate it.

while(check response from modalwindow);

statement2 ; // statement2 need date from statement1 and response from modalwindow to finish its logic.

}

The problem is that screen stop redrawing when execute callback handler, then the modal window cannot show up and we cannot click the button on it to quit while loop. We understand polling the response from tick will work. we are porting our project from old GUI to TGFX. We don't want change the logic too much. Is there any way that redraw the screen from the callback handler? Thanks.

Martin KJELDSEN
Chief III

Hi,

What are you executing in your callback so that you're not receiving any ticks? The entire graphical application is executed in the gui thread so if you have a method with a long execution time you're affecting your render time.

/Martin

zzzzz
Senior

Hi Martin

In our callback we want to open a message box, wait the user click button on it ,then handle the message box response. The callback need long execution time, for waiting user response. We are porting our old GUI project to TGFX, we do not want change this logic.

We figure out that screen will refresh if we keep calling the following functions in callback:

 touchgfx:: OSWrappers::waitForVSync();

 touchgfx::HAL:: getInstance()->backPorchExited();

These kind solve our problem. But we never find any TGFX documents mention about that. Is safe to call them in callback? If so, will these functions be changed in a new version? Thanks.