forked from M-Labs/artiq
1
0
Fork 0

browser: dis/enable analyze/terminate buttons

This commit is contained in:
Robert Jördens 2016-05-13 15:43:02 +02:00
parent 633c36336c
commit fe69712cc5
1 changed files with 13 additions and 14 deletions

View File

@ -176,7 +176,6 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow):
self.layout.setRowStretch(0, 1) self.layout.setRowStretch(0, 1)
self.options = {"log_level": logging.WARNING} self.options = {"log_level": logging.WARNING}
self._worker = None
self._run_task = None self._run_task = None
log_level = QtWidgets.QComboBox() log_level = QtWidgets.QComboBox()
@ -206,6 +205,7 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow):
QtWidgets.QSizePolicy.Expanding) QtWidgets.QSizePolicy.Expanding)
self.layout.addWidget(run, 1, 4, 2, 1) self.layout.addWidget(run, 1, 4, 2, 1)
run.clicked.connect(self.run_clicked) run.clicked.connect(self.run_clicked)
self._run = run
terminate = QtWidgets.QPushButton("Terminate") terminate = QtWidgets.QPushButton("Terminate")
terminate.setIcon(QtWidgets.QApplication.style().standardIcon( terminate.setIcon(QtWidgets.QApplication.style().standardIcon(
@ -216,6 +216,8 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow):
QtWidgets.QSizePolicy.Expanding) QtWidgets.QSizePolicy.Expanding)
self.layout.addWidget(terminate, 3, 4) self.layout.addWidget(terminate, 3, 4)
terminate.clicked.connect(self.terminate_clicked) terminate.clicked.connect(self.terminate_clicked)
terminate.setEnabled(False)
self._terminate = terminate
def dragEnterEvent(self, ev): def dragEnterEvent(self, ev):
if ev.mimeData().hasFormat("text/uri-list"): if ev.mimeData().hasFormat("text/uri-list"):
@ -265,9 +267,6 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow):
await self._recompute_arguments(arguments) await self._recompute_arguments(arguments)
def run_clicked(self): 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) class_name, file = self.expurl.split("@", maxsplit=1)
expid = { expid = {
"repo_rev": "N/A", "repo_rev": "N/A",
@ -280,32 +279,32 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow):
for name, argument in self.arguments.items()}, for name, argument in self.arguments.items()},
} }
self._run_task = asyncio.ensure_future(self._get_run_task(expid)) self._run_task = asyncio.ensure_future(self._get_run_task(expid))
self._run.setEnabled(False)
self._terminate.setEnabled(True)
def done(fut): def done(fut):
logger.info("Analysis done") logger.info("Analysis done")
self._run_task = None self._run_task = None
self._run.setEnabled(True)
self._terminate.setEnabled(False)
self._run_task.add_done_callback(done) self._run_task.add_done_callback(done)
async def _get_run_task(self, expid): async def _get_run_task(self, expid):
self._worker = Worker(self._area.worker_handlers) worker = Worker(self._area.worker_handlers)
try: try:
await self._worker.build(rid=None, pipeline_name="browser", await worker.build(rid=None, pipeline_name="browser",
wd=os.path.abspath("."), wd=os.path.abspath("."),
expid=expid, priority=0) expid=expid, priority=0)
await self._worker.analyze() await worker.analyze()
except: except:
# May happen when experiment has been removed # May happen when experiment has been removed
# from repository/explist # from repository/explist
logger.error("Failed to run '%s'", logger.error("Failed to run '%s'",
self.expurl, exc_info=True) self.expurl, exc_info=True)
finally: finally:
await self._worker.close() await worker.close()
self._worker = None
def terminate_clicked(self): def terminate_clicked(self):
if self._run_task is None:
return
try: try:
self._run_task.cancel() self._run_task.cancel()
except: except: