artiq/artiq/gui/explorer.py

160 lines
5.8 KiB
Python
Raw Normal View History

2015-05-24 20:24:07 +08:00
import asyncio
2015-10-20 18:11:50 +08:00
import logging
from functools import partial
2015-05-24 20:24:07 +08:00
2015-05-23 01:25:33 +08:00
from quamash import QtGui, QtCore
from pyqtgraph import dockarea
2015-05-23 01:25:33 +08:00
from pyqtgraph import LayoutWidget
2015-11-17 19:46:26 +08:00
from artiq.gui.models import DictSyncTreeSepModel
2015-05-24 20:24:07 +08:00
2015-12-08 18:57:53 +08:00
logger = logging.getLogger(__name__)
class _OpenFileDialog(QtGui.QDialog):
def __init__(self, parent, exp_manager):
QtGui.QDialog.__init__(self, parent=parent)
self.setWindowTitle("Open file outside repository")
2015-12-08 18:57:53 +08:00
self.exp_manager = exp_manager
grid = QtGui.QGridLayout()
self.setLayout(grid)
grid.addWidget(QtGui.QLabel("Filename:"), 0, 0)
2015-12-08 18:57:53 +08:00
self.filename = QtGui.QLineEdit()
grid.addWidget(self.filename, 0, 1)
buttons = QtGui.QDialogButtonBox(
QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
grid.addWidget(buttons, 1, 0, 1, 2)
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
2015-12-08 18:57:53 +08:00
self.accepted.connect(self.open_file)
def open_file(self):
file = self.filename.text()
async def open_task():
try:
await self.exp_manager.open_file(file)
except:
logger.error("Failed to open file '%s'",
file, exc_info=True)
asyncio.ensure_future(open_task())
2015-11-17 19:46:26 +08:00
class Model(DictSyncTreeSepModel):
2015-11-11 12:13:19 +08:00
def __init__(self, init):
2015-11-27 19:30:05 +08:00
DictSyncTreeSepModel.__init__(self, "/", ["Experiment"], init)
2015-05-24 20:24:07 +08:00
2015-07-18 03:28:46 +08:00
class ExplorerDock(dockarea.Dock):
def __init__(self, status_bar, exp_manager, d_shortcuts,
2015-12-06 18:39:27 +08:00
explist_sub, schedule_ctl, experiment_db_ctl):
dockarea.Dock.__init__(self, "Explorer", size=(1500, 500))
self.layout.setSpacing(5)
self.layout.setContentsMargins(5, 5, 5, 5)
2015-05-23 01:25:33 +08:00
2015-05-24 20:24:07 +08:00
self.status_bar = status_bar
2015-11-27 19:30:05 +08:00
self.exp_manager = exp_manager
self.d_shortcuts = d_shortcuts
2015-05-24 20:24:07 +08:00
self.schedule_ctl = schedule_ctl
2015-11-17 19:46:26 +08:00
self.el = QtGui.QTreeView()
self.el.setHeaderHidden(True)
self.el.setSelectionBehavior(QtGui.QAbstractItemView.SelectItems)
2015-11-27 19:30:05 +08:00
self.addWidget(self.el, 0, 0, colspan=2)
self.el.doubleClicked.connect(
partial(self.expname_action, "open_experiment"))
2015-10-20 18:11:50 +08:00
2015-11-27 19:30:05 +08:00
open = QtGui.QPushButton("Open")
open.setIcon(QtGui.QApplication.style().standardIcon(
QtGui.QStyle.SP_DialogOpenButton))
2015-11-27 19:30:05 +08:00
open.setToolTip("Open the selected experiment (Return)")
self.addWidget(open, 1, 0)
open.clicked.connect(
partial(self.expname_action, "open_experiment"))
2015-05-23 01:25:33 +08:00
submit = QtGui.QPushButton("Submit")
submit.setIcon(QtGui.QApplication.style().standardIcon(
2015-12-05 14:47:20 +08:00
QtGui.QStyle.SP_DialogOkButton))
submit.setToolTip("Schedule the selected experiment (Ctrl+Return)")
2015-11-27 19:30:05 +08:00
self.addWidget(submit, 1, 1)
submit.clicked.connect(
partial(self.expname_action, "submit"))
2015-05-23 01:25:33 +08:00
2015-11-11 12:13:19 +08:00
self.explist_model = Model(dict())
explist_sub.add_setmodel_callback(self.set_model)
2015-10-27 17:59:34 +08:00
self.el.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
2015-11-27 19:30:05 +08:00
open_action = QtGui.QAction("Open", self.el)
open_action.triggered.connect(
partial(self.expname_action, "open_experiment"))
2015-11-27 19:30:05 +08:00
open_action.setShortcut("RETURN")
self.el.addAction(open_action)
submit_action = QtGui.QAction("Submit", self.el)
submit_action.triggered.connect(
partial(self.expname_action, "submit"))
submit_action.setShortcut("CTRL+RETURN")
self.el.addAction(submit_action)
reqterm_action = QtGui.QAction("Request termination of instances", self.el)
reqterm_action.triggered.connect(
partial(self.expname_action, "request_inst_term"))
reqterm_action.setShortcut("CTRL+BACKSPACE")
self.el.addAction(reqterm_action)
set_shortcut_menu = QtGui.QMenu()
for i in range(12):
action = QtGui.QAction("F" + str(i+1), self.el)
action.triggered.connect(partial(self.set_shortcut, i))
set_shortcut_menu.addAction(action)
set_shortcut_action = QtGui.QAction("Set shortcut", self.el)
set_shortcut_action.setMenu(set_shortcut_menu)
self.el.addAction(set_shortcut_action)
sep = QtGui.QAction(self.el)
sep.setSeparator(True)
self.el.addAction(sep)
scan_repository_action = QtGui.QAction("Scan repository HEAD",
self.el)
def scan_repository():
2015-12-06 18:39:27 +08:00
asyncio.ensure_future(experiment_db_ctl.scan_repository_async())
self.status_bar.showMessage("Requested repository scan")
scan_repository_action.triggered.connect(scan_repository)
self.el.addAction(scan_repository_action)
2015-07-18 03:28:46 +08:00
open_file_action = QtGui.QAction("Open file outside repository",
self.el)
open_file_action.triggered.connect(
lambda: _OpenFileDialog(self, self.exp_manager).open())
self.el.addAction(open_file_action)
2015-11-11 12:13:19 +08:00
def set_model(self, model):
self.explist_model = model
self.el.setModel(model)
2015-11-27 19:30:05 +08:00
def _get_selected_expname(self):
selection = self.el.selectedIndexes()
if selection:
2015-11-17 19:46:26 +08:00
return self.explist_model.index_to_key(selection[0])
else:
return None
def expname_action(self, action):
2015-11-27 19:30:05 +08:00
expname = self._get_selected_expname()
if expname is not None:
action = getattr(self.exp_manager, action)
action("repo:" + expname)
2015-05-24 20:24:07 +08:00
def set_shortcut(self, nr):
expname = self._get_selected_expname()
if expname is not None:
expurl = "repo:" + expname
self.d_shortcuts.set_shortcut(nr, expurl)
self.status_bar.showMessage("Set shortcut F{} to '{}'"
.format(nr+1, expurl))