Discussion:
wx.Timer blocks GUI
pluto mars
2014-10-20 19:46:33 UTC
Permalink
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Steve Barnes
2014-10-20 20:21:38 UTC
Permalink
Post by pluto mars
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
For more options, visit https://groups.google.com/d/optout.
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
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
pluto mars
2014-10-21 05:03:45 UTC
Permalink
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
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-10-21 07:54:00 UTC
Permalink
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)
Post by pluto mars
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
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Paul Wiseman
2014-10-21 09:25:08 UTC
Permalink
Post by pluto mars
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.
Post by pluto mars
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...