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
26{
27protected:
28 TGTextButton *fReset, *fExit;
29 TGTextViewostream *fTextView;
30 TGVerticalFrame *fContents;
31 TGHorizontalFrame *fButtons, *fCommandFrame;
32 TGTextEntry *fCommand;
33
34public:
35 TextViewMainFrame();
36 ~TextViewMainFrame() override {}
37 void Reset();
38 void HandleReturn();
39
40 ClassDefOverride(TextViewMainFrame, 0)
41};
42
43
44//______________________________________________________________________________
45TextViewMainFrame::TextViewMainFrame() : TGMainFrame(gClient->GetRoot())
46{
47 // Main test window.
48
49 SetCleanup(kDeepCleanup);
50
51 // Contents
52 fContents = new TGVerticalFrame(this);
53 fButtons = new TGHorizontalFrame(fContents);
54
55 // TextView
56 fTextView = new TGTextViewostream(fContents, 500, 300);
57 fContents->AddFrame(fTextView, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 0));
58
59 fCommandFrame = new TGHorizontalFrame(fContents);
60 fCommand = new TGTextEntry(fCommandFrame, (const char *)"", 20);
61 fCommand->Connect("ReturnPressed()", "TextViewMainFrame", this, "HandleReturn()");
62 fCommandFrame->AddFrame(new TGLabel(fCommandFrame, "Command: "),
63 new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 5, 5));
64 fCommandFrame->AddFrame(fCommand, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
65 fContents->AddFrame(fCommandFrame, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
66
67 // The button for test
68 fReset = new TGTextButton(fButtons, "&Reset");
69 fReset->SetToolTipText("Press to clear the command entry\nand the TGTextView", 200);
70 fReset->Connect("Clicked()", "TextViewMainFrame", this, "Reset()");
71 fButtons->AddFrame(fReset, new TGLayoutHints(kLHintsExpandX | kLHintsTop, 5, 5, 5, 5));
72
73 fExit = new TGTextButton(fButtons, "&Exit");
74 fExit->SetToolTipText("Terminate the application", 200);
75 fButtons->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX | kLHintsTop, 5, 5, 5, 5));
76 fExit->Connect("Pressed()", "TApplication", gApplication, "Terminate()");
77
78 fContents->AddFrame(fButtons, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 0, 0));
79 Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
80 DontCallClose();
81
82 AddFrame(fContents, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY));
84 Resize(GetDefaultSize());
85
86 SetWindowName("TGTextView Demo");
87 MapRaised();
88}
89
90//______________________________________________________________________________
91void TextViewMainFrame::Reset()
92{
93 fCommand->Clear();
94 fTextView->Clear();
95}
96
97//______________________________________________________________________________
98void TextViewMainFrame::HandleReturn()
99{
100 std::string line;
101 std::string command = fCommand->GetText();
102 *fTextView << gSystem->GetFromPipe(command.c_str()).Data() << std::endl;
103 fTextView->ShowBottom();
104 fCommand->Clear();
105}
106
107//______________________________________________________________________________
108void textviewostream()
109{
110 // Main program.
111
112 new TextViewMainFrame();
113}
114
115
#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