GUI command prompt

Hello,

I am currently building a GUI and would like to have a window that displays standard output commands. Is there a class I can utilize to do this or should I turn all my standard output commands to file output commands and display the text file? Any insight is greatly appreciated.

Thank you!

Hi,

You can pipe the standard output to a TGTextView, as it is done in the TBrowser

Cheers, Bertrand.

Hi Bertrand,

Thank you for your quick response.
I’m sorry, but I’m still unsure how to do this. Is there a function in TGTextView that will do it directly? Also, I tried looking at TBrowser.cxx to see how it’s done in TBrowser, but I wasn’t able to find that section of code. Did I just overlook it or am I looking in the wrong place?

Thank you,
Jen

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.