21 #include <QCoreApplication>
22 #include <qmessagebox.h>
34 #include <QElapsedTimer>
35 #include <QProgressBar>
39 static void set_elapsed_label_seconds(qint64 seconds)
41 const QString msg = QStringLiteral(
"Calcul acoustique en coursâ¦\nTemps écoulé : %1 s").arg(seconds);
42 TYProgressManager::setMessage(msg.toUtf8().constData());
51 if (!TYProgressManager::getProgressDialog())
53 auto* dlg = TYProgressManager::getProgressDialog();
55 dlg->setWindowModality(Qt::ApplicationModal);
59 TYProgressManager::setProgress(0);
63 if (
auto* bar = dlg->findChild<QProgressBar*>())
65 bar->setTextVisible(
false);
69 auto* bar2 =
new QProgressBar(dlg);
70 bar2->setRange(0, 100);
72 bar2->setTextVisible(
false);
76 set_elapsed_label_seconds(0);
82 elapsedTimer.setInterval(1000);
83 QObject::connect(&elapsedTimer, &QTimer::timeout,
84 [&] { set_elapsed_label_seconds(chrono.elapsed() / 1000); });
88 bool userCanceled =
false;
91 QObject::connect(dlg, &QProgressDialog::canceled,
100 dlg->activateWindow();
101 qApp->processEvents();
106 QThread* thread =
new QThread;
108 runner->moveToThread(thread);
110 bool computation_ok =
false;
111 QString error_msg_qs;
116 [&](
bool ok,
const QString& msg)
123 QObject::connect(thread, &QThread::finished, runner, &QObject::deleteLater);
124 QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater);
138 if (cancelled || userCanceled)
141 msgBox.setIcon(QMessageBox::Information);
142 msgBox.setText(
"Calcul acoustique interrompu par l'utilisateur.");
148 logger.
error(
"Echec du calcul acoustique: %s", error_msg_qs.toStdString().c_str());
150 msgBox.setIcon(QMessageBox::Critical);
151 msgBox.setText(
"Echec du calcul acoustique. Veuillez consulter le journal d'erreurs.\n");
161 return computation_ok;
Worker object that runs the blocking python(...) call off the GUI thread.
TYMainWindow * getTYMainWnd()
Retourne le pointeur sur la fenetre principale.
pour l'application Tympan (fichier header)
virtual void error(const char *message,...)
static OMessageManager * get()
Runs the blocking python(...) computation in a worker thread.
void finished(bool ok, QString errorMsg)
Emitted when the computation completes.
void run()
Call this slot to start the computation (meant to be invoked from the worker thread).
static void setCurrentQtDir()
Indique à Qt le chemin du répertoire courant.
static void set(int totalSteps, int stepSize=1)
static void create(QWidget *pParent, const char *name=0)
bool python_gui(QStringList args)
Launch a Python-driven computation with a GUI progress dialog.
Utilities for interactions between the GUI and the operating system (headers).
void python_request_cancel()
Request cancellation of the currently running Python subprocess (UI hook, stage A).
bool python_cancel_was_requested()
Query whether a cancellation was requested since the last call to python().
Utilities to interact with Python subprocesses from the Tympan application.