source: branches/start/MagicSoft/Mars/mgui/MGDataCheckMain.cc@ 8593

Last change on this file since 8593 was 461, checked in by harald, 24 years ago
Starting the subdir for the gui Graphical user interfaces.
  • Property svn:executable set to *
File size: 12.2 KB
Line 
1#include "MGDataCheckMain.h"
2
3#include <TSystem.h> // gSystem
4
5#include <TGTab.h> // TGTab
6#include <TGMenu.h> // TGPopupMenu
7#include <TGButton.h> // TGTextButton
8#include <TGMsgBox.h> // TGMsgBox
9#include <TGListBox.h> // TGListBox
10#include <TGFSContainer.h> // TGFileContainer
11
12// FIXME: Move to MAGIC.h
13#define S_ISDIR(m) (((m)&(0170000)) == (0040000))
14
15ClassImp(MGDataCheckMain)
16
17MGDataCheckMain::MGDataCheckMain(const TGWindow *p, const TGWindow *main,
18 UInt_t w, UInt_t h )
19 : TGTransientFrame(p, main, w, h )
20{
21 //
22 // Main window to controll the october test
23 //
24
25 // set non-gui members to starting values
26
27 sprintf ( fInputFile, "\n" ) ;
28
29 //
30 // First create the MenuBar.
31 //
32
33 // Layout objects for menue.
34
35 fLayMenuBar = new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) ;
36 fLayMenuItem = new TGLayoutHints ( kLHintsTop | kLHintsLeft , 0, 4, 0, 0 ) ;
37
38 // crate the menu bar
39
40 fFileMenu = new TGPopupMenu ( fClient->GetRoot() ) ;
41 fFileMenu->AddEntry ("Close", M_FILE_CLOSE ) ;
42 fFileMenu->Associate(this) ;
43
44 // the button messages are handled by main frame (this)
45
46 fMenuBar = new TGMenuBar ( this, 1, 1, kHorizontalFrame ) ;
47 fMenuBar->AddPopup("File", fFileMenu, fLayMenuItem ) ;
48 AddFrame(fMenuBar, fLayMenuBar ) ;
49
50 //
51 // Create the top window with a lot of buttons
52 //
53
54 fFrameTop = new TGCompositeFrame (this, 300,100, kVerticalFrame ) ;
55
56 fTop1 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
57
58 fFrameTop->AddFrame (fTop1, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
59
60 fTop2 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
61
62 fButPedADC = new TGTextButton(fTop2, "ADC Spectra of Pedestals", M_BUTTON_PEDADC );
63 fButPedADC->Associate(this) ;
64 fTop2->AddFrame (fButPedADC, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 10, 5, 5) );
65
66 fButCrADC = new TGTextButton(fTop2, "ADC Specta of Cosmics", M_BUTTON_CRADC );
67 fButCrADC->Associate(this) ;
68 fTop2->AddFrame (fButCrADC, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 10, 5, 5) );
69
70 fFrameTop->AddFrame (fTop2, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
71
72 fTop3 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
73
74 fButPedTDC = new TGTextButton(fTop3, "TDC Spectra of Pedestals", M_BUTTON_PEDTDC );
75 fButPedTDC->Associate(this) ;
76 fTop3->AddFrame (fButPedTDC, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 10, 5, 5) );
77
78 fButCrTDC = new TGTextButton(fTop3, "TDC Specta of Cosmics", M_BUTTON_CRTDC );
79 fButCrTDC->Associate(this) ;
80 fTop3->AddFrame (fButCrTDC, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 10, 5, 5) );
81
82 fFrameTop->AddFrame (fTop3, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
83
84 AddFrame(fFrameTop, new TGLayoutHints (kLHintsTop ) ) ;
85
86
87 //
88 // Create the low window with a tabs in it
89 //
90
91 fFrameLow = new TGCompositeFrame (this, 300,100, kHorizontalFrame ) ;
92
93 fLayTab = new TGLayoutHints ( kLHintsExpandX , 5, 5, 5, 5 ) ;
94
95 // create the first tab
96
97 fTab = new TGTab ( fFrameLow, 400, 400 ) ;
98
99 TGCompositeFrame *tf = fTab->AddTab("Input File") ;
100
101 fTabF1 = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
102 // tf->AddFrame(fTabF1, fLayTab ) ;
103
104
105 fTabF1a = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
106 tf->AddFrame(fTabF1a, new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
107
108 fTabF1b = new TGCompositeFrame (tf, 100, 100, kVerticalFrame) ;
109 // tf->AddFrame(fTabF1b, new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 5, 5, 5, 5 ) ) ;
110 tf->AddFrame(fTabF1b, new TGLayoutHints ( kLHintsExpandX | kLHintsExpandY , 5, 5, 5, 5 ) ) ;
111
112
113 fDir = new TGListBox(fTabF1a, -1) ;
114 fDir->Resize(350,20) ;
115 char temp[100] ;
116 // sprintf ( temp, "%s", START_DIRECTORY ) ;
117 sprintf ( temp, "%s", gSystem->WorkingDirectory() ) ;
118 fDir->AddEntry(temp, 1) ;
119 fTabF1a->AddFrame( fDir, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
120
121
122 fPicCdup = fClient->GetPicture("tb_uplevel.xpm") ;
123 fCdup = new TGPictureButton(fTabF1a, fPicCdup, M_PBUTTON_CDIR_UP ) ;
124 fCdup->SetToolTipText("One Level up!") ;
125 fCdup->Associate(this) ;
126 fTabF1a->AddFrame (fCdup, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
127
128 fPicList = fClient->GetPicture("tb_list.xpm") ;
129 fListMode = new TGPictureButton(fTabF1a, fPicList, M_PBUTTON_LIST_MODE ) ;
130 fListMode->SetToolTipText("List Mode") ;
131 fListMode->Associate(this) ;
132 fListMode->SetState(kButtonUp) ;
133 fListMode->AllowStayDown(kTRUE) ;
134 fListMode->AllowStayDown(kTRUE) ; fTabF1a->AddFrame (fListMode, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
135
136 fPicDetail = fClient->GetPicture("tb_details.xpm") ;
137 fDetail = new TGPictureButton(fTabF1a, fPicDetail, M_PBUTTON_DETAIL_MODE ) ;
138 fDetail->SetToolTipText("Details Mode") ;
139 fDetail->Associate(this) ;
140 fDetail->SetState(kButtonEngaged) ;
141 fDetail->AllowStayDown(kTRUE) ;
142 fTabF1a->AddFrame (fDetail, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
143
144
145 fFileView = new TGListView(fTabF1b, 540, 380 ) ;
146 fFileCont = new TGFileContainer(fFileView->GetViewPort(), 100, 100,
147 kVerticalFrame, fgWhitePixel) ;
148
149 fFileCont->Associate(this) ;
150 fFileView->GetViewPort()->SetBackgroundColor(fgWhitePixel) ;
151 fFileView->SetContainer(fFileCont) ;
152 fFileCont->SetFilter("*") ;
153 // fFileCont->ChangeDirectory(START_DIRECTORY) ;
154 fFileCont->ChangeDirectory(gSystem->WorkingDirectory()) ;
155 fFileView->SetViewMode(kLVDetails);
156 fFileCont->Sort(kSortByName) ;
157
158 fTabF1b->AddFrame(fFileView, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5) ) ;
159
160 tf->AddFrame(fTabF1, fLayTab) ;
161
162 fFrameLow->AddFrame ( fTab, new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) );
163
164 AddFrame(fFrameLow, new TGLayoutHints (kLHintsExpandX|kLHintsExpandY) ) ;
165
166 //
167 // Map the window, set up the layout, etc.
168 //
169
170 SetWMSizeHints(400, 650, 1000, 1000, 10, 10 ) ; // set the smallest and biggest size of the Main frame
171
172 MapSubwindows();
173
174 Layout();
175
176 SetWindowName("DataCheck Window");
177 SetIconName("DataCheck");
178
179 MapWindow();
180
181}
182
183
184// ======================================================================
185// ======================================================================
186
187MGDataCheckMain::~MGDataCheckMain()
188{
189 //delete fPicCdup, fPicList, fPicDetail;
190 delete fLayTab, fLayMenuBar, fLayMenuItem;
191 delete fFileView;
192 delete fFileCont;
193 delete fCdup, fListMode, fDetail;
194 delete fDir ;
195 delete fTabF1b, fTabF1a, fTabF1;
196 delete fButPedADC, fButCrADC, fButPedTDC, fButCrTDC;
197 delete fTop3, fTop2, fTop1;
198 delete fTab;
199 delete fFrameTop, fFrameLow ;
200 delete fFileMenu;
201 delete fMenuBar;
202
203}
204
205
206// ======================================================================
207// ======================================================================
208
209void MGDataCheckMain::CloseWindow()
210{
211 // Got close message for this MainFrame. Calls parent CloseWindow()
212 // (which destroys the window) and terminate the application.
213 // The close message is generated by the window manager when its close
214 // window menu item is selected.
215
216 delete this ;
217}
218
219
220// ======================================================================
221// ======================================================================
222
223Bool_t MGDataCheckMain::InputFileSelected()
224{
225 // Checks if there is a selected input root file
226
227 if ( strcmp ( fInputFile, "\n") == 0 )
228 {
229 return ( kFALSE ) ;
230 }
231
232 return (kTRUE) ;
233}
234
235
236// ======================================================================
237// ======================================================================
238
239Bool_t MGDataCheckMain::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
240{
241 // Process events generated by the buttons in the frame.
242
243 Int_t buttons = 4, retval = 0 ;
244 Char_t wort[100] ;
245 Char_t extens[5] ;
246 Char_t command[110] ;
247
248 TGFileItem *item ; // to process items in the file view container
249 void *np = NULL ; // null pointer
250
251 switch (GET_MSG(msg))
252 {
253 case kC_COMMAND:
254 switch (GET_SUBMSG(msg))
255 {
256 case kCM_BUTTON:
257
258 switch (parm1)
259 {
260
261 case M_BUTTON_PEDADC:
262
263 if ( InputFileSelected() == kFALSE ) { // it is not selected
264
265 new TGMsgBox(fClient->GetRoot(), this, "ERROR!",
266 "No Input (root) File selected!", kMBIconExclamation, buttons, &retval);
267 break ;
268 }
269
270 fViewAdc.PedAdcSpectra(fInputFile) ;
271
272 break ;
273
274
275 case M_BUTTON_CRADC:
276
277 if ( InputFileSelected() == kFALSE ) { // it is not selected
278
279 new TGMsgBox(fClient->GetRoot(), this, "ERROR!",
280 "No Input (root) File selected!", kMBIconExclamation, buttons, &retval);
281 break ;
282 }
283
284 // fOctober.CrAdcSpectra(fInputFile) ;
285
286 break ;
287
288 case M_BUTTON_PEDTDC:
289
290 if ( InputFileSelected() == kFALSE ) { // it is not selected
291
292 new TGMsgBox(fClient->GetRoot(), this, "ERROR!",
293 "No Input (root) File selected!", kMBIconExclamation, buttons, &retval);
294 break ;
295 }
296
297 // fOctober.PedTdcSpectra(fInputFile) ;
298
299 break ;
300
301 case M_BUTTON_CRTDC:
302
303 if ( InputFileSelected() == kFALSE ) { // it is not selected
304
305 new TGMsgBox(fClient->GetRoot(), this, "ERROR!",
306 "No Input (root) File selected!", kMBIconExclamation, buttons, &retval);
307 break ;
308 }
309
310 // fOctober.CrTdcSpectra(fInputFile) ;
311
312 break ;
313
314 case M_PBUTTON_CDIR_UP :
315
316 // goto the parent directory
317
318 gSystem->ChangeDirectory("..") ;
319 fDir->RemoveEntry(1) ;
320 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
321 fDir->AddEntry(wort,1) ;
322 fDir->MapSubwindows() ;
323 fDir->Layout() ;
324 fFileCont->ChangeDirectory( wort ) ;
325 fFileCont->DisplayDirectory() ;
326
327 break ;
328
329 case M_PBUTTON_LIST_MODE:
330 fFileView->SetViewMode(kLVList) ;
331 fDetail->SetState(kButtonUp) ;
332
333 break ;
334
335 case M_PBUTTON_DETAIL_MODE:
336 fFileView->SetViewMode(kLVDetails) ;
337 fListMode->SetState(kButtonUp) ;
338
339 break ;
340
341 default:
342 break ;
343 }
344
345 case kCM_MENU:
346
347 switch (parm1) {
348 case M_FILE_CLOSE:
349 CloseWindow() ;
350
351 break;
352 }
353 break ;
354
355 default:
356 break ;
357
358 }
359
360 case kC_CONTAINER:
361 switch (GET_SUBMSG(msg)) {
362
363 // case kCT_ITEMCLICK:
364 // printf ("itemclick\n");
365 // break;
366
367
368 case kCT_ITEMDBLCLICK:
369 //
370 // process the double click in the file view container
371 //
372
373 if ( parm1 == kButton1) {
374 if ( fFileCont->NumSelected() == 1 ) {
375 //
376 // one file selected
377 //
378 item = (TGFileItem *) fFileCont->GetNextSelected(&np) ;
379
380 if ( S_ISDIR(item->GetType()) ) // file is directory
381 {
382 // goto directory
383
384 sprintf (wort, "%s", item->GetItemName()->GetString()) ;
385 fFileCont->ChangeDirectory ( wort ) ;
386 gSystem->ChangeDirectory( wort ) ;
387
388 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
389 fDir->RemoveEntry(1) ;
390 fDir->AddEntry( wort, 1 ) ;
391 fDir->MapSubwindows() ;
392 fDir->Layout() ;
393 }
394 else // file is no directory, is a file
395 {
396 sprintf (wort, "%s", item->GetItemName()->GetString() ) ;
397
398 // determine the file type by extensions
399
400 for (Int_t i = 0 ; i<5; i++)
401 extens[i] = '\0' ;
402
403 for ( Int_t i=0; wort[i] != '\0'; i++) {
404 if ( wort[i] == '.') {
405 strncpy (extens, &wort[i+1], 4 ) ;
406 break ;
407 }
408 }
409
410 if ( ! strcmp(extens, "ps") ) { // postscript file
411 sprintf ( command, "gv %s/%s &",
412 gSystem->WorkingDirectory(),
413 wort ) ;
414 gSystem->Exec(command) ;
415 break ;
416 }
417 else if ( ! strcmp(extens, "root") ) { // root file
418 sprintf ( fInputFile, "%s/%s" , gSystem->WorkingDirectory(), wort ) ;
419
420 printf (" %s \n", fInputFile ) ;
421 break ;
422 }
423
424 }
425 }
426 }
427 break;
428
429 default:
430 break ;
431 }
432
433
434
435 default:
436 break;
437 }
438 return kTRUE;
439}
Note: See TracBrowser for help on using the repository browser.