dashboard: use get_open_file_name

This commit is contained in:
Robert Jördens 2016-05-08 16:16:04 +02:00
parent c44e786cc5
commit c5fcb6b8d5
3 changed files with 15 additions and 15 deletions

View File

@ -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:

View File

@ -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"][()]

View File

@ -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)