wx.Timer blocks GUI

Hi All,

I want to make a GUI in which from start till finish a function is called continuously with a certain interval. For example the function will read some value from a text control, perform some calculation, update an image on a panel, and update a value on a text control. This function for the rest does not need to wait for any other function. I tried to achieve this by using wx.Timer. However, since my function is not fast, I see that when the function is being called that my GUI get non responsive. I have made an example program and put it as attachement. In the example I just add a time.sleep and I see the same effect. When my sleep time is small, I see that the program is responsive with no problem. The problem appears when the function takes a bit of time to finish. How can I solve this problem ? I don care that the function take some time, but I dont want it to block my GUI.

Thanks in advance for helping.

Pluto.

TestTimer.py (1.16 KB)

Pluto,
What you need do is called threading - i.e. Call your processing in
another task that generates the new values, ready for display - your
main program just handles the user input and the final display. Take
a look at the threads and delayed result samples from the Documents
and Demos package. Just remember - no GUI interaction (in or out)
from your background task(s).
Gadget/Steve

···

On 20/10/14 20:46, pluto mars wrote:

Hi All,

    I want to make a GUI in which from start till finish a function

is called continuously with a certain interval. For example the
function will read some value from a text control, perform some
calculation, update an image on a panel, and update a value on a
text control. This function for the rest does not need to wait
for any other function. I tried to achieve this by using
wx.Timer. However, since my function is not fast, I see that
when the function is being called that my GUI get non
responsive. I have made an example program and put it as
attachement. In the example I just add a time.sleep and I see
the same effect. When my sleep time is small, I see that the
program is responsive with no problem. The problem appears when
the function takes a bit of time to finish. How can I solve this
problem ? I don care that the function take some time, but I
dont want it to block my GUI.

    Thanks in advance for helping.



    Pluto.

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

Hi,
I saw the examples using post event to communicate back to the main thread when using threads to solve the problem. However how do I communicate to the thread that a value of a textctrl has change and thus when the thread continues to the next iteration that it should use other parameters to perform calculations.Because as said in my thread I keep on performing a certain task in an interval. Each time the task is perform I need to know if the user has change any inputs thru e.g. a text control. This input is needed by the thread to perform its task. So how do I communicate from the main thread the current inputs to the thread so that the thread can perform its task.

pluto

if you want to pass values from the thread before it is totally finished, then you need to use a thread-safe data object… such as a queue:
https://docs.python.org/2/library/queue.html

to update the main thread from your new thread, you can also use wx.CallAfter(self.someUpdateFunction, newValue) … where
def someUpdateFunction(self, newVal):

self.textctrl.SetValue(newVal)

···

On Monday, October 20, 2014 10:03:45 PM UTC-7, pluto mars wrote:

Hi,
I saw the examples using post event to communicate back to the main thread when using threads to solve the problem. However how do I communicate to the thread that a value of a textctrl has change and thus when the thread continues to the next iteration that it should use other parameters to perform calculations.Because as said in my thread I keep on performing a certain task in an interval. Each time the task is perform I need to know if the user has change any inputs thru e.g. a text control. This input is needed by the thread to perform its task. So how do I communicate from the main thread the current inputs to the thread so that the thread can perform its task.
pluto

Hi,
I saw the examples using post event to communicate back to the main thread when using threads to solve the problem. However how do I communicate to the thread that a value of a textctrl has change and thus when the thread continues to the next iteration that it should use other parameters to perform calculations.Because as said in my thread I keep on performing a certain task in an interval. Each time the task is perform I need to know if the user has change any inputs thru e.g. a text control. This input is needed by the thread to perform its task. So how do I communicate from the main thread the current inputs to the thread so that the thread can perform its task.

pluto

I wouldn't access any of the gui controls directly from the thread,
but the main thread could listen to changes to these gui elements and
update an object shared also by the thread. If it's a case of just
values changing (if the thread is reading-only) then you don't need to
do anything special. Queues or some other thread safe method seems
unnecessary here.

···

On 21 October 2014 06:03, pluto mars <plutomars955@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.