GUI command prompt

Hi Jen,

You can take a look at the gui/gui/src/TGCommandPlugin.cxx source file, it is the command plugin used by the ROOT browser.

Cheers, Bertrand.

Ah, okay. I will take a look at that. Thank you very much!

You’re very welcome! And just let me know if you have any problem.

Cheers, Bertrand.

Hi Bertrand,

I’m still trying to figure out how to do this. I looked at the TGCommandPlugin class and found the HandleCommand function. I’m working on using this code as a model where const char *string is assigned the contents of cout. Is this close to a correct approach?

Thank you,
Jen

Hi,

OK, here is an example of how to get the result of a command in a TGTextView:

std::string line; std::istringstream iss(gSystem->GetFromPipe(command).Data()); while (std::getline(iss, line)) { fTextView->AddLine(line.c_str()); } fTextView->ShowBottom();
You can also redirect the output to a file (as it is done in TGCommandPlugin.cxx). Here is a simplified example:

gSystem->RedirectOutput(filename, "a"); gROOT->ProcessLine(command); gSystem->RedirectOutput(0); fTextView->LoadFile(filename);
Cheers, Bertrand

And here is a complete, running example:
test_textview.C (3.31 KB)
Cheers, Bertrand.

Thank you very much! I really appreciate the help. As you can probably tell, I’m rather new to root and having to relearn my C++ skills.

For the macro file you provided, do I download the TGTextViewStream.h file from this thread?

Hi,

No, it works without any other need that ROOT itself. Just start ROOT and execute it

Cheers, Bertrand.

Hi Bertrand,

I’m getting an error message saying “cannot open file ‘TGTextViewStream.h’”. I’m in the directory where I’ve run all the other root tutorials so I don’t think any paths should be a problem, but I may be missing something. Any advice?

Thanks,
Jen

Ooops! Yes, stupid me, please replace

#include "TGTextViewStream.h" by

#include "TGTextView.h" I also modified the original file. Sorry about that.

Cheers, Bertrand

No problem! Thank you. It works now. :smiley:

I have another related question: Is there a way to print cout statements from cxx files to the text viewer by a means other than rewriting every cout statement with a TGTextView AddLine() function? Or is this possible with the example code provided, and I just don’t see it.

Thanks again.

[quote=“jito”]No problem! Thank you. It works now.[/quote]You’re welcome

[quote=“jito”]Is there a way to print cout statements from cxx files to the text viewer by a means other than rewriting every cout statement with a TGTextView AddLine() function?[/quote]Nope. You have to add it explicitly with AddLine()…

Cheers, Bertrand.

Okay, thank you.

The project that I’m working on has a large amount of coded cout statements that I would like to print out in a text box in my GUI. I’ve attached a macro showing a simple example of code just for clarity’s sake. I’d really prefer to not have to rewrite all the cout statements so is there any other way I can print these statements to a text viewer?

Thanks again. I really appreciate all your help.
cout_example.C (166 Bytes)

gSystem->RedirectOutput("test_cout.txt", "a"); cout << "Hello! I'm wondering if there is any other way to print this statement to a text box that I would display in my GUI." << endl; gSystem->RedirectOutput(0); fTextView->LoadFile("test_cout.txt");

Thank you very much! I was able to implement it in a way that it does what I was hoping for.

My apologies. As I kept working on my project, I discovered that I’m still not able to do exactly what I’m hoping for. I would like to redirect the standard output to a view box such that the box updates in real time.
In my project, there are standard output statements in external executables/functions whose code I do not have access to. Because of this, I cannot use AddLine and I cannot Update the view box or reload the file after every cout statement which means I have to wait for the executable/function to complete before I see any output in the TGTextView box. This is a problem because I need to see the cout statements in real time to look for error messages that might arise while running the external executables/functions.

I’m guessing there is no other workaround, correct?
I also saw a project proposal for redirecting standard output to TGTextView. Is there a timeline available for that?

Thank you!

Hi,

Well, I think there is a misunderstanding here. If you don’t have control of the other application, then I don’t see how you can redirect its stdout… and the project proposal you’re referring to is to redirect ostream to TGTextView (e.g. make a class inheriting from both TGTextView and ostream), and it would not solve the problem with other applications…

Cheers, Bertrand.

Hello,

My apologies again. I will try to clarify. I would like to have any printf or cout statement print to a text box in real time. The solution you gave me earlier (redirecting to a text file) partially works because it takes any printf or cout statement and prints it to the TGTextView. The issue I discovered is that it does not print in real time. For example:

gSystem->RedirectOutput("textfile.txt", "a"); for (int i = 0; i < 8; i++) { cout << "Round " << i << endl; } fTextView->LoadFile(textfile.txt);
This text box will only display the cout statements after the for loop has completed. I would like the text box to show each cout statement as it is executed. I hope the nuance makes sense. Thank you again.

Hi,

So yes, in this case, you can create a class inheriting from TGTextView and std::ostream. But I think you would still have to replace all your calls to cout << "Round " << i << endl; with something like: *fTextViewOStream << "Round " << i << endl;
Cheers, Bertrand

Okay, thank you. I will explore that though unfortunately it may still not work if I have to replace the cout statements. I apologize for the confusion and thank you for your patience. :smiley: