From fe69712cc5108418147593f1193a2270c1a75ce6 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Fri, 13 May 2016 15:43:02 +0200 Subject: [PATCH] browser: dis/enable analyze/terminate buttons --- artiq/browser/experiments.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/artiq/browser/experiments.py b/artiq/browser/experiments.py index ebe64ef6d..5e984469b 100644 --- a/artiq/browser/experiments.py +++ b/artiq/browser/experiments.py @@ -176,7 +176,6 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow): self.layout.setRowStretch(0, 1) self.options = {"log_level": logging.WARNING} - self._worker = None self._run_task = None log_level = QtWidgets.QComboBox() @@ -206,6 +205,7 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow): QtWidgets.QSizePolicy.Expanding) self.layout.addWidget(run, 1, 4, 2, 1) run.clicked.connect(self.run_clicked) + self._run = run terminate = QtWidgets.QPushButton("Terminate") terminate.setIcon(QtWidgets.QApplication.style().standardIcon( @@ -216,6 +216,8 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow): QtWidgets.QSizePolicy.Expanding) self.layout.addWidget(terminate, 3, 4) terminate.clicked.connect(self.terminate_clicked) + terminate.setEnabled(False) + self._terminate = terminate def dragEnterEvent(self, ev): if ev.mimeData().hasFormat("text/uri-list"): @@ -265,9 +267,6 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow): await self._recompute_arguments(arguments) def run_clicked(self): - if self._run_task is not None: - logger.error("Analysis already started") - return class_name, file = self.expurl.split("@", maxsplit=1) expid = { "repo_rev": "N/A", @@ -280,32 +279,32 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow): for name, argument in self.arguments.items()}, } self._run_task = asyncio.ensure_future(self._get_run_task(expid)) + self._run.setEnabled(False) + self._terminate.setEnabled(True) def done(fut): logger.info("Analysis done") self._run_task = None - + self._run.setEnabled(True) + self._terminate.setEnabled(False) self._run_task.add_done_callback(done) async def _get_run_task(self, expid): - self._worker = Worker(self._area.worker_handlers) + worker = Worker(self._area.worker_handlers) try: - await self._worker.build(rid=None, pipeline_name="browser", - wd=os.path.abspath("."), - expid=expid, priority=0) - await self._worker.analyze() + await worker.build(rid=None, pipeline_name="browser", + wd=os.path.abspath("."), + expid=expid, priority=0) + await worker.analyze() except: # May happen when experiment has been removed # from repository/explist logger.error("Failed to run '%s'", self.expurl, exc_info=True) finally: - await self._worker.close() - self._worker = None + await worker.close() def terminate_clicked(self): - if self._run_task is None: - return try: self._run_task.cancel() except: