forked from M-Labs/artiq
1
0
Fork 0

gui/shortcuts: make shrinkable, add open button

This commit is contained in:
Sebastien Bourdeauducq 2015-12-01 18:04:43 +08:00
parent ff4c03014c
commit bbabc7bb8d
1 changed files with 21 additions and 1 deletions

View File

@ -35,6 +35,8 @@ class ShortcutsDock(dockarea.Dock):
self.addWidget(QtGui.QLabel("F" + str(i+1)), row, 0) self.addWidget(QtGui.QLabel("F" + str(i+1)), row, 0)
label = QtGui.QLabel() label = QtGui.QLabel()
label.setSizePolicy(QtGui.QSizePolicy.Ignored,
QtGui.QSizePolicy.Ignored)
self.addWidget(label, row, 1) self.addWidget(label, row, 1)
clear = QtGui.QToolButton() clear = QtGui.QToolButton()
@ -43,15 +45,22 @@ class ShortcutsDock(dockarea.Dock):
self.addWidget(clear, row, 2) self.addWidget(clear, row, 2)
clear.clicked.connect(partial(self.set_shortcut, i, "")) clear.clicked.connect(partial(self.set_shortcut, i, ""))
open = QtGui.QToolButton()
open.setIcon(QtGui.QApplication.style().standardIcon(
QtGui.QStyle.SP_DialogOpenButton))
self.addWidget(open, row, 3)
open.clicked.connect(partial(self._open_experiment, i))
submit = QtGui.QPushButton("Submit") submit = QtGui.QPushButton("Submit")
submit.setIcon(QtGui.QApplication.style().standardIcon( submit.setIcon(QtGui.QApplication.style().standardIcon(
QtGui.QStyle.SP_DialogOkButton)) QtGui.QStyle.SP_DialogOkButton))
self.addWidget(submit, row, 3) self.addWidget(submit, row, 4)
submit.clicked.connect(partial(self._activated, i)) submit.clicked.connect(partial(self._activated, i))
self.shortcut_widgets[i] = { self.shortcut_widgets[i] = {
"label": label, "label": label,
"clear": clear, "clear": clear,
"open": open,
"submit": submit "submit": submit
} }
shortcut = QShortcut("F" + str(i+1), main_window) shortcut = QShortcut("F" + str(i+1), main_window)
@ -72,14 +81,25 @@ class ShortcutsDock(dockarea.Dock):
"(from global shortcut)" "(from global shortcut)"
.format(rid)) .format(rid))
def _open_experiment(self, nr):
expname = self.shortcut_widgets[nr]["label"].text()
if expname:
try:
self.exp_manager.open_experiment(expname)
except:
logger.warning("failed to open experiment %s",
expname, exc_info=True)
def set_shortcut(self, nr, expname): def set_shortcut(self, nr, expname):
widgets = self.shortcut_widgets[nr] widgets = self.shortcut_widgets[nr]
widgets["label"].setText(expname) widgets["label"].setText(expname)
if expname: if expname:
widgets["clear"].show() widgets["clear"].show()
widgets["open"].show()
widgets["submit"].show() widgets["submit"].show()
else: else:
widgets["clear"].hide() widgets["clear"].hide()
widgets["open"].hide()
widgets["submit"].hide() widgets["submit"].hide()
def save_state(self): def save_state(self):