An editable combo box is used as a CLING 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:
TGTextButton *fExit;
IDList fIDs;
TGComboBox *fComboCmd;
TGTextBuffer *fCommandBuf;
TGTextEntry *fCommand;
TGTextView *fTextView;
TString fName;
public:
~MyApplication() override;
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 CLING Input/Output");
Resize(GetDefaultSize());
MapWindow();
fCommand->Connect("ReturnPressed()", "MyApplication", this, "DoEnteredCommand()");
fName =
Form(
"%soutput.log",
gSystem->WorkingDirectory());
};
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);
}
gSystem->RedirectOutput(fName.Data(),
"a");
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 guiWithCLING()
{
new MyApplication(
gClient->GetRoot(),600,300);
}
ULong_t Pixel_t
Pixel value.
#define ClassDefOverride(name, id)
R__EXTERN TApplication * gApplication
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void w
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
R__EXTERN TSystem * gSystem
A combobox (also known as a drop down listbox) allows the selection of one item out of a list of item...
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
A composite frame that layout their children in horizontal way.
This class handles GUI labels.
This class describes layout hints used by the layout classes.
Defines top level windows that interact with the system Window Manager.
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
Yield an action as soon as it is clicked.
A TGTextView is a text viewer widget.
ROOT GUI Window base class.
const char * Data() const