ButtonBar.cxx
Go to the documentation of this file.
1 ///
2 /// \file ButtonBar.cxx
3 /// \brief The button bar at the top of every display window
4 /// \version $Id: ButtonBar.cxx,v 1.6 2012-03-03 06:48:11 messier Exp $
5 /// \author messier@indiana.edu
6 ///
8 #include <iostream>
9 #include <string>
10 #include <cstdlib>
11 // ROOT includes
12 #include "TTimer.h"
13 #include "TGFrame.h"
14 #include "TGButton.h"
15 #include "TGLayout.h"
16 #include "TGLabel.h"
17 #include "TGTextEntry.h"
18 #include "TGPicture.h"
19 #include "TGMsgBox.h"
20 // ART Framework includes
22 // Local includes
27 
28 namespace evdb{
29 
30  //......................................................................
31 
32  ButtonBar::ButtonBar(TGMainFrame* frame) :
33  fTimer(0)
34  {
35  fButtonBar = new TGCompositeFrame(frame, 60, 20,
36  kSunkenFrame|kHorizontalFrame);
37  fLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 1, 0);
38 
39  // Previous event button
40  fPrevEvt = new TGTextButton(fButtonBar, "<- Previous", 150);
41  fPrevEvt->SetToolTipText("Go to previous event");
42  fPrevEvt->Connect("Clicked()", "evdb::ButtonBar", this, "PrevEvt()");
43  fButtonBar->AddFrame(fPrevEvt,
44  new TGLayoutHints(kLHintsTop | kLHintsLeft,
45  2, 0, 2, 2));
46 
47  // Next event button
48  fNextEvt = new TGTextButton(fButtonBar, "Next ----->", 150);
49  fNextEvt->SetToolTipText("Go to next event");
50  fNextEvt->Connect("Clicked()", "evdb::ButtonBar", this, "NextEvt()");
51  fButtonBar->AddFrame(fNextEvt,
52  new TGLayoutHints(kLHintsTop | kLHintsLeft,
53  2, 0, 2, 2));
54 
55  // Auto advance button
56  fAutoAdvance = new TGTextButton(fButtonBar, ">", 150);
57  fAutoAdvance->SetToolTipText("Start auto advance");
58  fAutoAdvance->Connect("Clicked()", "evdb::ButtonBar", this, "AutoAdvance()");
59  fButtonBar->AddFrame(fAutoAdvance,
60  new TGLayoutHints(kLHintsTop | kLHintsLeft,
61  2, 0, 2, 2));
62 
63  // Reload button
64  fReload = new TGTextButton(fButtonBar, "Reload", 150);
65  fReload->SetToolTipText("Reload current event");
66  fReload->Connect("Clicked()", "evdb::ButtonBar", this, "ReloadEvt()");
67  fButtonBar->AddFrame(fReload,
68  new TGLayoutHints(kLHintsTop | kLHintsLeft,
69  2, 0, 2, 2));
70 
71  fCurrentFile = new TGTextEntry(fButtonBar, new TGTextBuffer(256));
72  fCurrentFile->SetToolTipText("Name of current file");
73  fCurrentFile->Resize(400, fCurrentFile->GetDefaultHeight());
74  fButtonBar->AddFrame(fCurrentFile,
75  new TGLayoutHints(kLHintsTop | kLHintsLeft,
76  8, 2, 2, 2));
77 
78  // Button to list attached files
79  const TGPicture* p = evdb::PicturePool()->GetPicture("arrow_down.xpm");
80  GContext_t norm = TGPictureButton::GetDefaultGC()();
81  fFileList = new TGPictureButton(fButtonBar, p, -1, norm, kRaisedFrame);
82  fFileList->SetToolTipText("List files");
83  fFileList->Connect("Clicked()", "evdb::ButtonBar", this, "FileList()");
84  fButtonBar->AddFrame(fFileList,
85  new TGLayoutHints(kLHintsCenterY,
86  2, 0, 2, 2));
87 
88  // Print button
89  fPrint = new TGTextButton(fButtonBar, "Print", 150);
90  fPrint->SetToolTipText("Print display to a file");
91  fPrint->Connect("Clicked()", "evdb::ButtonBar", this, "PrintToFile()");
92  fButtonBar->AddFrame(fPrint,
93  new TGLayoutHints(kLHintsTop|kLHintsRight,
94  2, 0, 2, 2));
95 
96  // Go To button
97  fGoTo = new TGTextButton(fButtonBar, "Go");
98  fGoTo->SetToolTipText("Go to event");
99  fGoTo->Connect("Clicked()", "evdb::ButtonBar", this, "GoTo()");
100  fButtonBar->AddFrame(fGoTo, new TGLayoutHints(kLHintsTop|kLHintsRight, 2, 0, 2, 2));
101 
102  // Go to event text entry
103  fEventTextEntry = new TGTextEntry(fButtonBar, new TGTextBuffer(128));
104  fEventTextEntry->Connect("ReturnPressed()","evdb::ButtonBar",this,"GoTo()");
105  fEventTextEntry->Resize(75,20);
106  fButtonBar->AddFrame(fEventTextEntry, new TGLayoutHints(kLHintsTop|kLHintsRight,2,0,2,2));
107 
108  fRunTextEntry = new TGTextEntry(fButtonBar, new TGTextBuffer(128));
109  fRunTextEntry->Connect("ReturnPressed()","evdb::ButtonBar",this,"GoTo()");
110  fRunTextEntry->Resize(50,20);
111  fButtonBar->AddFrame(fRunTextEntry, new TGLayoutHints(kLHintsCenterY|kLHintsRight,2,0,2,2));
112 
113  fRunEvtLabel = new TGLabel(fButtonBar, new TGHotString("[Run/Event]="));
114  fButtonBar->AddFrame(fRunEvtLabel, new TGLayoutHints(kLHintsCenterY|kLHintsRight,2,0,2,2));
115 
116  // Add button bar to frame
117  frame->AddFrame(fButtonBar, fLayout);
118  }
119 
120  //......................................................................
121 
123  {
124  if (fTimer) { delete fTimer; fTimer = 0; }
125 
127  delete fRunTextEntry; fRunTextEntry =0;
128  delete fRunEvtLabel; fRunEvtLabel =0;
129  delete fPrint; fPrint =0;
130  delete fGoTo; fGoTo =0;
131  delete fFileList; fFileList =0;
132  delete fCurrentFile; fCurrentFile =0;
133  delete fReload; fReload =0;
134  delete fNextEvt; fNextEvt =0;
135  delete fPrevEvt; fPrevEvt =0;
136  delete fLayout; fLayout =0;
137  delete fButtonBar; fButtonBar =0;
138  }
139 
140  //......................................................................
141 
143  {
145  }
146 
147  //......................................................................
148 
150  {
152  }
153 
154  //......................................................................
155 
156  ///
157  /// The timer sets the pace for the auto advance feature
158  ///
159  Bool_t ButtonBar::HandleTimer(TTimer* t)
160  {
161  this->NextEvt();
162 
164  t->SetTime(evd->fAutoAdvanceInterval);
165 
166  return kTRUE;
167  }
168 
169  //......................................................................
170 
172  {
173  if (fTimer==0) {
174  //
175  // Start the auto-advance feature
176  //
177  fAutoAdvance->SetText("X");
178  fTimer = new TTimer;
179  fTimer->SetObject(this);
180 
182  fTimer->Start(evd->fAutoAdvanceInterval);
183  }
184  else {
185  //
186  // Stop the auto-advance
187  //
188  fAutoAdvance->SetText(">");
189  fTimer->Stop();
190  delete fTimer;
191  fTimer = 0;
192  }
193  }
194 
195  //......................................................................
196 
198  {
200  }
201 
202  //......................................................................
203 
205  {
206  // int i;
207  // const char* f;
208  // for (i=0; (f=IoModule::Instance()->FileName(i)); ++i) {
209  // std::cerr << f << std::endl;
210  // }
211  }
212 
213  //......................................................................
214 
216 
217  //......................................................................
218 
220  {
221  int run = atoi(fRunTextEntry ->GetText());
222  int evt = atoi(fEventTextEntry->GetText());
223  NavState::SetTarget(run, evt);
225  }
226 
227  //......................................................................
228 
230  {
231  char runtxt[128];
232  char evttxt[128];
233 
234  sprintf(runtxt,"%d",run);
235  sprintf(evttxt,"%d",evt);
236  fRunTextEntry ->SetText(runtxt);
237  fEventTextEntry->SetText(evttxt);
238  }
239 
240  //......................................................................
241 
242  int ButtonBar::NoImpl(const char* method)
243  {
244  std::string s;
245  s = "Sorry action '"; s += method; s+= "' is not implemented.\n";
246  new TGMsgBox(evdb::TopWindow(), fButtonBar,
247  "No implementation",s.c_str(),kMBIconExclamation);
248  return 0;
249  }
250 
251 }// namespace
252 
253 ////////////////////////////////////////////////////////////////////////
TGTextButton * fNextEvt
Goto to next event.
Definition: ButtonBar.h:48
static void Set(int which)
Definition: NavState.cxx:24
void PrintToFile()
Definition: ButtonBar.cxx:215
TGPictureButton * fFileList
Access to the list of files attached.
Definition: ButtonBar.h:52
const char * p
Definition: xmltok.h:285
TGCompositeFrame * fButtonBar
The top button bar.
Definition: ButtonBar.h:45
unsigned int fAutoAdvanceInterval
Wait time in milliseconds.
Definition: EventDisplay.h:44
TGTextButton * fPrint
Print button.
Definition: ButtonBar.h:59
TGLayoutHints * fLayout
Layout for button bar.
Definition: ButtonBar.h:46
TGTextButton * fPrevEvt
Goto to previous event.
Definition: ButtonBar.h:47
Manage all things related to colors for the event display.
Definition: Display3DPad.h:11
TGTextButton * fAutoAdvance
Start to auto advance.
Definition: ButtonBar.h:49
Bool_t HandleTimer(TTimer *t)
Definition: ButtonBar.cxx:159
The interactive event display.
const XML_Char * s
Definition: expat.h:262
nova event display
TGTextButton * fGoTo
Go To event button.
Definition: ButtonBar.h:58
Pop up dialog for printing.
int evt
Definition: run.py:1
static void SetTarget(int run, int event)
Definition: NavState.cxx:39
TTimer * fTimer
Timer to handle auto advancing.
Definition: ButtonBar.h:42
const TGWindow * TopWindow()
Definition: evdb.cxx:12
A bar containing the next event and related buttons.
Float_t norm
TGTextButton * fReload
Reload current event.
Definition: ButtonBar.h:50
void SetRunEvent(int run, int event)
Definition: ButtonBar.cxx:229
TGPicturePool * PicturePool()
Definition: evdb.cxx:16
int NoImpl(const char *c)
Definition: ButtonBar.cxx:242
TGTextEntry * fEventTextEntry
Event number text entry.
Definition: ButtonBar.h:56
TGTextEntry * fRunTextEntry
Run number text entry.
Definition: ButtonBar.h:55
ButtonBar(TGMainFrame *frame)
Definition: ButtonBar.cxx:32
TGLabel * fRunEvtLabel
Run/Event number label.
Definition: ButtonBar.h:54
TGTextEntry * fCurrentFile
Currently loaded file.
Definition: ButtonBar.h:51
virtual ~ButtonBar()
Definition: ButtonBar.cxx:122
void AutoAdvance()
Definition: ButtonBar.cxx:171
enum BeamMode string