Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
textviewostream.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// This macro gives an example of how to use the TGTextViewostream widget.
4/// Simply type a command in the "Command" text entry, then the output is redirected to theTGTextViewostream.
5/// To run it do either:
6/// ~~~
7/// .x textviewostream.C
8/// .x textviewostream.C++
9/// ~~~
10///
11/// \macro_code
12///
13/// \author Bertrand Bellenot 06/01/2015
14
15#include "TGButton.h"
16#include "TGButtonGroup.h"
17#include "TGLabel.h"
18#include "TGNumberEntry.h"
19#include "TGTextViewStream.h"
20#include "TApplication.h"
21#include "TGFrame.h"
22#include "TSystem.h"
23
24////////////////////////////////////////////////////////////////////////////////
25class TextViewMainFrame : public TGMainFrame {
26protected:
27 TGTextButton *fReset, *fExit;
28 TGTextViewostream *fTextView;
29 TGVerticalFrame *fContents;
30 TGHorizontalFrame *fButtons, *fCommandFrame;
31 TGTextEntry *fCommand;
32
33public:
34 TextViewMainFrame();
35 ~TextViewMainFrame() override {}
36 void Reset();
37 void HandleReturn();
38
39 ClassDefOverride(TextViewMainFrame, 0)
40};
41
42//______________________________________________________________________________
43TextViewMainFrame::TextViewMainFrame() : TGMainFrame(gClient->GetRoot())
44{
45 // Main test window.
46
47 SetCleanup(kDeepCleanup);
48
49 // Contents
50 fContents = new TGVerticalFrame(this);
51 fButtons = new TGHorizontalFrame(fContents);
52
53 // TextView
54 fTextView = new TGTextViewostream(fContents, 500, 300);
55 fContents->AddFrame(fTextView, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 0));
56
57 fCommandFrame = new TGHorizontalFrame(fContents);
58 fCommand = new TGTextEntry(fCommandFrame, (const char *)"", 20);
59 fCommand->Connect("ReturnPressed()", "TextViewMainFrame", this, "HandleReturn()");
60 fCommandFrame->AddFrame(new TGLabel(fCommandFrame, "Command: "),
61 new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 5, 5));
62 fCommandFrame->AddFrame(fCommand, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
63 fContents->AddFrame(fCommandFrame, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
64
65 // The button for test
66 fReset = new TGTextButton(fButtons, "&Reset");
67 fReset->SetToolTipText("Press to clear the command entry\nand the TGTextView", 200);
68 fReset->Connect("Clicked()", "TextViewMainFrame", this, "Reset()");
69 fButtons->AddFrame(fReset, new TGLayoutHints(kLHintsExpandX | kLHintsTop, 5, 5, 5, 5));
70
71 fExit = new TGTextButton(fButtons, "&Exit");
72 fExit->SetToolTipText("Terminate the application", 200);
73 fButtons->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX | kLHintsTop, 5, 5, 5, 5));
74 fExit->Connect("Pressed()", "TApplication", gApplication, "Terminate()");
75
76 fContents->AddFrame(fButtons, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 0, 0));
77 Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
78 DontCallClose();
79
80 AddFrame(fContents, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY));
82 Resize(GetDefaultSize());
83
84 SetWindowName("TGTextView Demo");
85 MapRaised();
86}
87
88//______________________________________________________________________________
89void TextViewMainFrame::Reset()
90{
91 fCommand->Clear();
92 fTextView->Clear();
93}
94
95//______________________________________________________________________________
96void TextViewMainFrame::HandleReturn()
97{
98 std::string line;
99 std::string command = fCommand->GetText();
100 *fTextView << gSystem->GetFromPipe(command.c_str()).Data() << std::endl;
101 fTextView->ShowBottom();
102 fCommand->Clear();
103}
104
105//______________________________________________________________________________
106void textviewostream()
107{
108 // Main program.
109
110 new TextViewMainFrame();
111}
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
R__EXTERN TApplication * gApplication
#define gClient
Definition TGClient.h:157
@ 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:561
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