From 9f1bef1c8174f53d9d39a72d2a1536ded2d7bb6b Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Wed, 4 May 2016 22:00:09 +0200 Subject: [PATCH] browser: open experiments from mdiarea --- artiq/frontend/artiq_browser.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/artiq/frontend/artiq_browser.py b/artiq/frontend/artiq_browser.py index 2bb8e3ac4..1f48e44b2 100755 --- a/artiq/frontend/artiq_browser.py +++ b/artiq/frontend/artiq_browser.py @@ -4,6 +4,7 @@ import argparse import asyncio import atexit import os +import logging from PyQt5 import QtCore, QtGui, QtWidgets from quamash import QEventLoop @@ -15,6 +16,9 @@ from artiq.browser import datasets, files from artiq.dashboard import experiments +logger = logging.getLogger(__name__) + + def get_argparser(): if os.name == "nt": default_db_file = os.path.expanduser("~\\artiq_browser.pyon") @@ -62,9 +66,17 @@ class MainWindow(QtWidgets.QMainWindow): class MdiArea(QtWidgets.QMdiArea): - def __init__(self): + def __init__(self, root): QtWidgets.QMdiArea.__init__(self) - self.pixmap = QtGui.QPixmap(os.path.join(artiq_dir, "gui", "logo20.svg")) + self.pixmap = QtGui.QPixmap(os.path.join( + artiq_dir, "gui", "logo20.svg")) + self.current_dir = root + self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) + action = QtWidgets.QAction("&Open experiment", self) + # action.setShortcut(QtGui.QKeySequence("CTRL+o")) + action.setShortcutContext(QtCore.Qt.WidgetShortcut) + action.triggered.connect(self.open_experiment) + self.addAction(action) def paintEvent(self, event): QtWidgets.QMdiArea.paintEvent(self, event) @@ -74,6 +86,13 @@ class MdiArea(QtWidgets.QMdiArea): painter.setOpacity(0.5) painter.drawPixmap(x, y, self.pixmap) + def open_experiment(self): + file, filter = QtWidgets.QFileDialog.getOpenFileName( + self, "Open experiment", self.current_dir, "Experiments (*.py)") + if not file: + return + print(file) + def main(): # initialize application @@ -108,7 +127,7 @@ def main(): d_datasets = datasets.DatasetsDock(datasets_sub) smgr.register(d_datasets) - mdi_area = MdiArea() + mdi_area = MdiArea(args.browse_root) mdi_area.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) mdi_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) main_window.setCentralWidget(mdi_area)