forked from M-Labs/artiq
1
0
Fork 0

browser: open experiments from mdiarea

This commit is contained in:
Robert Jördens 2016-05-04 22:00:09 +02:00
parent d99d19dd3a
commit 9f1bef1c81
1 changed files with 22 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import argparse
import asyncio import asyncio
import atexit import atexit
import os import os
import logging
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
from quamash import QEventLoop from quamash import QEventLoop
@ -15,6 +16,9 @@ from artiq.browser import datasets, files
from artiq.dashboard import experiments from artiq.dashboard import experiments
logger = logging.getLogger(__name__)
def get_argparser(): def get_argparser():
if os.name == "nt": if os.name == "nt":
default_db_file = os.path.expanduser("~\\artiq_browser.pyon") default_db_file = os.path.expanduser("~\\artiq_browser.pyon")
@ -62,9 +66,17 @@ class MainWindow(QtWidgets.QMainWindow):
class MdiArea(QtWidgets.QMdiArea): class MdiArea(QtWidgets.QMdiArea):
def __init__(self): def __init__(self, root):
QtWidgets.QMdiArea.__init__(self) 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): def paintEvent(self, event):
QtWidgets.QMdiArea.paintEvent(self, event) QtWidgets.QMdiArea.paintEvent(self, event)
@ -74,6 +86,13 @@ class MdiArea(QtWidgets.QMdiArea):
painter.setOpacity(0.5) painter.setOpacity(0.5)
painter.drawPixmap(x, y, self.pixmap) 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(): def main():
# initialize application # initialize application
@ -108,7 +127,7 @@ def main():
d_datasets = datasets.DatasetsDock(datasets_sub) d_datasets = datasets.DatasetsDock(datasets_sub)
smgr.register(d_datasets) smgr.register(d_datasets)
mdi_area = MdiArea() mdi_area = MdiArea(args.browse_root)
mdi_area.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) mdi_area.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
mdi_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) mdi_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
main_window.setCentralWidget(mdi_area) main_window.setCentralWidget(mdi_area)