wx.wxMessageBox with lua question

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
gorf25
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon Aug 21, 2017 3:10 pm

wx.wxMessageBox with lua question

Postby gorf25 » Wed Nov 29, 2017 2:26 am

I have a button event that calls a function i have it running a stepper motor, and running though a loop till the motor reaches the distance it was told to travel. The GUI seems to lockup every time in the loop making a call to check the motor position.

But the strange thing is if i put a wx.wxMessageBox in the loop it runs fine the problem is, i have to keep hitting the enter key or the clicking the ok button, i can even leave the wx.wxMessageBox up without clicking it for a little while and the motor and position still keep moving once it reaches the end of loop it continues ok from there after i hit enter to close the wx.wxMessageBox.

Is there a way to simulate this without using a wx.wxMessageBox and having to hit enter or a button press in the loop?

So far anything other way i have tried seems lockup the GUI..

Thanks gary

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1754
Joined: Sun Jan 03, 2010 5:45 pm

Re: wx.wxMessageBox with lua question

Postby PB » Wed Nov 29, 2017 9:59 am

(I know nothing about lua, I am speaking from the viewpoint of a C++ programmer).

Well, if I understand it correctly, the application behaves as expected, if you enter a loop in the main thread, the message queue will not be processed and GUI becomes unresponsive.

wxMessageBox is probably implemented as a modal dialog which has its own message queue so it "works". But as it is application modal, the main program GUI still cannot be used, right?

The solution depends on the task, i.e., mostly on how long the task takes, if it is expected to be interruptible by the user, and whether the application is supposed to be used for doing other tasks while the motor is being repositioned. Depending on this, either a worker thread or a progress dialog updated within the loop should be used.

I do not think it could be possible to use wxTimer and move the motor in small steps in response to each timer event until the desired position is reached - if the call to move the motor is blocking and it takes more than a fraction of a second, the UI would probably become jumpy, not to mention that the motor might prefer to be moved from the starting to the desired position in a single step.

gorf25
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon Aug 21, 2017 3:10 pm

Re: wx.wxMessageBox with lua question

Postby gorf25 » Wed Nov 29, 2017 1:46 pm

Yes it behaves as expected as long as I have the wx.messagebox in the loop in the main thread there is a DRO that displays the distance being traveled while the motor is moving and that works also.

If I remove the wx.messagebox from the loop and call the function that reads the distance of current motor position the GUI locks up and the DRO stops showing the motor distance, some times after a minute or so, I assume it reached its travel distance the GUI frees unlocks, and the DRO will just jump from 0 to the entered distance it has traveled in stead of showing the movement on the DRO from 0 to entered distance at the motor speed.

if I add the wx.messagebox to the loop every thing works correct, but I don't want to have user input in the loop..

I don't think the motor will ever move in a single step most of the time depending on the stepper it would take an average of 1800 or so steps to move an inch I don't remember off the top to my head but I think it around 250 steps per 1 motor turn.

What do you think the wx.messagebox is doing that would make the loop and distance check work correctly but without it everything seems to lock up the then frees back up, I assume the loop is completed then, if I click anywhere in the program window I will get the message program not responding endless I have the wx.messagebox in the loop

Hope this makes more sense

Gary

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1754
Joined: Sun Jan 03, 2010 5:45 pm

Re: wx.wxMessageBox with lua question

Postby PB » Wed Nov 29, 2017 4:17 pm

I do not have much to add to what I wrote above.

In case you do not know, there is a bunch of *yield* methods in wxAppConsole and wxApp. You can look into this, I have never used them and TBH think these are kind of last resort hacks...

I still believe that a worker thread which notifies the main thread about the progress (or use a progress dialog and update it from within the loop if the application is to not do anything else anyway) is the best idea but I know nothing about wxLua or the actual communication with the device...

gorf25
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon Aug 21, 2017 3:10 pm

Re: wx.wxMessageBox with lua question

Postby gorf25 » Wed Nov 29, 2017 10:00 pm

Not sure yet if its working totally correct but I setup an timer event
i click a button that calls the function to move the motor
Then exit the function and turn on the timer that calls the function to check the distance motor has traveled
set timer to 1000 for now

Only tried it a couple times so far but seems to work no wx.messagebox and no user input also the DRO movers up correctly
So the timer event may be the way to go.


Thanks gary


Return to “General Development”

Who is online

Users browsing this forum: No registered users and 5 guests