Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-24-2006, 08:15 AM
|
#1
|
|
Member
Registered: Apr 2006
Posts: 49
Rep:
|
[wxWidgets] how to unfroze the GUI while the event is running?
Hello, I have to make a very simple GUI for my C++ mathematical model.
Basically I just need a wxTextContr window that display the output of my model as it is produced.
The problem is that is is display at the end of the event call (when the model end, sometimes after hours), while I need it in real-time.
I am completelly new to GUI programming, so I think what I wrote is completelly ridicolous...
I would seriously appreciate on GUI programming strategies to improve my small GUI ;-).
This is what I wrote:
Code:
class
regmasapp : public wxApp
{
public:
virtual bool OnInit();
};
class
regmasFrame : public wxFrame
{
public:
void OnRun( wxCommandEvent& event );
wxTextCtrl* logAreaBox;
[...]
}
void
regmasFrame::OnRun( wxCommandEvent& WXUNUSED( event ) )
{
MainProgram* myProgram;
myProgram = new MainProgram( this);
myProgram->run();
}
class MainProgram{
private:
regmasFrame* GUI;
public:
MainProgram( regmasFrame* GUI_h);
~MainProgram();
void run();
};
and finally...
MainProgram::MainProgram(regmasFrame* GUI_h):GUI(GUI_h)
{
}
void
MainProgram::run(){
[...]
GUI->logAreaBox->AppendText(wxT("Stampa qualcosa\n"));
[...]
}
|
|
|
|
10-24-2006, 08:23 AM
|
#2
|
|
Member
Registered: Oct 2005
Posts: 970
Rep: 
|
If I understand you correctly then you are computing data which takes a long time; yet you want to display results as they happen rather than at the end of the computation.
Use two threads one for the gui and one for the computation, have data passing from the maths thread into a threadsafe queue and display the results in that thread.
This allows the gui to be responsive whilst still computing the data, tho I would give a higher priority to the the non gui thread.
Last edited by dmail; 10-24-2006 at 08:29 AM.
|
|
|
|
10-24-2006, 08:28 AM
|
#3
|
|
Member
Registered: Apr 2006
Posts: 49
Original Poster
Rep:
|
Quote:
|
Originally Posted by dmail
If I understand you correctly then you are computing data which takes a long time; yet you want to display results as they happen rather than at the end of the computation.
Use two threads one for the gui and one for the computation, have data passing from the maths thread into a threadsafe queue and display the results in that thread.
|
yes, that's correct.
Can you raccomand me a tutorial on this point?
(I was thinking that the thread division was just made automatically by wxWidgets when calling events)
|
|
|
|
10-24-2006, 08:32 AM
|
#4
|
|
Member
Registered: Oct 2005
Posts: 970
Rep: 
|
My knowledge of wxWidgets is very minimal(almost nothing lol), so you may be correct. If its a thread tutorial you are looking for then I would recommend Posix thread tut
|
|
|
|
10-24-2006, 09:09 AM
|
#5
|
|
Member
Registered: Apr 2006
Posts: 49
Original Poster
Rep:
|
Quote:
|
Originally Posted by dmail
My knowledge of wxWidgets is very minimal(almost nothing lol), so you may be correct. If its a thread tutorial you are looking for then I would recommend Posix thread tut
|
thanks.. I really think there is a "wxWay" to use threads in a wxWidget application, but yr generic tutorial is very nice (just too flashing banners on that site :-(( )
|
|
|
|
10-24-2006, 09:11 AM
|
#6
|
|
Senior Member
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065
Rep:
|
wxWidgets has a thread class you can use, wxThread.
iirc there is an entire chapter dedicated to threads in a book that is available for free from the prentice hall website. i cant think of the name of the book though..
|
|
|
|
10-24-2006, 09:31 AM
|
#7
|
|
Member
Registered: Apr 2006
Posts: 49
Original Poster
Rep:
|
Quote:
|
Originally Posted by xhi
wxWidgets has a thread class you can use, wxThread.
iirc there is an entire chapter dedicated to threads in a book that is available for free from the prentice hall website. i cant think of the name of the book though..
|
I suppose you mean "Cross-Platform GUI Programming with wxWidgets", but it doesn't look for free:
http://vig.prenhall.com/catalog/acad...473816,00.html
|
|
|
|
10-24-2006, 10:22 AM
|
#8
|
|
Member
Registered: Apr 2006
Posts: 49
Original Poster
Rep:
|
I am really, really lost on all of this.
here I read:
Quote:
|
Before starting an MT application (or starting to add MT features to an existing one) it is worth asking oneself if there is no easier and safer way to implement the same functionality. Of course, in some situations threads really make sense (classical example is a server application which launches a new thread for each new client), but in others it might be a very poor choice (example: launching a separate thread when doing a long computation to show a progress dialog). Other implementation choices are available: for the progress dialog example it is far better to do the calculations in the idle handler or even simply do everything at once but call wxWindow::Update() periodically to update the screen.
|
That's more or less my case... a long computation where I need just to display things sequentially. Yes, I would also like to use the capability to pause,resume,stop, but this isn't really so necessary.
|
|
|
|
10-24-2006, 11:24 AM
|
#9
|
|
Member
Registered: Oct 2005
Posts: 970
Rep: 
|
What that example does not taken into account is "when the model end, sometimes after hours", it just says long computation and you want it realtime.
Quote:
|
...it is far better to do the calculations in the idle handler ...
|
Which could be hours later.
Quote:
|
...or even simply do everything at once but call wxWindow::Update() periodically to update the screen.
|
...which cou...
I personally see this as the correct method to acheive what you want and is the way many guis work. Their comment I would see as a word of warning that everything may not go as you wish, if you don't have an understanding of threads and the benefits they do or do not give.
On the other hand if you do not want to use threads, then you would have to stop the computation at some point to display results and then continue...
If it was to be run on a dual core cpu, I would try splitting the computation into threads
[edit]misread the comment about wxWindow::Update().
This is an option.
Last edited by dmail; 10-24-2006 at 11:41 AM.
|
|
|
|
10-24-2006, 11:45 AM
|
#10
|
|
Senior Member
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065
Rep:
|
Quote:
|
Originally Posted by sylvaticus
|
yeh it is but not from the normal pren hall website.. look for it on here.
|
|
|
|
10-24-2006, 02:57 PM
|
#11
|
|
Member
Registered: Apr 2006
Posts: 49
Original Poster
Rep:
|
thanks all.. I have found the book (in PDF) and I am going to learn threads..
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:15 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|