From c5fcb6b8d505b4e394b336cd6c37fe686f267950 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Sun, 8 May 2016 16:16:04 +0200 Subject: [PATCH] dashboard: use get_open_file_name --- artiq/browser/experiments.py | 4 ++-- artiq/dashboard/experiments.py | 24 ++++++++++++------------ artiq/gui/tools.py | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/artiq/browser/experiments.py b/artiq/browser/experiments.py index 7f701d3e2..21a2617c6 100644 --- a/artiq/browser/experiments.py +++ b/artiq/browser/experiments.py @@ -8,7 +8,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets import h5py from artiq import __artiq_dir__ as artiq_dir -from artiq.gui.tools import LayoutWidget, log_level_to_name, getOpenFileName +from artiq.gui.tools import LayoutWidget, log_level_to_name, get_open_file_name from artiq.gui.entries import argty_to_entry from artiq.protocols import pyon from artiq.master.worker import Worker @@ -346,7 +346,7 @@ class ExperimentsArea(QtWidgets.QMdiArea): async def _select_experiment_task(self): try: - file = await getOpenFileName( + file = await get_open_file_name( self, "Open experiment", self.current_dir, "Experiments (*.py);;All files (*.*)") except asyncio.CancelledError: diff --git a/artiq/dashboard/experiments.py b/artiq/dashboard/experiments.py index f156f4c6d..52cb1f3ae 100644 --- a/artiq/dashboard/experiments.py +++ b/artiq/dashboard/experiments.py @@ -7,7 +7,7 @@ from collections import OrderedDict from PyQt5 import QtCore, QtGui, QtWidgets import h5py -from artiq.gui.tools import LayoutWidget, log_level_to_name +from artiq.gui.tools import LayoutWidget, log_level_to_name, get_open_file_name from artiq.gui.entries import argty_to_entry from artiq.protocols import pyon @@ -330,18 +330,18 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow): self.layout.addWidget(self.argeditor, 0, 0, 1, 5) def _load_hdf5_clicked(self): - dialog = QtWidgets.QFileDialog(self.manager.main_window, - "Load HDF5", self.hdf5_load_directory, - "HDF5 files (*.h5 *.hdf5);;All files (*.*)") - dialog.setFileMode(QtWidgets.QFileDialog.ExistingFile) - def on_accept(): - filename = dialog.selectedFiles()[0] - self.hdf5_load_directory = os.path.dirname(filename) - asyncio.ensure_future(self._load_hdf5_task(filename)) - dialog.accepted.connect(on_accept) - dialog.open() + asyncio.ensure_future(self._load_hdf5_task()) + + async def _load_hdf5_task(self): + try: + filename = await get_open_file_name( + self.manager.main_window, "Load HDF5", + self.hdf5_load_directory, + "HDF5 files (*.h5 *.hdf5);;All files (*.*)") + except asyncio.CancelledError: + return + self.hdf5_load_directory = os.path.dirname(filename) - async def _load_hdf5_task(self, filename): try: with h5py.File(filename, "r") as f: expid = f["expid"][()] diff --git a/artiq/gui/tools.py b/artiq/gui/tools.py index e89bf0787..fc3daf91a 100644 --- a/artiq/gui/tools.py +++ b/artiq/gui/tools.py @@ -48,7 +48,7 @@ class LayoutWidget(QtWidgets.QWidget): self.layout.addWidget(item, row, col, rowspan, colspan) -async def getOpenFileName(parent, caption, dir, filter): +async def get_open_file_name(parent, caption, dir, filter): """like QtWidgets.QFileDialog.getOpenFileName(), but a coroutine""" dialog = QtWidgets.QFileDialog(parent, caption, dir, filter) dialog.setFileMode(dialog.ExistingFile)