Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
textviewostream.C File Reference

Detailed Description

This macro gives an example of how to use the TGTextViewostream widget.

Simply type a command in the "Command" text entry, then the output is redirected to theTGTextViewostream. To run it do either:

.x textviewostream.C
.x textviewostream.C++
#include "TGButton.h"
#include "TGButtonGroup.h"
#include "TGLabel.h"
#include "TGNumberEntry.h"
#include "TApplication.h"
#include "TGFrame.h"
#include "TSystem.h"
////////////////////////////////////////////////////////////////////////////////
class TextViewMainFrame : public TGMainFrame
{
protected:
TGTextButton *fReset, *fExit;
TGTextViewostream *fTextView;
TGVerticalFrame *fContents;
TGHorizontalFrame *fButtons, *fCommandFrame;
TGTextEntry *fCommand;
public:
TextViewMainFrame();
~TextViewMainFrame() override {}
void Reset();
void HandleReturn();
ClassDefOverride(TextViewMainFrame, 0)
};
//______________________________________________________________________________
TextViewMainFrame::TextViewMainFrame() : TGMainFrame(gClient->GetRoot())
{
// Main test window.
SetCleanup(kDeepCleanup);
// Contents
fContents = new TGVerticalFrame(this);
fButtons = new TGHorizontalFrame(fContents);
// TextView
fTextView = new TGTextViewostream(fContents, 500, 300);
fContents->AddFrame(fTextView, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 0));
fCommandFrame = new TGHorizontalFrame(fContents);
fCommand = new TGTextEntry(fCommandFrame, (const char *)"", 20);
fCommand->Connect("ReturnPressed()", "TextViewMainFrame", this, "HandleReturn()");
fCommandFrame->AddFrame(new TGLabel(fCommandFrame, "Command: "),
fCommandFrame->AddFrame(fCommand, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
fContents->AddFrame(fCommandFrame, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
// The button for test
fReset = new TGTextButton(fButtons, "&Reset");
fReset->SetToolTipText("Press to clear the command entry\nand the TGTextView", 200);
fReset->Connect("Clicked()", "TextViewMainFrame", this, "Reset()");
fButtons->AddFrame(fReset, new TGLayoutHints(kLHintsExpandX | kLHintsTop, 5, 5, 5, 5));
fExit = new TGTextButton(fButtons, "&Exit");
fExit->SetToolTipText("Terminate the application", 200);
fButtons->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX | kLHintsTop, 5, 5, 5, 5));
fExit->Connect("Pressed()", "TApplication", gApplication, "Terminate()");
fContents->AddFrame(fButtons, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 0, 0));
Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
DontCallClose();
AddFrame(fContents, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY));
Resize(GetDefaultSize());
SetWindowName("TGTextView Demo");
MapRaised();
}
//______________________________________________________________________________
void TextViewMainFrame::Reset()
{
fCommand->Clear();
fTextView->Clear();
}
//______________________________________________________________________________
void TextViewMainFrame::HandleReturn()
{
std::string line;
std::string command = fCommand->GetText();
*fTextView << gSystem->GetFromPipe(command.c_str()).Data() << std::endl;
fTextView->ShowBottom();
fCommand->Clear();
}
//______________________________________________________________________________
void textviewostream()
{
// Main program.
new TextViewMainFrame();
}
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
R__EXTERN TApplication * gApplication
#define gClient
Definition TGClient.h:156
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
A composite frame that layout their children in vertical way.
Definition TGFrame.h:374
const char * Data() const
Definition TString.h:376
virtual TString GetFromPipe(const char *command)
Execute command and return output in TString.
Definition TSystem.cxx:680
TLine * line
Author
Bertrand Bellenot 06/01/2015

Definition in file textviewostream.C.