Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4GUI/TGo4ScriptWidget.ui.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 /****************************************************************************
00017 ** ui.h extension file, included from the uic-generated form implementation.
00018 **
00019 ** If you wish to add, delete or rename functions or slots use
00020 ** Qt Designer which will update this file, preserving your code. Create an
00021 ** init() function in place of a constructor, and a destroy() function in
00022 ** place of a destructor.
00023 *****************************************************************************/
00024 
00025 #include <iostream.h>
00026 
00027 void TGo4ScriptWidget::init() 
00028 {
00029  // TGo4LockGuard glob;
00030     QGridLayout* layout = new QGridLayout( this, 1, 1, 11, 6, "TGo4AnalysisWindowLayout");
00031     fxOutput = new QTextEdit( this, "output" );
00032     layout->addWidget( fxOutput, 0, 0 );
00033 
00034     fxOutput->setReadOnly(TRUE);
00035     fxOutput->setWordWrap(QTextEdit::NoWrap);
00036     fxOutput->setUndoRedoEnabled(FALSE);
00037     fxOutput->setAutoFormatting(QTextEdit::AutoNone);
00038 
00039     TGo4GUIRegistry *fxRegistry = TGo4GUIRegistry::Instance();
00040     fxSlots = (TGo4ScriptSlots*) fxRegistry->GetSlotClass("TGo4ScriptSlots");
00041     if(fxSlots!=0)
00042       fxSlots->SetGUI(this);
00043     else
00044       fxSlots = new TGo4ScriptSlots("TGo4ScriptSlots", "Slots Class for Qt GUI", this);
00045     fxStatus = (TGo4ScriptStatus*)  fxSlots->GetStatus();
00046 
00047     fxSlots->setOutput(fxOutput);
00048 }
00049 
00050 void TGo4ScriptWidget::destroy() 
00051 {
00052    if (fxSlots) fxSlots->SetGUI(0);
00053 }
00054 
00055 void TGo4ScriptWidget::closeEvent(QCloseEvent* e) 
00056 {
00057    fbBreakExecution = true;
00058    QWidget::closeEvent(e);
00059 }
00060 
00061 void TGo4ScriptWidget::executeScript(const char* fname) 
00062 {
00063     QString fileName = fname;
00064     QString ext = TGo4ScriptSlots::GUIScriptExtension;
00065 
00066     if (fname==0) {
00067        fileName = QFileDialog::getOpenFileName(
00068          "",
00069          QString("GUI script (*") + ext + ")",
00070          this,
00071          "Execute GUI script dialog",
00072          "Choose a file to be executed");
00073 
00074       if (fileName.length()==0) return;
00075     } else {
00076        int pos = fileName.find(ext);
00077        if ((pos<0) || (pos!=fileName.length()-strlen(ext)))
00078            fileName+=ext;
00079     }
00080 
00081     fxOutput->clear();
00082     fbBreakExecution = false;
00083 
00084     QFile file(fileName);
00085     if (file.open(IO_ReadOnly)) {
00086        fxStatus->fxCommands.Clear();
00087 
00088        QString str;
00089        while (!file.atEnd()) {
00090           file.readLine(str, 1000);
00091           fxStatus->fxCommands.Add(new TObjString(str.latin1()));
00092        }
00093 
00094        QTimer::singleShot(500, this, SLOT(startScript()));
00095     } else {
00096        fxOutput->append(QString("File ") + fileName + " not found");
00097     }
00098 }
00099 
00100 void TGo4ScriptWidget::produceScript(const char* fname) 
00101 {
00102    QString fileName = fname;
00103    QString ext = TGo4ScriptSlots::GUIScriptExtension;
00104    if (fileName.length()==0)
00105        fileName = QFileDialog::getSaveFileName(
00106         "",
00107         QString("GUI hotstart script (*") + ext + ")",
00108         this,
00109         "Create GUI script dialog",
00110         "Choose a file to be created");
00111    if (fileName.length()==0) return;
00112 
00113    int pos = fileName.find(ext);
00114 
00115    if ((pos<0) || (pos!=fileName.length()-strlen(ext)))
00116      fileName+=ext;
00117 
00118    fxOutput->clear();
00119    fxSlots->GenerateStartupScript(fileName);
00120    close();
00121 }
00122 
00123 void TGo4ScriptWidget::startScript() 
00124 {
00125    if (fxSlots && fxSlots->StartScriptExecution()) {
00126      QTimer::singleShot(10, this, SLOT(continueScript()));
00127      //QApplication::setOverrideCursor( Qt::WaitCursor );
00128    }
00129    else
00130      close();
00131 }
00132 
00133 
00134 
00135 void TGo4ScriptWidget::continueScript() 
00136 {
00137    if (fbBreakExecution) {
00138      QApplication::restoreOverrideCursor();  
00139      return;
00140    }
00141    if (fxSlots && fxSlots->ProcessScriptExecution()) {
00142       QTimer::singleShot(10, this, SLOT(continueScript()));
00143       if (QApplication::overrideCursor()==0)
00144         QApplication::setOverrideCursor( Qt::WaitCursor );
00145    } else {
00146       close();
00147       QApplication::restoreOverrideCursor();
00148    }
00149 }
00150 
00151 void TGo4ScriptWidget::breakScript() 
00152 {
00153    fxOutput->append("// Break script execution");
00154    fbBreakExecution = true;
00155 }
00156 
00157 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:03 2005 for Go4-v2.10-5 by doxygen1.2.15