hello again,
I was trying to make my application multithreaded, I put my calculations in different Thread, then I gave this Thread name of the function to call when it finish.
This function updates ListCtrl.
So it works this way:
- ListCtrl has old values
- I want to add new element, it requires calculations
- I call different thread and give it reference to Update() function
- I do different things while thread does its calculations
- thread finishes calculations and calls Update()
- Update() regenerates data in ListCtrl
The problem is, that my GUI is unstable after last step. ListCtrl is not updated until I use scroll, then it updates, but I can’t click anything else in the wxPython window.
Can I use threads this way when developing wxPython application?
If not, how can I update ListCtrl when another Thread finish its job?
···
–
Free Software - find interesting programs and change them
NetHack - meet interesting creatures, kill them and eat their bodies
Usenet - meet interesting people from all over the world and flame them
Decopter - unrealistic helicopter simulator, get it from http://decopter.sf.net
Jacek Poplawski wrote:
hello again,
I was trying to make my application multithreaded, I put my calculations in different Thread, then I gave this Thread name of the function to call when it finish.
This function updates ListCtrl.
So it works this way:
- ListCtrl has old values
- I want to add new element, it requires calculations
- I call different thread and give it reference to Update() function
- I do different things while thread does its calculations
- thread finishes calculations and calls Update()
- Update() regenerates data in ListCtrl
The problem is, that my GUI is unstable after last step. ListCtrl is not updated until I use scroll, then it updates, but I can't click anything else in the wxPython window.
Hi Jacek,
From the "wxPython in Action": the GUI bit is not threadsafe. You should not call any function of the GUI from a thread. Any GUI function can *only* be called from the main thread or you will have trouble. And it will be hard to diagnose.
As soon as you call update() from your thread, the update-function runs in the thread and the GUI becomes unstable. Dont.
I suppose you could use Queue objects, but I have no experience doing so.
What you would do is: post to the queue from the thread and read from the queue from the main thread. Does that make any sense?
Guus.
···
--
A.J. Bonnema, Leiden The Netherlands,
user #328198 (Linux Counter http://counter.li.org)
Jacek Poplawski escribió:
hello again,
I was trying to make my application multithreaded, I put my calculations
in different Thread, then I gave this Thread name of the function to
call when it finish.
This function updates ListCtrl.
So it works this way:
- ListCtrl has old values
- I want to add new element, it requires calculations
- I call different thread and give it reference to Update() function
- I do different things while thread does its calculations
- thread finishes calculations and calls Update()
- Update() regenerates data in ListCtrl
The problem is, that my GUI is unstable after last step. ListCtrl is not
updated until I use scroll, then it updates, but I can't click anything
else in the wxPython window.
you can tell the mainloop to schedule a call from a non-thread via
wx.CallAfter:
wx.CallAfter(the_list.Update, arg1, arg2)
···
Can I use threads this way when developing wxPython application?
If not, how can I update ListCtrl when another Thread finish its job?
--
Free Software - find interesting programs and change them
NetHack - meet interesting creatures, kill them and eat their bodies
Usenet - meet interesting people from all over the world and flame them
Decopter - unrealistic helicopter simulator, get it from
http://decopter.sf.net