Logo ROOT  
Reference Guide
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();
virtual ~TextViewMainFrame() {}
void Reset();
void HandleReturn();
ClassDef(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));
MapSubwindows();
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();
}
Author
Bertrand Bellenot 06/01/2015

Definition in file textviewostream.C.

TGMainFrame
Definition: TGFrame.h:444
TString::Data
const char * Data() const
Definition: TString.h:369
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:40
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:37
TGLabel
Definition: TGLabel.h:32
TGTextButton
Definition: TGButton.h:142
TSystem::GetFromPipe
virtual TString GetFromPipe(const char *command)
Execute command and return output in TString.
Definition: TSystem.cxx:681
TGHorizontalFrame
Definition: TGFrame.h:423
gClient
#define gClient
Definition: TGClient.h:166
TApplication.h
TSystem.h
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:41
TGVerticalFrame
Definition: TGFrame.h:412
TGTextEntry
Definition: TGTextEntry.h:39
TGFrame.h
TGLayoutHints
Definition: TGLayout.h:57
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TGButtonGroup.h
kLHintsExpandY
@ kLHintsExpandY
Definition: TGLayout.h:44
line
TLine * line
Definition: entrylistblock_figure1.C:235
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
TGLabel.h
TGTextViewStream.h
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:51
TGTextViewostream
Definition: TGTextViewStream.h:53
TGNumberEntry.h
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102