@@ -23,8 +23,9 @@ void MainView::SetupPython() {
2323 emb::setMainView (this );
2424 PythonWorker *worker = new PythonWorker ();
2525 emb::setWorker (worker);
26- worker->moveToThread (&m_workerThread);
27- connect (&m_workerThread, &QThread::finished, worker, &QObject::deleteLater);
26+ m_workerThread = new QThread ();
27+ worker->moveToThread (m_workerThread);
28+ connect (m_workerThread, &QThread::finished, worker, &QObject::deleteLater);
2829 connect (this , &MainView::operate, worker, &PythonWorker::RunPython);
2930 connect (worker, &PythonWorker::WriteOutput, this , &MainView::WriteOutput);
3031 connect (worker, &PythonWorker::SetCode, this , &MainView::SetCode);
@@ -35,14 +36,15 @@ void MainView::SetupPython() {
3536 connect (worker, &PythonWorker::EndPythonRun, this , &MainView::EndPythonRun);
3637 connect (worker, &PythonWorker::SetSearchRegex, this ,
3738 &MainView::SetSearchRegex);
38- m_workerThread. start ();
39+ m_workerThread-> start ();
3940}
4041// Buttons to enable when you execute a python script
4142void MainView::StartPythonRun () {
4243 ui->btnRun ->setEnabled (false );
4344 ui->btnRunSnippet ->setEnabled (false );
4445 ui->btnRunSnippetFromCombo ->setEnabled (false );
4546 ui->dwTutorial ->setEnabled (false );
47+ ui->btnStopPython ->setEnabled (true );
4648}
4749// End python script
4850void MainView::EndPythonRun () {
@@ -56,6 +58,7 @@ void MainView::EndPythonRun() {
5658 ui->btnRunSnippet ->setEnabled (true );
5759 ui->btnRunSnippetFromCombo ->setEnabled (true );
5860 ui->dwTutorial ->setEnabled (true );
61+ ui->btnStopPython ->setEnabled (false );
5962}
6063// Util function: Confirm message box
6164bool MainView::Confirm (const QString &what) {
@@ -169,8 +172,9 @@ MainView::~MainView() {
169172 settings.setValue (KEY_NOTESBOX, ui->txtNotes ->toPlainText ());
170173 settings.setValue (KEY_FONT, ui->fntCombo ->currentText ());
171174 settings.setValue (KEY_FONTSIZE, ui->cmbFontSize ->currentIndex ());
172- m_workerThread.quit ();
173- m_workerThread.wait ();
175+ m_workerThread->quit ();
176+ m_workerThread->wait ();
177+ delete m_workerThread;
174178 delete ui;
175179 delete m_tute;
176180}
@@ -542,3 +546,12 @@ void MainView::on_btnTuteMark_clicked()
542546
543547 emit operate (m_startMe, ui->txtCode ->toPlainText ());
544548}
549+
550+ void MainView::on_btnStopPython_clicked ()
551+ {
552+ m_workerThread->terminate ();
553+ this ->EndPythonRun ();
554+ m_workerThread->wait ();
555+ delete m_workerThread;
556+ SetupPython ();
557+ }
0 commit comments