]> henry.ined.fr Git - .git/commitdiff
Summary: imach gui
authorN. Brouard <brouard@ined.fr>
Tue, 27 Feb 2018 23:00:08 +0000 (23:00 +0000)
committerN. Brouard <brouard@ined.fr>
Tue, 27 Feb 2018 23:00:08 +0000 (23:00 +0000)
imach-gui/dialog.cpp [new file with mode: 0644]
imach-gui/dialog.h [new file with mode: 0644]
imach-gui/dialog.ui [new file with mode: 0644]
imach-gui/imach-gui.pro [new file with mode: 0644]
imach-gui/main.cpp [new file with mode: 0644]

diff --git a/imach-gui/dialog.cpp b/imach-gui/dialog.cpp
new file mode 100644 (file)
index 0000000..d328c59
--- /dev/null
@@ -0,0 +1,221 @@
+// dialog.cpp
+
+#include "dialog.h"
+#include "ui_dialog.h"
+#include <QDebug>
+#include <QString>
+#include <QProcess>
+#include <QScrollBar>
+#include <QMessageBox>
+#include <QFileInfo>
+#include <QFileDialog>
+
+#include <QTextStream>
+#include <QFile>
+#include <QDesktopServices>
+#include <QUrl>
+
+Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog)
+{
+    ui->setupUi(this);
+
+    // Play button for output - initially disabled
+    //ui->playOutputButton->setEnabled(false);
+    ui->openGnuplotButton->setEnabled(false);
+
+    // Create three processes
+    // 1.imachexec, 2.input play 3.output play
+    mImachexecProcess = new QProcess(this);
+    mGnuplotProcess = new QProcess(this);
+    //mOutputPlayProcess = new QProcess(this);
+
+    connect(mImachexecProcess, SIGNAL(started()), this, SLOT(processStarted()));
+
+    connect(mImachexecProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
+    connect(mImachexecProcess, SIGNAL(finished(int)), this, SLOT(imachexecFinished()));
+}
+
+Dialog::~Dialog()
+{
+    delete ui;
+}
+
+void Dialog::processStarted()
+{
+    qDebug() << "processStarted()";
+}
+
+// imach start
+void Dialog::on_startButton_clicked()
+{
+    QString program = "imach";
+
+    QStringList arguments;
+
+    QString input = ui->fromLineEdit->text();
+    if(input.isEmpty()) {
+        qDebug() << "No input";
+        QMessageBox::information(this,
+                     tr("imach"),tr("Input file not specified"));
+        return;
+    }
+    QString output = input;
+//    QString output = ui->toLineEdit->text();
+//    if(output.isEmpty()) {
+//        qDebug() << "No output";
+//        QMessageBox::information(this,
+//                     tr("imach"),tr("Output file not specified"));
+//        return;
+//    }
+
+//    QString fileName = ui->toLineEdit->text();
+//    qDebug() << "output file check " << fileName;
+//    qDebug() << "QFile::exists(fileName) = " << QFile::exists(fileName);
+//    if (QFile::exists(fileName)) {
+//         if (QMessageBox::question(this, tr("imach"),
+//                    tr("There already exists a file called %1 in "
+//                    "the current directory. Overwrite?").arg(fileName),
+//                    QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
+//             == QMessageBox::No)
+//             return;
+//         QFile::remove(fileName);
+//         while(QFile::exists(fileName)) {
+//             qDebug() << "output file still there";
+//         }
+//     }
+
+//    arguments << input << output;
+      arguments << input << " q";
+
+    qDebug() << arguments;
+
+    mImachexecProcess->setProcessChannelMode(QProcess::MergedChannels);
+    mImachexecProcess->start(program, arguments);
+}
+
+void Dialog::readyReadStandardOutput()
+{
+    mOutputString.append(mImachexecProcess->readAllStandardOutput());
+    ui->textEdit->setText(mOutputString);
+
+    // put the slider at the bottom
+    ui->textEdit->verticalScrollBar()
+            ->setSliderPosition(
+                ui->textEdit->verticalScrollBar()->maximum());
+}
+
+void Dialog::imachexecFinished()
+{
+    // Set the imachexec status by checking output gnuplot file's existence
+    //QString fileName = ui->toLineEdit->text();
+    QString fichnom = ui->fromLineEdit->text();
+    QFileInfo fileInfor(fichnom);
+    QString NomComplet = fileInfor.completeBaseName();
+    //QString NomSuffix = fileInfor.suffix();
+    //QString NomCheminsansEx = fileInfor.canonicalPath()+NomComplet;
+    QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp";
+    //QFileInfo fileInfoGp(NomCompGp);
+
+    //if (QFile::exists(fileName)) {
+    if (QFile::exists(NomCompGp)) {
+        ui->imachStatusLabel
+                ->setText("IMaCh Status: Successful!");
+        //ui->playOutputButton->setEnabled(true);
+        ui->openGnuplotButton->setEnabled(true);
+    }
+    else {
+        ui->imachStatusLabel
+                ->setText("IMaCh Status: Failed!");
+    }
+}
+
+// Browse... button clicked - this is for input file
+void Dialog::on_fileOpenButton_clicked()
+{
+    QString fileName =
+        QFileDialog::getOpenFileName(
+                this,
+                tr("Open File"),
+                "/tmp/test",
+                tr("imach parameter files (*.imach *.txt *.log *.gp)"));
+    QFileInfo fileInfor(fileName);
+    if (!fileName.isEmpty()) {
+        ui->fromLineEdit->setText(fileName);
+    }
+
+}
+
+void Dialog::on_openLogButton_clicked()
+{
+    QString fichnom = ui->fromLineEdit->text();
+    QFileInfo fileInfor(fichnom);
+    QString NomComplet = fileInfor.completeBaseName();
+    QString NomCompLog = fileInfor.canonicalPath()+"/"+NomComplet+".log";
+    //QFileInfo fileInfolog(NomCompLog);
+    QDesktopServices::openUrl(QUrl("file://"+NomCompLog,QUrl::TolerantMode));
+}
+
+void Dialog::on_launchbrowButton_clicked()
+{
+    QString fichnom = ui->fromLineEdit->text();
+    QFileInfo fileInfor(fichnom);
+    QString NomComplet = fileInfor.completeBaseName();
+    QString NomCompLaunch = fileInfor.canonicalPath()+"/"+NomComplet+".htm";
+    //QFileInfo fileInfolog(NomCompLaunch;
+    QDesktopServices::openUrl(QUrl("file://"+NomCompLaunch,QUrl::TolerantMode));
+}
+
+void Dialog::on_openGnuplotButton_clicked()
+{
+ //   QString program = "ffplay";
+ //   QStringList arguments;
+    QString fichnom = ui->fromLineEdit->text();
+    QFileInfo fileInfor(fichnom);
+    QString NomComplet = fileInfor.completeBaseName();
+    //QString NomSuffix = fileInfor.suffix();
+    //QString NomCheminsansEx = fileInfor.canonicalPath()+NomComplet;
+    QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp";
+    QFileInfo fileInfoGp(NomCompGp);
+    //QString input = NomCheminsansEx;
+    //   arguments << input;
+ //   mInputPlayProcess->start(program, arguments);
+  //  QFile file(NomCompLog);
+  //  if(!file.open(QIODevice::ReadOnly))
+  //      QMessageBox::information(0,"info",file.errorString());
+
+    QDesktopServices::openUrl(QUrl("file://"+NomCompGp,QUrl::TolerantMode));
+//o    QTextStream in(&file);
+//o    ui->playInputButton->setText(in.readAll());
+}
+
+
+void Dialog::on_runGnuplotButton_clicked()
+{
+    QString program = "gnuplot";
+    QStringList arguments;
+    QString fichnom = ui->fromLineEdit->text();
+    QFileInfo fileInfor(fichnom);
+    QString NomComplet = fileInfor.completeBaseName();
+    QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp";
+    //QFileInfo fileInfoGp(NomCompGp);
+    //QString input = NomCheminsansEx;
+    arguments << NomCompGp;
+    mGnuplotProcess->start(program, arguments);
+  //  QFile file(NomCompLog);
+  //  if(!file.open(QIODevice::ReadOnly))
+  //      QMessageBox::information(0,"info",file.errorString());
+
+    //QDesktopServices::openUrl(QUrl("file://"+NomCompGp,QUrl::TolerantMode));
+//o    QTextStream in(&file);
+//o    ui->playInputButton->setText(in.readAll());
+}
+
+//void Dialog::on_playOutputButton_clicked()
+//{
+//    QString program = "ffplay";
+//    QStringList arguments;
+//    QString output = ui->toLineEdit->text();
+//    arguments << output;
+//    mInputPlayProcess->start(program, arguments);
+//}
+
diff --git a/imach-gui/dialog.h b/imach-gui/dialog.h
new file mode 100644 (file)
index 0000000..cc0f9a6
--- /dev/null
@@ -0,0 +1,49 @@
+// dialog.h
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+#include <QProcess>
+#include <QFile>
+#include <QTextEdit>
+
+namespace Ui {
+class Dialog;
+}
+
+class Dialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit Dialog(QWidget *parent = 0);
+    ~Dialog();
+
+public slots:
+
+public:
+
+private slots:
+     void on_startButton_clicked();
+     void readyReadStandardOutput();
+     void processStarted();
+     void imachexecFinished();
+     void on_fileOpenButton_clicked();
+     void on_openLogButton_clicked();
+     void on_openGnuplotButton_clicked();
+     void on_launchbrowButton_clicked();
+     void on_runGnuplotButton_clicked();
+
+
+     //void on_playOutputButton_clicked();
+
+private:
+    Ui::Dialog *ui;
+    QProcess *mImachexecProcess;
+    QProcess *mGnuplotProcess;
+    QProcess *mOutputPlayProcess;
+    QString mOutputString;
+};
+
+#endif // DIALOG_H
diff --git a/imach-gui/dialog.ui b/imach-gui/dialog.ui
new file mode 100644 (file)
index 0000000..a7de37d
--- /dev/null
@@ -0,0 +1,187 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>406</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0" colspan="3">
+    <layout class="QHBoxLayout" name="horizontalLayout_4">
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <item>
+        <widget class="QLabel" name="imachStatusLabel">
+         <property name="text">
+          <string>IMaCh parameter file</string>
+         </property>
+         <property name="buddy">
+          <cstring>fromLineEdit</cstring>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="fromLineEdit">
+         <property name="locale">
+          <locale language="French" country="France"/>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <widget class="QPushButton" name="fileOpenButton">
+       <property name="text">
+        <string>Browse...</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item row="1" column="0" colspan="3">
+    <layout class="QHBoxLayout" name="horizontalLayout_5">
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout_2"/>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item row="2" column="0">
+    <layout class="QHBoxLayout" name="horizontalLayout_6">
+     <item>
+      <widget class="QPushButton" name="startButton">
+       <property name="text">
+        <string>Run imach</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item row="3" column="0" colspan="3">
+    <widget class="QTextEdit" name="textEdit"/>
+   </item>
+   <item row="4" column="0" colspan="3">
+    <layout class="QHBoxLayout" name="horizontalLayout_7">
+     <item>
+      <widget class="QPushButton" name="runGnuplotButton">
+       <property name="text">
+        <string>Run Gnuplot file</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_3">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item row="5" column="0" colspan="3">
+    <layout class="QHBoxLayout" name="horizontalLayout_3">
+     <item>
+      <widget class="QPushButton" name="openLogButton">
+       <property name="text">
+        <string>Browse log file</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="openGnuplotButton">
+       <property name="text">
+        <string>Edit gnuplot file</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item row="6" column="2">
+    <widget class="QPushButton" name="pushButton">
+     <property name="text">
+      <string>Close</string>
+     </property>
+    </widget>
+   </item>
+   <item row="6" column="1">
+    <widget class="QPushButton" name="launchbrowButton">
+     <property name="text">
+      <string>Visualize results</string>
+     </property>
+    </widget>
+   </item>
+   <item row="6" column="0">
+    <spacer name="horizontalSpacer_4">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>298</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>pushButton</sender>
+   <signal>clicked()</signal>
+   <receiver>Dialog</receiver>
+   <slot>close()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>267</x>
+     <y>125</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>267</x>
+     <y>174</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/imach-gui/imach-gui.pro b/imach-gui/imach-gui.pro
new file mode 100644 (file)
index 0000000..1d88588
--- /dev/null
@@ -0,0 +1,22 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2013-10-03T22:30:49
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = imach-gui
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+    dialog.cpp \
+
+HEADERS  += dialog.h \
+    dialog.h
+
+FORMS    += dialog.ui \
+    dialog.ui
diff --git a/imach-gui/main.cpp b/imach-gui/main.cpp
new file mode 100644 (file)
index 0000000..4c3f5e4
--- /dev/null
@@ -0,0 +1,13 @@
+#include "dialog.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+    Dialog w;
+    w.setWindowTitle("Imach-Gui Dialog");
+    w.show();
+
+    return a.exec();
+}
+