A simple example of entering CINT commands and having the CINT output in a ROOT GUI application window.
An editable combo box is used as a CINT prompt, a text view widget displays the command output.
#include <iostream>
#include <Getline.h>
class IDList {
private:
public:
IDList() : fID(0) {}
~IDList() {}
Int_t GetUnID(
void) {
return ++fID; }
};
private:
IDList fIDs;
public:
virtual ~MyApplication();
void DoExit();
void DoEnteredCommand();
};
{
Connect("CloseWindow()", "MyApplication", this, "DoExit()");
DontCallClose();
AddFrame(fOutlabel);
fComboCmd =
new TGComboBox(fHL2,
"", fIDs.GetUnID());
FILE *fhist = fopen(hist.Data(), "rt");
if (fhist) {
char histline[256];
while (fgets(histline, 256, fhist)) {
histline[strlen(histline)-1] = 0;
fComboCmd->InsertEntry(histline, 0, -1);
}
fclose(fhist);
}
gClient->GetColorByName(
"#c0c0c0", backpxl);
fExit->
Connect(
"Clicked()",
"MyApplication",
this,
"DoExit()");
SetWindowName("GUI with CINT Input/Output");
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
fCommand->
Connect(
"ReturnPressed()",
"MyApplication",
this,
"DoEnteredCommand()");
};
MyApplication::~MyApplication()
{
Cleanup();
}
void MyApplication::DoExit()
{
}
void MyApplication::DoEnteredCommand()
{
const char *command = fCommand->
GetTitle();
if (strlen(command)) {
prompt = ((
TRint*)
gROOT->GetApplication())->GetPrompt();
FILE *cintout = fopen(fName.
Data(),
"a+t");
if (cintout) {
fputs(
Form(
"%s%s\n",prompt.
Data(), command), cintout);
fclose(cintout);
}
gROOT->ProcessLine(command);
fComboCmd->InsertEntry(command, 0, fIDs.GetUnID());
Gl_histadd((char *)command);
fTextView->LoadFile(fName.
Data());
if (fTextView->ReturnLineCount() > 10)
fTextView->SetVsbPosition(fTextView->ReturnLineCount());
} else {
printf("No command entered\n");
}
fTextView->ShowBottom();
}
void guiWithCINT()
{
new MyApplication(
gClient->GetRoot(),600,300);
}
- Author
- Ilka Antcheva 06/07/2007
Definition in file guiWithCINT.C.