18 #include "Riostream.h"
22 #include "qpushbutton.h"
24 #include <QtCore/QTimer>
25 #include <QtCore/QTextStream>
26 #include <QtCore/QProcess>
28 #include <QHBoxLayout>
29 #include <QGridLayout>
32 #include <QMessageBox>
33 #include <QFileDialog>
34 #include <QToolButton>
49 setAcceptDrops(
false);
62 setWindowTitle(
"Analysis Terminal");
69 setWindowIcon(QIcon(
":/icons/analysiswin.png"));
70 QGridLayout* layout =
new QGridLayout(
this );
71 layout->setMargin(11);
72 layout->setSpacing(6);
76 fxOutput->setAutoFormatting(QTextEdit::AutoNone);
77 fxOutput->setWordWrapMode(QTextOption::NoWrap);
86 QHBoxLayout *box1 =
new QHBoxLayout();
87 box1->addWidget(
new QLabel(
"Press enter to execute.",
this), 1);
89 layout->addLayout(box1, 1, 0);
91 QHBoxLayout *box2 =
new QHBoxLayout();
93 layout->addLayout(box2, 2, 0);
98 QHBoxLayout *box =
new QHBoxLayout(
this);
119 fxCmdHist->setToolTip(
"CINT command for analysis process. Note: '@' means 'TGo4Analysis::Instance()->' . A leading '$' will invoke Python script.");
121 fxCmdHist->setMinimumSize( QSize( 220, 25 ) );
129 QToolButton* MacroSearch =
new QToolButton(
this );
130 MacroSearch->setMinimumSize( QSize( 30, 25 ) );
131 MacroSearch->setMaximumSize( QSize( 30, 25 ) );
132 MacroSearch->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
133 MacroSearch->setIcon( QIcon(
":/icons/findfile.png" ) );
134 MacroSearch->setToolTip(
"Search root or python macro on disk.");
136 box->addWidget(MacroSearch,1);
142 QToolButton* KillProcess =
new QToolButton(
this );
143 KillProcess->setMinimumSize( QSize( 30, 25 ) );
144 KillProcess->setMaximumSize( QSize( 30, 25 ) );
145 KillProcess->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
146 KillProcess->setIcon( QIcon(
":/icons/killanal.png" ) );
147 KillProcess->setToolTip(
"Apply Ctrl+C in the analysis terminal.");
149 box->addWidget(KillProcess);
153 QToolButton* ClearButton =
new QToolButton(
this );
154 ClearButton->setMinimumSize( QSize( 30, 25 ) );
155 ClearButton->setMaximumSize( QSize( 30, 25 ) );
156 ClearButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
157 ClearButton->setIcon( QIcon(
":/icons/clear.png" ) );
158 ClearButton->setToolTip(
"Clear Terminal Window.");
160 box->addItem(
new QSpacerItem(1,1));
161 box->addWidget(ClearButton,1);
163 QToolButton* ScrollEndButton =
new QToolButton(
this );
164 ScrollEndButton->setMinimumSize( QSize( 30, 25 ) );
165 ScrollEndButton->setMaximumSize( QSize( 30, 25 ) );
166 ScrollEndButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
167 ScrollEndButton->setIcon( QIcon(
":/icons/shiftdown.png" ) );
168 ScrollEndButton->setToolTip(
"Scroll to end of Terminal Window. (keyboard: end)");
170 box->addWidget(ScrollEndButton,1);
176 QToolButton* PrintHistoButton =
new QToolButton(
this );
177 PrintHistoButton->setMinimumSize( QSize( 30, 25 ) );
178 PrintHistoButton->setMaximumSize( QSize( 30, 25 ) );
179 PrintHistoButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
180 PrintHistoButton->setIcon( QIcon(
":/icons/hislist.png" ) );
181 PrintHistoButton->setToolTip(
"Print list of all histograms.");
182 connect(PrintHistoButton, SIGNAL(clicked()),
this, SLOT(
PrintHistograms()));
183 box->addWidget(PrintHistoButton,1);
185 QToolButton* PrintConnyButton =
new QToolButton(
this );
186 PrintConnyButton->setMinimumSize( QSize( 30, 25 ) );
187 PrintConnyButton->setMaximumSize( QSize( 30, 25 ) );
188 PrintConnyButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
189 PrintConnyButton->setIcon( QIcon(
":/icons/condlist.png" ) );
190 PrintConnyButton->setToolTip(
"Print list of all conditions.");
191 connect(PrintConnyButton, SIGNAL(clicked()),
this, SLOT(
PrintConditions()));
192 box->addWidget(PrintConnyButton,1);
194 QToolButton* PrintEventButton =
new QToolButton(
this );
195 PrintEventButton->setMinimumSize( QSize( 30, 25 ) );
196 PrintEventButton->setMaximumSize( QSize( 30, 25 ) );
197 PrintEventButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
198 PrintEventButton->setIcon( QIcon(
":/icons/zoom.png" ) );
199 PrintEventButton->setToolTip(
"Start Event Inspection panel");
200 connect(PrintEventButton, SIGNAL(clicked()),
this, SLOT(
PrintEvent()));
201 box->addWidget(PrintEventButton,1);
237 unsigned int outlen =
fxOutput->toPlainText().length();
244 else if (buflen >= cutlength)
248 fxOutput->moveCursor(QTextCursor::End);
252 QString curr =
fxOutput->toPlainText();
253 curr.remove(0, cutlength - buflen);
256 fxOutput->moveCursor(QTextCursor::End);
295 QString pre = prio>0 ?
"!":
"*";
296 QString format= QString(
"GO4-%1> [%2]\n").arg(pre).arg(
fxTimeFormat);
297 buf = QDateTime::currentDateTime().toString(format)+ buf;
319 setWindowTitle(
"Analysis Terminal");
332 std::cerr <<
"Fatal error. Could not start the Analysis" << std::endl;
337 setWindowTitle(
"Analysis Terminal [with QProcess]");
339 setWindowTitle(QString(
"Analysis Terminal [pid:%1]").arg((qint64)
fAnalysisProcess->pid()));
368 fxOutput->moveCursor(QTextCursor::End);
377 "Save analysis terminal output",
378 "",
"Plain text (*.txt)");
379 fd.setFileMode( QFileDialog::AnyFile );
380 fd.setAcceptMode(QFileDialog::AcceptSave);
382 if (fd.exec() != QDialog::Accepted)
return;
384 QStringList flst = fd.selectedFiles();
385 if (flst.isEmpty())
return;
386 QString fileName = flst[0];
388 if(!fileName.endsWith(
".txt")) fileName.append(
".txt");
389 QFile NewFile(fileName);
390 NewFile.open( QIODevice::ReadWrite | QIODevice::Append );
391 QTextStream t( &NewFile );
392 t <<
fxOutput->toPlainText() <<
"\n";
399 if (cmd.length()==0)
return;
411 QFileDialog fd(
this,
412 "Select ROOT macro for analysis task",
413 "",
"CINT Macro(*.C);;Python script(*.py)");
414 fd.setFileMode( QFileDialog::ExistingFile);
416 if (fd.exec() != QDialog::Accepted)
return;
418 QStringList flst = fd.selectedFiles();
419 if (flst.isEmpty())
return;
421 bool iscint = fd.selectedNameFilter().contains(
".C");
422 bool ispyth = fd.selectedNameFilter().contains(
".py");
426 cmd = QString(
".x ") + flst[0];
430 cmd = QString(
"$") + flst[0];
435 cmd = QString(
".x ") + flst[0];
436 if(!cmd.endsWith(
".C")) cmd.append(
".C");
451 const QString cmd =
"@PrintHistograms()";
464 const QString cmd =
"@PrintConditions()";
490 AddLink(slot,
"ObjectUpdateCmd");
501 if (strcmp(linkname,
"ObjectUpdateCmd")==0) {
512 if (strcmp(linkname,
"DebugOutput")==0) {
514 TList* lst =
dynamic_cast<TList*
> (obj);
516 TListIter iter(lst, kFALSE);
519 while ((obj = iter()) != 0) {
520 if (obj == lst->First())
continue;
531 if (!
HasOutput() || (strcmp(linkname,
"DebugOutput")==0))
546 QWidget* mdi = parentWidget();
QStringList getCommandsHistoryAnalysis()
void setCommandsHistoryAnalysis(const QStringList &commands)
void CreateCmdLine(QHBoxLayout *)
QStringList getHistory(int max=50)
const char * GetObjectFullName() const
void AddTimeStamp(QString &buf, int prio=0)
QGo4CommandsHistory * fxCmdHist
QString getTermTimeFormat()
void storePanelSize(QWidget *w, const QString &kind="ViewPanel")
virtual void resizeEvent(QResizeEvent *)
TClass * ItemClass(const char *name)
void StartAnalysisShell(const char *cmd, const char *workdir=0, bool aschildprocess=false)
virtual void closeEvent(QCloseEvent *e)
void SetHistorySize(int sz)
TGo4AnalysisWindow(QWidget *parent=0, const char *name=0, bool needoutput=false, bool needkillbtn=true)
virtual ~TGo4AnalysisWindow()
void WorkWithDebugOutput(TGo4Slot *slot)
virtual void ExecuteLine(const char *line)
bool getTermShowTimestamp()
void WorkWithUpdateObjectCmd(TGo4Slot *slot)
void ClearAnalysisOutput()
virtual void linkedObjectUpdated(const char *linkname, TObject *obj)
void ScrollEndAnalysisOutput()
virtual void linkedObjectRemoved(const char *linkname)
unsigned int fiMaxOuputSize
void UpdateTimeStampFormat()
void AppendOutputBuffer(const QString &value, int prio=0)
void updateTerminalOutput()
void CreateButtons(QHBoxLayout *, bool)
QProcess * fAnalysisProcess
void TerminateAnalysisProcess()
void SaveAnalysisOutput()
void WaitForNewObject(bool isobjectforeditor)