2016-04-04 23:37:51 +08:00
|
|
|
#!/usr/bin/env python3.5
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import asyncio
|
|
|
|
import atexit
|
|
|
|
import os
|
|
|
|
|
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
|
|
|
from quamash import QEventLoop
|
|
|
|
|
|
|
|
from artiq import __artiq_dir__ as artiq_dir
|
2016-04-05 17:17:02 +08:00
|
|
|
from artiq.tools import verbosity_args, init_logger, atexit_register_coroutine
|
2016-04-05 18:50:19 +08:00
|
|
|
from artiq.gui import state, applets, models
|
2016-04-14 17:55:44 +08:00
|
|
|
from artiq.browser import datasets, files
|
2016-04-04 23:37:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
def get_argparser():
|
2016-04-15 19:05:12 +08:00
|
|
|
if os.name == "nt":
|
|
|
|
default_db_file = os.path.expanduser("~\\artiq_browser.pyon")
|
|
|
|
else:
|
|
|
|
default_db_file = os.path.expanduser("~/.artiq_browser.pyon")
|
|
|
|
|
2016-04-05 18:50:19 +08:00
|
|
|
parser = argparse.ArgumentParser(description="ARTIQ Browser")
|
2016-04-04 23:37:51 +08:00
|
|
|
parser.add_argument(
|
2016-04-15 19:05:12 +08:00
|
|
|
"--db-file", default=default_db_file,
|
|
|
|
help="database file for local browser settings "
|
|
|
|
"(default: %(default)s)")
|
2016-04-20 19:20:33 +08:00
|
|
|
parser.add_argument("PATH", nargs="?", help="browse path or file")
|
2016-04-04 23:37:51 +08:00
|
|
|
verbosity_args(parser)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
class MainWindow(QtWidgets.QMainWindow):
|
|
|
|
def __init__(self):
|
|
|
|
QtWidgets.QMainWindow.__init__(self)
|
|
|
|
|
|
|
|
icon = QtGui.QIcon(os.path.join(artiq_dir, "gui", "logo.svg"))
|
|
|
|
self.setWindowIcon(icon)
|
2016-04-05 18:50:19 +08:00
|
|
|
self.setWindowTitle("ARTIQ Browser")
|
2016-04-04 23:37:51 +08:00
|
|
|
|
|
|
|
qfm = QtGui.QFontMetrics(self.font())
|
|
|
|
self.resize(140*qfm.averageCharWidth(), 38*qfm.lineSpacing())
|
|
|
|
|
|
|
|
self.exit_request = asyncio.Event()
|
|
|
|
|
|
|
|
def closeEvent(self, *args):
|
|
|
|
self.exit_request.set()
|
|
|
|
|
|
|
|
def save_state(self):
|
|
|
|
return {
|
|
|
|
"state": bytes(self.saveState()),
|
|
|
|
"geometry": bytes(self.saveGeometry())
|
|
|
|
}
|
|
|
|
|
|
|
|
def restore_state(self, state):
|
|
|
|
self.restoreGeometry(QtCore.QByteArray(state["geometry"]))
|
|
|
|
self.restoreState(QtCore.QByteArray(state["state"]))
|
|
|
|
|
|
|
|
|
2016-04-10 16:22:24 +08:00
|
|
|
class MdiArea(QtWidgets.QMdiArea):
|
|
|
|
def __init__(self):
|
|
|
|
QtWidgets.QMdiArea.__init__(self)
|
|
|
|
self.pixmap = QtGui.QPixmap(os.path.join(artiq_dir, "gui", "logo.svg"))
|
|
|
|
|
|
|
|
def paintEvent(self, event):
|
|
|
|
QtWidgets.QMdiArea.paintEvent(self, event)
|
|
|
|
painter = QtGui.QPainter(self.viewport())
|
|
|
|
x = (self.width() - self.pixmap.width())//2
|
|
|
|
y = (self.height() - self.pixmap.height())//2
|
|
|
|
painter.setOpacity(0.5)
|
|
|
|
painter.drawPixmap(x, y, self.pixmap)
|
|
|
|
|
|
|
|
|
2016-04-04 23:37:51 +08:00
|
|
|
def main():
|
|
|
|
# initialize application
|
|
|
|
args = get_argparser().parse_args()
|
|
|
|
init_logger(args)
|
|
|
|
|
|
|
|
app = QtWidgets.QApplication([])
|
|
|
|
loop = QEventLoop(app)
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
atexit.register(loop.close)
|
|
|
|
smgr = state.StateManager(args.db_file)
|
|
|
|
|
2016-04-05 17:17:02 +08:00
|
|
|
datasets_sub = models.LocalModelManager(datasets.Model)
|
2016-04-04 23:37:51 +08:00
|
|
|
|
|
|
|
# initialize main window
|
|
|
|
main_window = MainWindow()
|
|
|
|
smgr.register(main_window)
|
|
|
|
status_bar = QtWidgets.QStatusBar()
|
|
|
|
main_window.setStatusBar(status_bar)
|
|
|
|
|
2016-04-20 19:20:33 +08:00
|
|
|
d_files = files.FilesDock(datasets_sub, main_window)
|
2016-04-14 17:55:44 +08:00
|
|
|
smgr.register(d_files)
|
2016-04-04 23:37:51 +08:00
|
|
|
|
|
|
|
d_applets = applets.AppletsDock(main_window, datasets_sub)
|
|
|
|
atexit_register_coroutine(d_applets.stop)
|
|
|
|
smgr.register(d_applets)
|
|
|
|
|
2016-04-05 18:50:19 +08:00
|
|
|
d_datasets = datasets.DatasetsDock(datasets_sub)
|
2016-04-05 00:02:32 +08:00
|
|
|
smgr.register(d_datasets)
|
|
|
|
|
2016-04-10 16:22:24 +08:00
|
|
|
mdi_area = MdiArea()
|
|
|
|
mdi_area.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
|
|
|
|
mdi_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
|
|
|
|
main_window.setCentralWidget(mdi_area)
|
|
|
|
|
2016-04-14 17:55:44 +08:00
|
|
|
main_window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, d_files)
|
2016-04-05 15:51:04 +08:00
|
|
|
main_window.addDockWidget(QtCore.Qt.BottomDockWidgetArea, d_applets)
|
|
|
|
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, d_datasets)
|
2016-04-04 23:37:51 +08:00
|
|
|
|
|
|
|
# load/initialize state
|
|
|
|
if os.name == "nt":
|
|
|
|
# HACK: show the main window before creating applets.
|
|
|
|
# Otherwise, the windows of those applets that are in detached
|
|
|
|
# QDockWidgets fail to be embedded.
|
|
|
|
main_window.show()
|
|
|
|
|
|
|
|
smgr.load()
|
|
|
|
|
|
|
|
smgr.start()
|
|
|
|
atexit_register_coroutine(smgr.stop)
|
|
|
|
|
|
|
|
# run
|
|
|
|
main_window.show()
|
2016-04-17 16:34:10 +08:00
|
|
|
|
|
|
|
if args.PATH:
|
|
|
|
d_files.select_file(os.path.normpath(args.PATH))
|
|
|
|
|
2016-04-04 23:37:51 +08:00
|
|
|
loop.run_until_complete(main_window.exit_request.wait())
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|