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());
fCommand = fComboCmd->GetTextEntry();
fComboCmd->Resize(450, fCommand->GetDefaultHeight());
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);
fTextView->SetBackground(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());
fCommand->Clear();
} else {
printf("No command entered\n");
}
fTextView->ShowBottom();
}
void guiWithCINT()
{
new MyApplication(
gClient->GetRoot(),600,300);
}
ULong_t Pixel_t
Pixel value.
#define ClassDef(name, id)
R__EXTERN TApplication * gApplication
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
const char * Data() const
virtual Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=nullptr)
Redirect standard output (stdout, stderr) to the specified file.
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
virtual const char * WorkingDirectory()
Return working directory.
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
virtual int Unlink(const char *name)
Unlink, i.e.