From 3d393e46549d38185adcb1b0bda2fc7906330418 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Wed, 20 Apr 2016 13:46:03 +0200 Subject: [PATCH] browser: add root dir option, load only one file on restore --- artiq/browser/files.py | 13 +++++++++---- artiq/frontend/artiq_browser.py | 16 ++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/artiq/browser/files.py b/artiq/browser/files.py index ed62a950f..62d868a39 100644 --- a/artiq/browser/files.py +++ b/artiq/browser/files.py @@ -57,7 +57,8 @@ class DirsOnlyProxy(QtCore.QSortFilterProxyModel): class FilesDock(QtWidgets.QDockWidget): - def __init__(self, datasets, main_window, root=""): + def __init__(self, datasets, main_window, root="", + select_file=None): QtWidgets.QDockWidget.__init__(self, "Files") self.setObjectName("Files") self.setFeatures(self.DockWidgetMovable | self.DockWidgetFloatable) @@ -67,6 +68,7 @@ class FilesDock(QtWidgets.QDockWidget): self.datasets = datasets self.main_window = main_window + self.override_restore_file = select_file self.model = QtWidgets.QFileSystemModel() self.model.setFilter(QtCore.QDir.Drives | QtCore.QDir.NoDotAndDotDot | @@ -180,9 +182,12 @@ class FilesDock(QtWidgets.QDockWidget): dir = state.get("dir") if dir: self.select_dir(dir) - file = state.get("file") - if file: - self.select_file(file) + if self.override_restore_file: + self.select_file(os.path.normpath(self.override_restore_file)) + else: + file = state.get("file") + if file: + self.select_file(file) header = state.get("header") if header: self.rt.header().restoreState(QtCore.QByteArray(header)) diff --git a/artiq/frontend/artiq_browser.py b/artiq/frontend/artiq_browser.py index b6cc22980..3773a918b 100755 --- a/artiq/frontend/artiq_browser.py +++ b/artiq/frontend/artiq_browser.py @@ -21,10 +21,12 @@ def get_argparser(): default_db_file = os.path.expanduser("~/.artiq_browser.pyon") parser = argparse.ArgumentParser(description="ARTIQ Browser") - parser.add_argument( - "--db-file", default=default_db_file, - help="database file for local browser settings " - "(default: %(default)s)") + parser.add_argument("--db-file", default=default_db_file, + help="database file for local browser settings " + "(default: %(default)s)") + parser.add_argument("--root", default="", + help="root path for directory tree " + "(default %(default)s)") parser.add_argument("PATH", nargs="?", help="browse path or file") verbosity_args(parser) return parser @@ -90,7 +92,8 @@ def main(): status_bar = QtWidgets.QStatusBar() main_window.setStatusBar(status_bar) - d_files = files.FilesDock(datasets_sub, main_window) + d_files = files.FilesDock(datasets_sub, main_window, args.root, + args.PATH) smgr.register(d_files) d_applets = applets.AppletsDock(main_window, datasets_sub) @@ -124,9 +127,6 @@ def main(): # run main_window.show() - if args.PATH: - d_files.select_file(os.path.normpath(args.PATH)) - loop.run_until_complete(main_window.exit_request.wait()) if __name__ == "__main__":