artiq/artiq/gui/explorer.py

180 lines
6.2 KiB
Python
Raw Normal View History

2015-05-24 20:24:07 +08:00
import asyncio
2015-07-18 03:28:46 +08:00
import traceback
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-05-24 20:24:07 +08:00
from artiq.protocols.sync_struct import Subscriber
2015-07-18 03:28:46 +08:00
from artiq.protocols import pyon
2015-05-24 20:24:07 +08:00
from artiq.gui.tools import DictSyncModel
class _ExplistModel(DictSyncModel):
def __init__(self, parent, init):
DictSyncModel.__init__(self,
["Experiment"],
parent, init)
def sort_key(self, k, v):
return k
def convert(self, k, v, column):
return k
2015-07-18 03:28:46 +08:00
class _FreeValueEntry(QtGui.QLineEdit):
def __init__(self, procdesc):
QtGui.QLineEdit.__init__(self)
if "default" in procdesc:
self.insert(pyon.encode(procdesc["default"]))
def get_argument_value(self):
return pyon.decode(self.text())
_procty_to_entry = {
"FreeValue": _FreeValueEntry
}
class _ArgumentSetter(LayoutWidget):
def __init__(self, dialog_parent, arguments):
LayoutWidget.__init__(self)
self.dialog_parent = dialog_parent
if not arguments:
self.addWidget(QtGui.QLabel("No arguments"), 0, 0)
self._args_to_entries = dict()
for n, (name, procdesc) in enumerate(arguments):
self.addWidget(QtGui.QLabel(name), n, 0)
entry = _procty_to_entry[procdesc["ty"]](procdesc)
self.addWidget(entry, n, 1)
self._args_to_entries[name] = entry
def get_argument_values(self):
r = dict()
for arg, entry in self._args_to_entries.items():
try:
r[arg] = entry.get_argument_value()
except:
msgbox = QtGui.QMessageBox(self.dialog_parent)
msgbox.setWindowTitle("Error")
msgbox.setText("Failed to obtain value for argument '{}'.\n{}"
.format(arg, traceback.format_exc()))
msgbox.setStandardButtons(QtGui.QMessageBox.Ok)
msgbox.show()
return None
return r
class ExplorerDock(dockarea.Dock):
2015-07-18 03:28:46 +08:00
def __init__(self, dialog_parent, status_bar, schedule_ctl):
dockarea.Dock.__init__(self, "Explorer", size=(1500, 500))
2015-05-23 01:25:33 +08:00
2015-07-18 03:28:46 +08:00
self.dialog_parent = dialog_parent
2015-05-24 20:24:07 +08:00
self.status_bar = status_bar
self.schedule_ctl = schedule_ctl
2015-07-18 03:28:46 +08:00
self.splitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
self.addWidget(self.splitter)
2015-05-23 01:25:33 +08:00
grid = LayoutWidget()
2015-07-18 03:28:46 +08:00
self.splitter.addWidget(grid)
2015-05-23 01:25:33 +08:00
2015-05-24 20:24:07 +08:00
self.el = QtGui.QListView()
2015-07-18 03:28:46 +08:00
self.el.selectionChanged = self.update_argsetter
2015-05-24 20:24:07 +08:00
grid.addWidget(self.el, 0, 0, colspan=4)
2015-05-23 01:25:33 +08:00
2015-05-24 20:24:07 +08:00
self.datetime = QtGui.QDateTimeEdit()
self.datetime.setDisplayFormat("MMM d yyyy hh:mm:ss")
self.datetime.setCalendarPopup(True)
self.datetime.setDate(QtCore.QDate.currentDate())
self.datetime.dateTimeChanged.connect(self.enable_duedate)
2015-05-28 17:20:58 +08:00
self.datetime_en = QtGui.QCheckBox("Due date:")
2015-05-24 20:24:07 +08:00
grid.addWidget(self.datetime_en, 1, 0)
2015-05-28 17:20:58 +08:00
grid.addWidget(self.datetime, 1, 1)
self.priority = QtGui.QSpinBox()
self.priority.setRange(-99, 99)
grid.addWidget(QtGui.QLabel("Priority:"), 1, 2)
2015-05-28 17:20:58 +08:00
grid.addWidget(self.priority, 1, 3)
2015-05-23 01:25:33 +08:00
2015-05-24 20:24:07 +08:00
self.pipeline = QtGui.QLineEdit()
self.pipeline.insert("main")
grid.addWidget(QtGui.QLabel("Pipeline:"), 2, 0)
2015-05-24 20:24:07 +08:00
grid.addWidget(self.pipeline, 2, 1)
2015-05-23 01:25:33 +08:00
2015-05-28 17:20:58 +08:00
self.flush = QtGui.QCheckBox("Flush")
grid.addWidget(self.flush, 2, 2, colspan=2)
2015-05-23 01:25:33 +08:00
submit = QtGui.QPushButton("Submit")
grid.addWidget(submit, 3, 0, colspan=4)
2015-05-24 20:24:07 +08:00
submit.clicked.connect(self.submit_clicked)
2015-05-23 01:25:33 +08:00
2015-07-18 03:28:46 +08:00
self.argsetter = _ArgumentSetter(self.dialog_parent, [])
self.splitter.addWidget(self.argsetter)
self.splitter.setSizes([grid.minimumSizeHint().width(), 1000])
def update_argsetter(self, selected, deselected):
selected = selected.indexes()
if selected:
row = selected[0].row()
key = self.explist_model.row_to_key[row]
expinfo = self.explist_model.backing_store[key]
arguments = expinfo["arguments"]
sizes = self.splitter.sizes()
self.argsetter.deleteLater()
self.argsetter = _ArgumentSetter(self.dialog_parent, arguments)
self.splitter.insertWidget(1, self.argsetter)
self.splitter.setSizes(sizes)
2015-05-24 20:24:07 +08:00
def enable_duedate(self):
self.datetime_en.setChecked(True)
2015-05-24 20:24:07 +08:00
@asyncio.coroutine
def sub_connect(self, host, port):
self.explist_subscriber = Subscriber("explist",
self.init_explist_model)
yield from self.explist_subscriber.connect(host, port)
@asyncio.coroutine
def sub_close(self):
yield from self.explist_subscriber.close()
def init_explist_model(self, init):
self.explist_model = _ExplistModel(self.el, init)
self.el.setModel(self.explist_model)
return self.explist_model
@asyncio.coroutine
2015-07-15 17:08:12 +08:00
def submit(self, pipeline_name, file, class_name, arguments,
2015-05-28 17:20:58 +08:00
priority, due_date, flush):
2015-05-24 20:24:07 +08:00
expid = {
"file": file,
2015-07-15 17:08:12 +08:00
"class_name": class_name,
2015-05-24 20:24:07 +08:00
"arguments": arguments,
}
rid = yield from self.schedule_ctl.submit(pipeline_name, expid,
2015-05-28 17:20:58 +08:00
priority, due_date, flush)
2015-05-24 20:24:07 +08:00
self.status_bar.showMessage("Submitted RID {}".format(rid))
def submit_clicked(self):
idx = self.el.selectedIndexes()
if idx:
row = idx[0].row()
key = self.explist_model.row_to_key[row]
expinfo = self.explist_model.backing_store[key]
2015-05-24 20:24:07 +08:00
if self.datetime_en.isChecked():
due_date = self.datetime.dateTime().toMSecsSinceEpoch()/1000
else:
due_date = None
2015-07-18 03:28:46 +08:00
arguments = self.argsetter.get_argument_values()
if arguments is None:
return
2015-05-24 20:24:07 +08:00
asyncio.async(self.submit(self.pipeline.text(),
2015-07-15 17:08:12 +08:00
expinfo["file"], expinfo["class_name"],
2015-07-18 03:28:46 +08:00
arguments, self.priority.value(),
due_date, self.flush.isChecked()))